-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1020 Bytes
/
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
package main
import (
"flag"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
yaml "gopkg.in/yaml.v2"
)
//Conf is a struct for our config-file
type Conf struct {
Listen string
Apikey string
Probetime int
Octopi string
}
var c Conf
var configpath = flag.String("config", "config.yaml", "Choose your config File")
func main() {
// Parse Configs
flag.Parse()
c.getConf()
// Register Metrics
jobinfo := newJobCollector()
prometheus.MustRegister(jobinfo)
// Start the Prometheus HTTP Server
log.Println("Started HTTP Server: " + c.Listen)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(c.Listen, nil))
}
func (c *Conf) getConf() *Conf {
yamlFile, err := ioutil.ReadFile(*configpath)
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
os.Exit(255)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return c
}