-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (46 loc) · 1.2 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
package main
import (
"flag"
"io/ioutil"
"log"
"net/http"
"os"
"gopkg.in/yaml.v2"
"github.com/eleven26/rds_exporter/exporter"
)
func parseConfig(path *string) exporter.Config {
if _, err := os.Stat(*path); os.IsNotExist(err) {
panic(err)
}
content, err := ioutil.ReadFile(*path)
if err != nil {
panic(err)
}
var conf exporter.Config
err = yaml.Unmarshal(content, &conf)
if err != nil {
panic(err)
}
return conf
}
func main() {
address := flag.String("web.listen-address", "127.0.0.1:9094", "监听地址,格式如 \"0.0.0.0:9094\"")
configFile := flag.String("config.file", "config.yml", "配置文件路径")
flag.Parse()
conf := parseConfig(configFile)
log.Printf("监听地址:%s", *address)
log.Printf("rds 实例id:%s", conf.InstanceId)
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
response, err := exporter.FetchLastMinuteDBInstancePerformance(exporter.Config{
InstanceId: conf.InstanceId,
AccessKeyId: conf.AccessKeyId,
AccessKeySecret: conf.AccessKeySecret,
})
if err != nil {
panic(err)
}
// log.Println(response.Json())
w.Write([]byte(response.Html()))
})
log.Fatal(http.ListenAndServe(*address, nil))
}