This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
forked from dreyau/bareos_exporter
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
55 lines (44 loc) · 1.44 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
package main
import (
"flag"
"fmt"
"net/http"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
var connectionString string
var (
exporterPort = flag.Int("port", 9625, "Bareos exporter port")
exporterEndpoint = flag.String("endpoint", "/metrics", "Bareos exporter endpoint")
databaseURL = flag.String("dsn", "mysql://bareos@unix()/bareos?parseTime=true", "Bareos database DSN")
jobDiscoveryDays = flag.Int("job-discovery-days", 7, "Number of days in the past that will be searched for jobs")
)
func splitDsn(dsn string) (string, string, error) {
var splitDsn = strings.SplitN(dsn, "://", 2)
if len(splitDsn) != 2 {
return "", "", fmt.Errorf("Database DSN is incomplete: missing protocol: %s", dsn)
}
return splitDsn[0], splitDsn[1], nil
}
func main() {
flag.Parse()
dbType, connectionString, err := splitDsn(*databaseURL)
if err != nil {
log.Fatal(err)
}
connection, err := GetConnection(dbType, connectionString, *jobDiscoveryDays)
if err != nil {
log.Fatal(err)
}
defer connection.Close()
collector := bareosCollector(connection)
prometheus.MustRegister(collector)
http.Handle(*exporterEndpoint, promhttp.Handler())
log.Info("Beginning to serve on port ", *exporterPort)
addr := fmt.Sprintf(":%d", *exporterPort)
log.Fatal(http.ListenAndServe(addr, nil))
}