forked from boynux/squid-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (28 loc) · 982 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/boynux/squid-exporter/collector"
"github.com/prometheus/client_golang/prometheus"
)
const indexContent = `<html>
<head><title>Squid Exporter</title></head>
<body>
<h1>Squid Exporter</h1>
<p><a href='` + "/metrics" + `'>Metrics</a></p>
</body>
</html>`
func main() {
config := NewConfig()
log.Println("Scraping metrics from", fmt.Sprintf("%s:%d", config.SquidHostname, config.SquidPort))
e := collector.New(config.SquidHostname, config.SquidPort, config.Login, config.Password)
prometheus.MustRegister(e)
// Serve metrics
http.Handle(config.MetricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(indexContent))
})
log.Println("Listening on", fmt.Sprintf("%s", config.ListenAddress))
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s", config.ListenAddress), nil))
}