I'm using the helm prometheus-operator chart: https://github.com/helm/charts/blob/master/stable/prometheus-operator/values.yaml and I expected it to get my custom metrics from my golang api as I did previously by "hardcoding" the name of the service and the port in the values.yml file:
scrape_configs:
- job_name: 'custom-api'
static_configs:
- targets: ['custom-api-service.backend.svc.cluster.local:8000']
However, as I have more microservices I know that it can also be done dynamically using the _meta
tags. Example:
__meta_kubernetes_service_name
However, I haven't figure it out what should I modify from the values.yaml file to make it work.
Grafana is getting my cpu and memory usage from the custom-api
but custom-api
is not appearing in the targets tab from the prometheus dashboard which is weird...
These are my services:
apiVersion: v1
kind: Service
metadata:
name: custom-api-service
namespace: backend
labels:
service: custom-api-service
spec:
type: NodePort
ports:
- port: 8000
targetPort: 8000
nodePort: 30080
protocol: TCP
name: custom-api
selector:
component: goapi
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: servicemonitor
namespace: backend
labels:
service: servicemonitor
spec:
selector:
matchLabels:
service: custom-api-service
endpoints:
- port: custom-api