-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (67 loc) · 1.55 KB
/
main.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
package main
import (
"log"
"os"
"time"
)
func main() {
defer func() {
if err := recover(); err != nil {
log.Fatal(err)
}
}()
forever := len(os.Args) == 1
log.Printf("Running forever: %v", forever)
db, llti := defaultConfig()
if forever {
log.Printf("Delay: %vs", llti.DelaySeconds)
}
// call with more than 0 parameter to run only once
run(forever, db, llti)
}
func run(forever bool, config *influxConfig, lconfig *lltiConfig) {
log.Printf("Connecting to %v, db: %v", config.InfluxUrl, config.InfluxDb)
sanityCheck()
client, err := newInfluxClient(config)
if err != nil {
panic(err)
}
ensureDbExists(client, config.InfluxDb)
for {
fields := ulimits()
mergeIntoFirst(fields, ipcsLimits())
tags := tags()
insertSinglePointNow(client, config, "limits", fields, tags)
time.Sleep(time.Duration(lconfig.DelaySeconds) * time.Second)
if !forever {
break
}
}
}
type influxConfig struct {
InfluxUrl string
InfluxDb string
InfluxUser string
InfluxPass string
}
type lltiConfig struct {
DelaySeconds int
}
func defaultConfig() (*influxConfig, *lltiConfig) {
config := &influxConfig{
InfluxUrl: os.Getenv("INFLUX_URL"),
InfluxDb: os.Getenv("INFLUX_DB"),
InfluxUser: os.Getenv("INFLUX_USER"),
InfluxPass: os.Getenv("INFLUX_PWD"),
}
if config.InfluxUrl == "" {
config.InfluxUrl = "http://localhost:8086"
}
if config.InfluxDb == "" {
config.InfluxDb = "llti"
}
lconfig := &lltiConfig{
DelaySeconds: int(toIntOrDefault(os.Getenv("LLTI_DELAY_SECONDS"), 3)), // no range check
}
return config, lconfig
}