-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppStatSend.go
More file actions
53 lines (39 loc) · 1.24 KB
/
AppStatSend.go
File metadata and controls
53 lines (39 loc) · 1.24 KB
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
package AppStats
import (
"bytes"
"fmt"
"net/http"
"strings"
"time"
l "github.com/acky666/ackyLog"
)
func UpdateInflux(AppConfig Config) {
out := ""
l.INFO("Starting GoRoutine to Update Influx")
// curl -v -XPOST 'http://my.influx.server:8086/write?db=db_name' --data-binary 'my_measurement,tag_name=stuff value=1'
httpClient := http.Client{Timeout: 10 * time.Second}
for {
collectedStats := 0
out = "Metrics,host=" + AppConfig.Hostname + ",Project=" + AppConfig.Project + ",Version=" + AppConfig.Version + ",EnvType=" + AppConfig.EnvironmentType + ",Env=" + AppConfig.Environment + " "
for _, v := range Stats.GetStatKeys() {
out = out + v + "=" + fmt.Sprintf("%d", Stats.GetStat(v))
out = out + ","
collectedStats++
}
out = strings.TrimRight(out, ",")
if collectedStats > 0 {
request, _ := http.NewRequest("POST", AppConfig.InfluxURL, bytes.NewBufferString(out+"\n"))
response, err := httpClient.Do(request)
if err != nil {
l.ERROR("Failed to Send Statistics to Influx")
l.ERROR("Error: %v", err)
} else {
if response.StatusCode != 204 {
l.ERROR("Bad response from Influx (Server Details and Labels Correct?)")
l.SPEW(response)
}
}
}
time.Sleep(AppConfig.UpdateFrequency)
}
}