Reputation: 1369
My Pod is not appearing in the prometheus targets
the application is exposing metrics '/metrics'
I added a service monitor to expose the service
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: abc
# Change this to the namespace the Prometheus instance is running in
# namespace: default
labels:
app: abc
release: prometheus
spec:
selector:
matchLabels:
app: abc # target gitlab service
endpoints:
- port: http
interval: 15s
path: /metrics
but still prometheus can't read the metrics
Upvotes: 3
Views: 837
Reputation: 1369
make sure that your pod has a label called "app"
Labels: app=<appname>
if you are using helpm chart add the label in the helper in {{chart-name}}\templates_helpers.tpl
{{/*
Selector labels
*/}}
{{- define "<appname>.selectorLabels" -}}
app.kubernetes.io/name: {{ include "<appname>.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ .Release.Name }} # <======================================= add this
{{- end }}
replace "< appname >" with your app name
check if your pod appeared in http://localhost:9090/config
rule_files:
- /etc/prometheus/rules/prometheus-prometheus-kube-prometheus-prometheus-rulefiles-0/*.yaml
scrape_configs:
- job_name: default/<appname>y/0
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
relabel_configs:
- source_labels: [__meta_kubernetes_service_label_app]
separator: ;
regex:
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: http
replacement: $1
action: keep
Upvotes: 2