-
Notifications
You must be signed in to change notification settings - Fork 32
/
influx.go
43 lines (38 loc) · 834 Bytes
/
influx.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
package stats
import (
"fmt"
client "github.com/influxdata/influxdb/client/v2"
)
type influxPublisher struct {
url string
database string
username, password string
}
func (i *influxPublisher) SendData(pts []*Measurement) error {
c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: i.url,
Username: i.username,
Password: i.password,
})
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: i.database,
Precision: "s",
})
if err != nil {
return err
}
for _, pt := range pts {
vals := map[string]interface{}{}
for k, v := range pt.Values {
vals[k] = v
}
dp, err := client.NewPoint(pt.Name, pt.Tags, vals, pt.Timestamp)
if err != nil {
return err
}
bp.AddPoint(dp)
}
err = c.Write(bp)
fmt.Println(err, len(pts), "FLLLLLL")
return err
}