-
Notifications
You must be signed in to change notification settings - Fork 1
/
prometheus.go
44 lines (37 loc) · 940 Bytes
/
prometheus.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
package prometheus
import (
"github.com/gin-gonic/gin"
"github.com/simiancreative/simiango/server"
promcore "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func Register(collector promcore.Collector) {
promcore.MustRegister(collector)
}
func Handle() {
r := server.GetRouter()
r.GET("/metrics", prometheusHandler())
}
func prometheusHandler() gin.HandlerFunc {
h := promhttp.Handler()
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
// adding a service monitor to k8s example
//
// apiVersion: monitoring.coreos.com/v1
// kind: ServiceMonitor
// metadata:
// name: {monitor name}
// namespace: metrics
// spec:
// endpoints:
// - port: metrics
// jobLabel: jobLabel
// namespaceSelector:
// matchNames:
// - metrics
// selector:
// matchLabels: # the service must have a mathcing label
// app: {service name}