-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (32 loc) · 1.01 KB
/
main.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
package main
import (
"context"
"fmt"
"time"
influxdb2 "github.com/influxdata/influxdb-client-go"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client := influxdb2.NewClient("http://localhost:8086", "influxdb:influxdb")
writeApi := client.WriteApiBlocking("", "test/autogen")
defer client.Close()
p := influxdb2.NewPoint("stat",
map[string]string{"unit": "mem"},
map[string]interface{}{"num": 23, "max": uint(42), "avg_ns": 111111111},
time.Now())
// the above will produce:
// stat,unit=mem avg_ns=111111111i,max=42u,num=23i 1593456269331238808\n
// which fails to be written in the db with empty error and status 400
// if I delete manually all i, u and \n then it is written successfully.
err := writeApi.WritePoint(ctx, p)
if err != nil {
fmt.Printf("%v\n", err)
}
// this is ok
line := fmt.Sprintf("stat,unit=temperature avg=%f,max=%d", 23.5, 45)
err = writeApi.WriteRecord(context.Background(), line)
if err != nil {
fmt.Printf("%v\n", err)
}
}