This repo build docker image for python-custom-metrics
which contains code sample for tracing custom metrics for prometheus using prometheus-client and python flask app that exposed custom defined metrics on metrics endpoint. For quick local setup docker-compose is available and for K8S, helm template is available.
docker-compose Commands
Docker-compose contains:
- prometheus
- grafana
- python-app
- grafana-dashboard
docker-compose build python-app
docker-compose up
docker-compose down
docker-compose ps
Steps for prometheus service monitor
kubectl get prometheus -A
kubectl get prometheus -n <NAMESPACE> <NAME> -o=jsonpath='{.spec.serviceMonitorSelector}'
Output:
{"matchLabels":{"release":"kube-prometheus-stack"}}
- Update the namespace under metadata from Step 1 output.
- Add the prometheus labels from above command output (release:kube-prometheus-stack) under metadata > labels
- Update endpoints path (if different than metrics)
- Update the custom metrics service namespace under namespaceSelector.matchNames
Sample service monitor template:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
release: kube-prometheus-stack
name: python-custom-metrics-sm
namespace: monitoring
spec:
endpoints:
- path: /metrics
port: metrics
interval: 60s
namespaceSelector:
matchNames:
- databricks-cd
selector:
matchLabels:
run: python-custom-metrics