-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinflux_output.go
53 lines (44 loc) · 1.23 KB
/
influx_output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package zipkin
import (
"github.com/hyperworks/influxdb/client"
)
type influxOutput struct {
*client.Client
clientConfig *client.ClientConfig
config *Config
seriesName string
}
// NewInfluxOutput() creates an Output that converts ZipKin spans to InfluxDB
// (http://influxdb.com) series/data points and writes it to the specified InfluxDB
// address and database.
func NewInfluxOutput(config *Config, address, database, username, password, seriesName string) (o Output, e error) {
defer autoRecover(&e)
clientConfig := &client.ClientConfig{
Host: address,
Username: username,
Password: password,
Database: database,
IsSecure: false,
}
cl, e := client.New(clientConfig)
noError(e)
if e = cl.Ping(); e != nil {
return nil, e
}
return &influxOutput{cl, clientConfig, config, seriesName}, nil
}
func (inf *influxOutput) Write(result OutputMap) error {
// convert to influx series
keys := make([]string, 0, len(result))
values := make([]interface{}, 0, len(result))
for k, v := range result {
keys = append(keys, k)
values = append(values, v)
}
series := &client.Series{
Name: inf.seriesName,
Columns: keys,
Points: [][]interface{}{values},
}
return inf.WriteSeries([]*client.Series{series})
}