-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
40 lines (35 loc) · 1.06 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
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/tedpearson/ambientweatherexporter/weather"
)
var (
version = "development"
goVersion = "unknown"
buildDate = "unknown"
)
func main() {
port := flag.Int("port", 2184, "Http server port to listen on")
name := flag.String("station-name", "Unknown",
"Weather station name for the 'name' label on the metrics")
versionFlag := flag.Bool("v", false, "Show version and exit")
flag.Parse()
fmt.Printf("ambientweatherexporter version %s built on %s with %s\n", version, buildDate, goVersion)
if *versionFlag {
os.Exit(0)
}
registry := prometheus.NewRegistry()
factory := promauto.With(registry)
http.Handle("/data/report/", weather.NewParser(*name, &factory))
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
if err != nil {
panic(err)
}
}