mirror of https://github.com/prometheus/prometheus
Merge pull request #1225 from fabric8io/kubernetes-discovery
KubernetesSD: Create targets for services as well as service endpointspull/1188/head
commit
5f52ed3202
|
@ -28,14 +28,11 @@ scrape_configs:
|
||||||
regex: (?:apiserver|node)
|
regex: (?:apiserver|node)
|
||||||
- action: labelmap
|
- action: labelmap
|
||||||
regex: __meta_kubernetes_node_label_(.+)
|
regex: __meta_kubernetes_node_label_(.+)
|
||||||
replacement: $1
|
|
||||||
- source_labels: [__meta_kubernetes_role]
|
- source_labels: [__meta_kubernetes_role]
|
||||||
action: replace
|
action: replace
|
||||||
regex: (.+)
|
|
||||||
target_label: kubernetes_role
|
target_label: kubernetes_role
|
||||||
replacement: $1
|
|
||||||
|
|
||||||
# Scrape config for services.
|
# Scrape config for service endpoints.
|
||||||
#
|
#
|
||||||
# The relabeling allows the actual service scrape endpoint to be configured
|
# The relabeling allows the actual service scrape endpoint to be configured
|
||||||
# via the following annotations:
|
# via the following annotations:
|
||||||
|
@ -46,7 +43,7 @@ scrape_configs:
|
||||||
# * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
|
# * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
|
||||||
# * `prometheus.io/port`: If the metrics are exposed on a different port to the
|
# * `prometheus.io/port`: If the metrics are exposed on a different port to the
|
||||||
# service then set this appropriately.
|
# service then set this appropriately.
|
||||||
- job_name: 'kubernetes-services'
|
- job_name: 'kubernetes-service-endpoints'
|
||||||
|
|
||||||
kubernetes_sd_configs:
|
kubernetes_sd_configs:
|
||||||
- api_servers:
|
- api_servers:
|
||||||
|
@ -54,19 +51,16 @@ scrape_configs:
|
||||||
in_cluster: true
|
in_cluster: true
|
||||||
|
|
||||||
relabel_configs:
|
relabel_configs:
|
||||||
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
|
- source_labels: [__meta_kubernetes_role, __meta_kubernetes_service_annotation_prometheus_io_scrape]
|
||||||
action: keep
|
action: keep
|
||||||
regex: true
|
regex: endpoint;true
|
||||||
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
|
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
|
||||||
action: replace
|
action: replace
|
||||||
target_label: __scheme__
|
target_label: __scheme__
|
||||||
regex: (https?)
|
regex: (https?)
|
||||||
replacement: $1
|
|
||||||
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
|
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
|
||||||
action: replace
|
action: replace
|
||||||
target_label: __metrics_path__
|
target_label: __metrics_path__
|
||||||
regex: (.+)
|
|
||||||
replacement: $1
|
|
||||||
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
|
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
|
||||||
action: replace
|
action: replace
|
||||||
target_label: __address__
|
target_label: __address__
|
||||||
|
@ -74,19 +68,53 @@ scrape_configs:
|
||||||
replacement: $1:$2
|
replacement: $1:$2
|
||||||
- action: labelmap
|
- action: labelmap
|
||||||
regex: __meta_kubernetes_service_label_(.+)
|
regex: __meta_kubernetes_service_label_(.+)
|
||||||
replacement: $1
|
|
||||||
- source_labels: [__meta_kubernetes_role]
|
- source_labels: [__meta_kubernetes_role]
|
||||||
action: replace
|
action: replace
|
||||||
regex: (.+)
|
|
||||||
target_label: kubernetes_role
|
target_label: kubernetes_role
|
||||||
replacement: $1
|
|
||||||
- source_labels: [__meta_kubernetes_service_namespace]
|
- source_labels: [__meta_kubernetes_service_namespace]
|
||||||
action: replace
|
action: replace
|
||||||
regex: (.+)
|
|
||||||
target_label: kubernetes_namespace
|
target_label: kubernetes_namespace
|
||||||
replacement: $1
|
|
||||||
- source_labels: [__meta_kubernetes_service_name]
|
- source_labels: [__meta_kubernetes_service_name]
|
||||||
action: replace
|
action: replace
|
||||||
regex: (.+)
|
|
||||||
target_label: kubernetes_name
|
target_label: kubernetes_name
|
||||||
replacement: $1
|
|
||||||
|
# Example scrape config for probing services via the Blackbox Exporter.
|
||||||
|
#
|
||||||
|
# The relabeling allows the actual service scrape endpoint to be configured
|
||||||
|
# via the following annotations:
|
||||||
|
#
|
||||||
|
# * `prometheus.io/probe`: Only probe services that have a value of `true`
|
||||||
|
- job_name: 'kubernetes-services'
|
||||||
|
|
||||||
|
metrics_path: /probe
|
||||||
|
params:
|
||||||
|
module: [http_2xx]
|
||||||
|
|
||||||
|
kubernetes_sd_configs:
|
||||||
|
- api_servers:
|
||||||
|
- 'https://kubernetes.default.svc'
|
||||||
|
in_cluster: true
|
||||||
|
|
||||||
|
relabel_configs:
|
||||||
|
- source_labels: [__meta_kubernetes_role, __meta_kubernetes_service_annotation_prometheus_io_probe]
|
||||||
|
action: keep
|
||||||
|
regex: service;true
|
||||||
|
- source_labels: []
|
||||||
|
target_label: __address__
|
||||||
|
replacement: prom-blackbox.default.svc:9115
|
||||||
|
- source_labels: [__address__]
|
||||||
|
regex: (.*)(:80)?
|
||||||
|
target_label: __param_target
|
||||||
|
- source_labels: [__param_target]
|
||||||
|
target_label: instance
|
||||||
|
- action: labelmap
|
||||||
|
regex: __meta_kubernetes_service_label_(.+)
|
||||||
|
- source_labels: [__meta_kubernetes_role]
|
||||||
|
action: replace
|
||||||
|
target_label: kubernetes_role
|
||||||
|
- source_labels: [__meta_kubernetes_service_namespace]
|
||||||
|
action: replace
|
||||||
|
target_label: kubernetes_namespace
|
||||||
|
- source_labels: [__meta_kubernetes_service_name]
|
||||||
|
action: replace
|
||||||
|
target_label: kubernetes_name
|
||||||
|
|
|
@ -501,7 +501,6 @@ func (kd *Discovery) updateServiceTargetGroup(service *Service, eps *Endpoints)
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
serviceNamespaceLabel: model.LabelValue(service.ObjectMeta.Namespace),
|
serviceNamespaceLabel: model.LabelValue(service.ObjectMeta.Namespace),
|
||||||
serviceNameLabel: model.LabelValue(service.ObjectMeta.Name),
|
serviceNameLabel: model.LabelValue(service.ObjectMeta.Name),
|
||||||
roleLabel: model.LabelValue("service"),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,6 +514,12 @@ func (kd *Discovery) updateServiceTargetGroup(service *Service, eps *Endpoints)
|
||||||
tg.Labels[model.LabelName(labelName)] = model.LabelValue(v)
|
tg.Labels[model.LabelName(labelName)] = model.LabelValue(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t := model.LabelSet{
|
||||||
|
model.AddressLabel: model.LabelValue(service.ObjectMeta.Name + "." + service.ObjectMeta.Namespace + ".svc"),
|
||||||
|
roleLabel: model.LabelValue("service"),
|
||||||
|
}
|
||||||
|
tg.Targets = append(tg.Targets, t)
|
||||||
|
|
||||||
// Now let's loop through the endpoints & add them to the target group with appropriate labels.
|
// Now let's loop through the endpoints & add them to the target group with appropriate labels.
|
||||||
for _, ss := range eps.Subsets {
|
for _, ss := range eps.Subsets {
|
||||||
epPort := ss.Ports[0].Port
|
epPort := ss.Ports[0].Port
|
||||||
|
@ -526,7 +531,10 @@ func (kd *Discovery) updateServiceTargetGroup(service *Service, eps *Endpoints)
|
||||||
}
|
}
|
||||||
address := fmt.Sprintf("%s:%d", ipAddr, epPort)
|
address := fmt.Sprintf("%s:%d", ipAddr, epPort)
|
||||||
|
|
||||||
t := model.LabelSet{model.AddressLabel: model.LabelValue(address)}
|
t := model.LabelSet{
|
||||||
|
model.AddressLabel: model.LabelValue(address),
|
||||||
|
roleLabel: model.LabelValue("endpoint"),
|
||||||
|
}
|
||||||
|
|
||||||
tg.Targets = append(tg.Targets, t)
|
tg.Targets = append(tg.Targets, t)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue