Skip to content

Instantly share code, notes, and snippets.

@saward
Created January 15, 2016 03:40
Show Gist options
  • Save saward/34156ca10e155aafc854 to your computer and use it in GitHub Desktop.
Save saward/34156ca10e155aafc854 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/influxdb/influxdb/client/v2"
"time"
)
const (
MyDB = "square_holes"
username = "bubba"
password = "bumblebeetuna"
)
func main() {
// Make client
c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: "http://localhost:8086",
Username: username,
Password: password,
})
if err != nil {
panic(err)
}
// Create a new point batch
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: MyDB,
Precision: "s",
})
if err != nil {
panic(err)
}
// Create a point and add to batch
tags := map[string]string{"cpu": "cpu-total"}
fields := map[string]interface{}{
"idle": 10.1,
"system": 53.3,
"user": 46.6,
}
pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now())
if err != nil {
panic(err)
}
bp.AddPoint(pt)
// Write the batch
err = c.Write(bp)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment