mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 06:59:40 -08:00
Merge branch 'k8s_sd_metrics' of https://github.com/dominikschulz/prometheus into dominikschulz-k8s_sd_metrics
This commit is contained in:
commit
06555bde93
|
@ -83,6 +83,8 @@ func (e *Endpoints) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
|
|
||||||
e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("endpoints", "add").Inc()
|
||||||
|
|
||||||
eps, err := convertToEndpoints(o)
|
eps, err := convertToEndpoints(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.logger.With("err", err).Errorln("converting to Endpoints object failed")
|
e.logger.With("err", err).Errorln("converting to Endpoints object failed")
|
||||||
|
@ -91,6 +93,8 @@ func (e *Endpoints) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(e.buildEndpoints(eps))
|
send(e.buildEndpoints(eps))
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
|
eventCount.WithLabelValues("endpoints", "update").Inc()
|
||||||
|
|
||||||
eps, err := convertToEndpoints(o)
|
eps, err := convertToEndpoints(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.logger.With("err", err).Errorln("converting to Endpoints object failed")
|
e.logger.With("err", err).Errorln("converting to Endpoints object failed")
|
||||||
|
@ -99,6 +103,8 @@ func (e *Endpoints) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(e.buildEndpoints(eps))
|
send(e.buildEndpoints(eps))
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("endpoints", "delete").Inc()
|
||||||
|
|
||||||
eps, err := convertToEndpoints(o)
|
eps, err := convertToEndpoints(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.logger.With("err", err).Errorln("converting to Endpoints object failed")
|
e.logger.With("err", err).Errorln("converting to Endpoints object failed")
|
||||||
|
@ -129,9 +135,18 @@ func (e *Endpoints) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
// TODO(fabxc): potentially remove add and delete event handlers. Those should
|
// TODO(fabxc): potentially remove add and delete event handlers. Those should
|
||||||
// be triggered via the endpoint handlers already.
|
// be triggered via the endpoint handlers already.
|
||||||
AddFunc: func(o interface{}) { serviceUpdate(o) },
|
AddFunc: func(o interface{}) {
|
||||||
UpdateFunc: func(_, o interface{}) { serviceUpdate(o) },
|
eventCount.WithLabelValues("service", "add").Inc()
|
||||||
DeleteFunc: func(o interface{}) { serviceUpdate(o) },
|
serviceUpdate(o)
|
||||||
|
},
|
||||||
|
UpdateFunc: func(_, o interface{}) {
|
||||||
|
eventCount.WithLabelValues("service", "update").Inc()
|
||||||
|
serviceUpdate(o)
|
||||||
|
},
|
||||||
|
DeleteFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("service", "delete").Inc()
|
||||||
|
serviceUpdate(o)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Block until the target provider is explicitly canceled.
|
// Block until the target provider is explicitly canceled.
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/prometheus/config"
|
"github.com/prometheus/prometheus/config"
|
||||||
|
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
|
@ -37,6 +38,27 @@ const (
|
||||||
namespaceLabel = metaLabelPrefix + "namespace"
|
namespaceLabel = metaLabelPrefix + "namespace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
eventCount = prometheus.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "prometheus_sd_kubernetes_events_total",
|
||||||
|
Help: "The number of Kubernetes events handled.",
|
||||||
|
},
|
||||||
|
[]string{"role", "event"},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
prometheus.MustRegister(eventCount)
|
||||||
|
|
||||||
|
// Initialize metric vectors.
|
||||||
|
for _, role := range []string{"endpoints", "node", "pod", "service"} {
|
||||||
|
for _, evt := range []string{"add", "delete", "update"} {
|
||||||
|
eventCount.WithLabelValues(role, evt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Kubernetes implements the TargetProvider interface for discovering
|
// Kubernetes implements the TargetProvider interface for discovering
|
||||||
// targets from Kubernetes.
|
// targets from Kubernetes.
|
||||||
type Kubernetes struct {
|
type Kubernetes struct {
|
||||||
|
|
|
@ -63,6 +63,8 @@ func (n *Node) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
}
|
}
|
||||||
n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
n.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("node", "add").Inc()
|
||||||
|
|
||||||
node, err := convertToNode(o)
|
node, err := convertToNode(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.logger.With("err", err).Errorln("converting to Node object failed")
|
n.logger.With("err", err).Errorln("converting to Node object failed")
|
||||||
|
@ -71,6 +73,8 @@ func (n *Node) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(n.buildNode(node))
|
send(n.buildNode(node))
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("node", "delete").Inc()
|
||||||
|
|
||||||
node, err := convertToNode(o)
|
node, err := convertToNode(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.logger.With("err", err).Errorln("converting to Node object failed")
|
n.logger.With("err", err).Errorln("converting to Node object failed")
|
||||||
|
@ -79,6 +83,8 @@ func (n *Node) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(&config.TargetGroup{Source: nodeSource(node)})
|
send(&config.TargetGroup{Source: nodeSource(node)})
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
|
eventCount.WithLabelValues("node", "update").Inc()
|
||||||
|
|
||||||
node, err := convertToNode(o)
|
node, err := convertToNode(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.logger.With("err", err).Errorln("converting to Node object failed")
|
n.logger.With("err", err).Errorln("converting to Node object failed")
|
||||||
|
|
|
@ -71,6 +71,8 @@ func (p *Pod) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
}
|
}
|
||||||
p.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
p.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("pod", "add").Inc()
|
||||||
|
|
||||||
pod, err := convertToPod(o)
|
pod, err := convertToPod(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logger.With("err", err).Errorln("converting to Pod object failed")
|
p.logger.With("err", err).Errorln("converting to Pod object failed")
|
||||||
|
@ -79,6 +81,8 @@ func (p *Pod) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(p.buildPod(pod))
|
send(p.buildPod(pod))
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("pod", "delete").Inc()
|
||||||
|
|
||||||
pod, err := convertToPod(o)
|
pod, err := convertToPod(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logger.With("err", err).Errorln("converting to Pod object failed")
|
p.logger.With("err", err).Errorln("converting to Pod object failed")
|
||||||
|
@ -87,6 +91,8 @@ func (p *Pod) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(&config.TargetGroup{Source: podSource(pod)})
|
send(&config.TargetGroup{Source: podSource(pod)})
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
|
eventCount.WithLabelValues("pod", "update").Inc()
|
||||||
|
|
||||||
pod, err := convertToPod(o)
|
pod, err := convertToPod(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logger.With("err", err).Errorln("converting to Pod object failed")
|
p.logger.With("err", err).Errorln("converting to Pod object failed")
|
||||||
|
|
|
@ -62,6 +62,8 @@ func (s *Service) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
}
|
}
|
||||||
s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
s.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(o interface{}) {
|
AddFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("service", "add").Inc()
|
||||||
|
|
||||||
svc, err := convertToService(o)
|
svc, err := convertToService(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.With("err", err).Errorln("converting to Service object failed")
|
s.logger.With("err", err).Errorln("converting to Service object failed")
|
||||||
|
@ -70,6 +72,8 @@ func (s *Service) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(s.buildService(svc))
|
send(s.buildService(svc))
|
||||||
},
|
},
|
||||||
DeleteFunc: func(o interface{}) {
|
DeleteFunc: func(o interface{}) {
|
||||||
|
eventCount.WithLabelValues("service", "delete").Inc()
|
||||||
|
|
||||||
svc, err := convertToService(o)
|
svc, err := convertToService(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.With("err", err).Errorln("converting to Service object failed")
|
s.logger.With("err", err).Errorln("converting to Service object failed")
|
||||||
|
@ -78,6 +82,8 @@ func (s *Service) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
send(&config.TargetGroup{Source: serviceSource(svc)})
|
send(&config.TargetGroup{Source: serviceSource(svc)})
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, o interface{}) {
|
UpdateFunc: func(_, o interface{}) {
|
||||||
|
eventCount.WithLabelValues("service", "update").Inc()
|
||||||
|
|
||||||
svc, err := convertToService(o)
|
svc, err := convertToService(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.With("err", err).Errorln("converting to Service object failed")
|
s.logger.With("err", err).Errorln("converting to Service object failed")
|
||||||
|
|
Loading…
Reference in a new issue