-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
58 lines (45 loc) · 1.13 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
package main
import (
"log"
"net/http"
"os"
"fmt"
"github.com/othalla/plex_exporter/collector"
"github.com/othalla/plex_exporter/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Load json configuration from `FILE`",
},
}
app.Action = runExporter
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func runExporter(c *cli.Context) error {
name := c.String("config")
config, err := config.Load(name)
if err != nil {
return err
}
client := &http.Client{}
server := &collector.PlexMediaServer{Address: config.Server.Address,
Port: config.Server.Port,
Token: config.Server.Token,
HTTPClient: client,
}
collector := collector.NewPlexMediaServerCollector(server)
prometheus.MustRegister(collector)
http.Handle("/metrics", promhttp.Handler())
log.Printf("Starting exporter on port %d ...", config.Exporter.Port)
http.ListenAndServe(fmt.Sprintf(":%d", config.Exporter.Port), nil)
return nil
}