-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.go
49 lines (42 loc) · 931 Bytes
/
collector.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
package main
import (
"log"
"strconv"
"github.com/prometheus/client_golang/prometheus"
)
type Collector struct {
Client *UptimerobotClient
Monitor *prometheus.Desc
}
func NewCollector(apiKey string) *Collector {
return &Collector{
Client: NewUptimerobotClient(apiKey),
Monitor: prometheus.NewDesc(
"uptimerobot_monitor_up",
"Status of the UptimeRobot monitor",
[]string{"id", "friendly_name", "url", "type"},
nil,
),
}
}
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.Monitor
}
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
monitors, err := c.Client.GetMonitors()
if err != nil {
log.Print(err)
return
}
for _, monitor := range monitors {
ch <- prometheus.MustNewConstMetric(
c.Monitor,
prometheus.GaugeValue,
float64(monitor.Status),
strconv.Itoa(monitor.ID),
monitor.FriendlyName,
monitor.URL,
strconv.Itoa(monitor.Type),
)
}
}