Hi,
I’m trying entering data in InfluxDB 2 Cloud using the golang client (see below). But I don’t see anything entering in my InfluxDB.
Can anyone point me in a direction what I’m missing?
Thanks.
Guy
package main
import (
“context”
“fmt”
//“net/http”
“time”
"github.com/influxdata/influxdb-client-go"
)
func main() {
myHTTPInfluxAddress := “https://us-west-2-1.aws.cloud2.influxdata.com”
myToken := “mytoken”
influx, err := influxdb.New(myHTTPInfluxAddress, myToken, influxdb.WithHTTPClient(nil))
if err != nil {
fmt.Println(err)
}
// we use client.NewRowMetric for the example because it's easy, but if you need extra performance
// it is fine to manually build the []client.Metric{}.
myMetrics := []influxdb.Metric{
influxdb.NewRowMetric(map[string]interface{}{"memory": 1000, "cpu": 0.93}, "system-metrics", map[string]string{"hostname": "hal9000"}, time.Date(2018, 3, 4, 5, 6, 7, 8, time.UTC)),
influxdb.NewRowMetric(map[string]interface{}{"memory": 1000, "cpu": 0.93}, "system-metrics", map[string]string{"hostname": "hal9000"}, time.Date(2018, 3, 4, 5, 6, 7, 9, time.UTC)),
}
// The actual write..., this method can be called concurrently.
if _, err := influx.Write(context.Background(), "my_bucket", "my_org", myMetrics...); err != nil {
fmt.Println(err) // as above use your own error handling here.
}
influx.Close() // closes the client. After this the client is useless.
}