-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (49 loc) · 1.23 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
59
60
61
package main
import (
"flag"
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const (
namespace = "abcd"
)
type myCollector struct{}
var (
exampleCount = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "example_count",
Help: "example counter help",
})
exampleGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "example_gauge",
Help: "example gauge help",
})
)
func (c myCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- exampleCount.Desc()
ch <- exampleGauge.Desc()
}
func (c myCollector) Collect(ch chan<- prometheus.Metric) {
dummyStaticNumber := float64(1234)
ch <- prometheus.MustNewConstMetric(
exampleCount.Desc(),
prometheus.CounterValue,
float64(dummyStaticNumber),
)
ch <- prometheus.MustNewConstMetric(
exampleGauge.Desc(),
prometheus.GaugeValue,
float64(dummyStaticNumber),
)
}
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
func main() {
flag.Parse()
var c myCollector
prometheus.MustRegister(c)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*addr, nil))
}