mirror of https://github.com/prometheus/prometheus
Add Kubernetes-SD metrics.
parent
552ab61fa1
commit
e1e30f12cd
|
@ -83,12 +83,15 @@ func (e *Endpoints) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
|||
|
||||
e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("endpoint", "add").Inc()
|
||||
send(e.buildEndpoints(o.(*apiv1.Endpoints)))
|
||||
},
|
||||
UpdateFunc: func(_, o interface{}) {
|
||||
eventCount.WithLabelValues("endpoint", "update").Inc()
|
||||
send(e.buildEndpoints(o.(*apiv1.Endpoints)))
|
||||
},
|
||||
DeleteFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("endpoint", "delete").Inc()
|
||||
send(&config.TargetGroup{Source: endpointsSource(o.(*apiv1.Endpoints).ObjectMeta)})
|
||||
},
|
||||
})
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/prometheus/config"
|
||||
|
||||
"github.com/prometheus/common/log"
|
||||
|
@ -35,8 +36,40 @@ const (
|
|||
// in this discovery.
|
||||
metaLabelPrefix = model.MetaLabelPrefix + "kubernetes_"
|
||||
namespaceLabel = metaLabelPrefix + "namespace"
|
||||
|
||||
// Constants for instrumentation.
|
||||
namespace = "prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
eventCount = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Name: "sd_kubernetes_events_total",
|
||||
Help: "The number of Kubernetes events received.",
|
||||
},
|
||||
[]string{"type", "event"},
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(eventCount)
|
||||
|
||||
// Initialize metric vectors.
|
||||
eventCount.WithLabelValues("endpoint", "add")
|
||||
eventCount.WithLabelValues("endpoint", "delete")
|
||||
eventCount.WithLabelValues("endpoint", "update")
|
||||
eventCount.WithLabelValues("node", "add")
|
||||
eventCount.WithLabelValues("node", "delete")
|
||||
eventCount.WithLabelValues("node", "update")
|
||||
eventCount.WithLabelValues("pod", "add")
|
||||
eventCount.WithLabelValues("pod", "delete")
|
||||
eventCount.WithLabelValues("pod", "update")
|
||||
eventCount.WithLabelValues("service", "add")
|
||||
eventCount.WithLabelValues("service", "delete")
|
||||
eventCount.WithLabelValues("service", "update")
|
||||
}
|
||||
|
||||
// Kubernetes implements the TargetProvider interface for discovering
|
||||
// targets from Kubernetes.
|
||||
type Kubernetes struct {
|
||||
|
|
|
@ -63,12 +63,15 @@ func (n *Node) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
|||
}
|
||||
n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("node", "add").Inc()
|
||||
send(n.buildNode(o.(*apiv1.Node)))
|
||||
},
|
||||
DeleteFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("node", "delete").Inc()
|
||||
send(&config.TargetGroup{Source: nodeSource(o.(*apiv1.Node))})
|
||||
},
|
||||
UpdateFunc: func(_, o interface{}) {
|
||||
eventCount.WithLabelValues("node", "update").Inc()
|
||||
send(n.buildNode(o.(*apiv1.Node)))
|
||||
},
|
||||
})
|
||||
|
|
|
@ -71,12 +71,15 @@ func (p *Pod) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
|||
}
|
||||
p.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("pod", "add").Inc()
|
||||
send(p.buildPod(o.(*apiv1.Pod)))
|
||||
},
|
||||
DeleteFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("pod", "delete").Inc()
|
||||
send(&config.TargetGroup{Source: podSource(o.(*apiv1.Pod))})
|
||||
},
|
||||
UpdateFunc: func(_, o interface{}) {
|
||||
eventCount.WithLabelValues("pod", "update").Inc()
|
||||
send(p.buildPod(o.(*apiv1.Pod)))
|
||||
},
|
||||
})
|
||||
|
|
|
@ -61,12 +61,15 @@ func (s *Service) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
|||
}
|
||||
s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("service", "add").Inc()
|
||||
send(s.buildService(o.(*apiv1.Service)))
|
||||
},
|
||||
DeleteFunc: func(o interface{}) {
|
||||
eventCount.WithLabelValues("service", "delete").Inc()
|
||||
send(&config.TargetGroup{Source: serviceSource(o.(*apiv1.Service))})
|
||||
},
|
||||
UpdateFunc: func(_, o interface{}) {
|
||||
eventCount.WithLabelValues("service", "update").Inc()
|
||||
send(s.buildService(o.(*apiv1.Service)))
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue