prometheus-postgres-exporter add metrics to bitnami/kube-prometheus

8/27/2021

I have a cluster deployed with: https://bitnami.com/stack/prometheus-operator/helm and https://github.com/prometheus-community/postgres_exporter

How to properly add own metrics to the prometheus-operator list of metrics that postgres_exporter exports ?

I tried it that way:

helm upgrade kube-prometheus bitnami/kube-prometheus \
    --set prometheus.additionalScrapeConfigs.enabled=true \
    --set prometheus.additionalScrapeConfigs.type=internal \
    --set prometheus.additionalScrapeConfigs.internal.jobList=
      - job_name: 'prometheus-postgres-exporter' 
        static_configs:
          - targets: ['prometheus-postgres-exporter.default:80']

but it doesn't work ('job_name:' are not added to the Prometheus Configuration).

-- stackuser
helm3
kubernetes
kubernetes-helm
prometheus
prometheus-operator

1 Answer

8/31/2021

Use ServiceMonitors if using Prometheus Operator.

Configure the following block under the values.yaml in the postgres-exporter helm chart.This allows Prometheus Operator to read and configure jobs automatically.

serviceMonitor:
  # When set true then use a ServiceMonitor to configure scraping
  enabled: true
  # Set the namespace the ServiceMonitor should be deployed
  namespace: <namespace where prometheus operator is deployed.>
  # Set how frequently Prometheus should scrape
  interval: 30s
  # Set path to cloudwatch-exporter telemtery-path
  telemetryPath: /metrics
  # Set labels for the ServiceMonitor, use this to define your scrape label for Prometheus Operator
  # labels:
  # Set timeout for scrape
  # timeout: 10s
  # Set of labels to transfer from the Kubernetes Service onto the target
  # targetLabels: []
  # MetricRelabelConfigs to apply to samples before ingestion
  # metricRelabelings: []
-- rohatgisanat
Source: StackOverflow