forked from jondot/groundcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempodb_reporter.go
62 lines (50 loc) · 1.69 KB
/
tempodb_reporter.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
package main
import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"time"
)
type Bulk struct {
Time string `json:"t"`
Data []map[string]interface{} `json:"data"`
}
type TempoDBReporter struct {
Credentials ReporterCredentials
}
func NewTempoDBReporter(creds ReporterCredentials) (h *TempoDBReporter) {
return &TempoDBReporter{Credentials: creds}
}
func (self *TempoDBReporter) ReportHealth(h *Health) {
base := "https://api.tempo-db.com/v1/data"
tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
http.DefaultTransport = tr
purl, _ := url.Parse(base)
purl.User = url.UserPassword(self.Credentials.User,
self.Credentials.Key)
t := time.Now()
now := t.Format("2006-01-02T15:04:05.999Z0700")
blk := &Bulk{Time: now}
blk.Data = append(blk.Data,
map[string]interface{}{"key": "avg1", "v": h.LoadAvg1},
map[string]interface{}{"key": "avg5", "v": h.LoadAvg5},
map[string]interface{}{"key": "avg15", "v": h.LoadAvg15},
map[string]interface{}{"key": "memfree", "v": h.MemActualFree},
map[string]interface{}{"key": "memused", "v": h.MemActualUsed},
map[string]interface{}{"key": "CPU temp", "v": h.CPUTemp},
)
for _, disk := range h.Disks {
blk.Data = append(blk.Data, map[string]interface{}{"key": fmt.Sprintf("disk_used: %s", disk.DeviceName), "v": disk.Used})
blk.Data = append(blk.Data, map[string]interface{}{"key": fmt.Sprintf("disk_used_pcent: %s", disk.DeviceName), "v": disk.UsedPcent})
}
b, _ := json.Marshal(blk)
r := bytes.NewReader(b)
resp, err := http.Post(purl.String(), "application/json", r)
if nil != err || resp.StatusCode != 200 {
log.Println("Error: TempoDB API Error: ", err, resp)
}
}