-
Notifications
You must be signed in to change notification settings - Fork 0
/
influxdb_insert.go
91 lines (81 loc) · 1.89 KB
/
influxdb_insert.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"github.com/influxdata/influxdb/client/v2"
"fmt"
"flag"
"time"
"os"
"log"
"strconv"
)
func influxDBClient() client.Client {
c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: "https://<<host>>:8086",
Username: "XXX",
Password: "YYYYY",
InsecureSkipVerify: true,
})
if err!= nil {
fmt.Println("Error: ",err)
}
return c
}
func main() {
log.SetOutput(os.Stdout)
t := time.Now()
serverPtr := flag.String("s","","Server Name")
ipPtr := flag.String("i","","IP address")
vpcPtr := flag.String("v","","VPC")
clusterPtr := flag.String("c","","Cluster")
poolPtr := flag.String("p","","Pool")
cpuPtr := flag.String("cpu","","CPU")
memPtr := flag.String("mem","","mem")
osPtr := flag.String("os","","OS")
domainPtr := flag.String("domain","","Domain")
requestorPtr := flag.String("r","","Requestor")
flag.Parse()
c := influxDBClient()
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: "provisioning",
Precision: "s",
})
if err != nil {
log.Fatalln("Error: ", err)
}
tags := map[string]string{
"cluster": *clusterPtr,
"vpc": *vpcPtr,
"pool": *poolPtr,
"os": *osPtr,
}
proc, err:= strconv.Atoi(*cpuPtr)
if err!= nil {
fmt.Println("Error: ",err)
}
ram, err:= strconv.Atoi(*memPtr)
if err!= nil {
fmt.Println("Error: ",err)
}
fields := map[string]interface{}{
"server": *serverPtr,
"cpu": proc,
"mem": ram,
"ip": *ipPtr,
"domain": *domainPtr,
"requestor": *requestorPtr,
}
point, err := client.NewPoint(
fmt.Sprintf("vm_provisioning1",),
tags,
fields,
t.AddDate(0, 0, -1).UTC(),
)
if err != nil {
log.Fatalln("Error: ", err)
}
bp.AddPoint(point)
err = c.Write(bp)
if err != nil {
log.Fatal(err)
}
}