Skip to content

Instantly share code, notes, and snippets.

@sudhirpandey
Created July 23, 2018 10:21
Show Gist options
  • Save sudhirpandey/fd53e9295c0d8ff9fbe53be27a932793 to your computer and use it in GitHub Desktop.
Save sudhirpandey/fd53e9295c0d8ff9fbe53be27a932793 to your computer and use it in GitHub Desktop.

Revisions

  1. sudhirpandey created this gist Jul 23, 2018.
    42 changes: 42 additions & 0 deletions prometheus.config
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    # Example scrape config for pods
    #
    # The relabeling allows the actual pod scrape endpoint to be configured via the
    # following annotations:
    #
    # * `prometheus.io/scrape`: Only scrape pods that have a value of `true`
    # * `prometheus.io/path`: If the metrics path is not `/metrics` override this. This
    # will be the same for every container in the pod that is scraped.
    # * this will scrape every container in a pod with `prometheus.io/scrape` set to true and the
    port is name `metrics` in the container
    # * note `prometheus.io/port` is no longer honored. You must name the port(s) to scrape `metrics`
    # Also, in some of the issues I read, there was mention of a container role, but I couldn't get
    # that to work - or find any more info on it.
    - job_name: 'kubernetes-pods'

    kubernetes_sd_configs:
    - role: pod

    relabel_configs:
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
    action: keep
    regex: true
    - source_labels: [__meta_kubernetes_pod_container_port_name]
    action: keep
    regex: metrics(-.*)?
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
    action: replace
    target_label: __metrics_path__
    regex: (.+)
    - source_labels: [ __address__, __meta_kubernetes_pod_container_port_number]
    action: replace
    regex: (.+):(?:\d+);(\d+)
    replacement: ${1}:${2}
    target_label: __address__
    - action: labelmap
    regex: __meta_kubernetes_pod_label_(.+)
    - source_labels: [__meta_kubernetes_namespace]
    action: replace
    target_label: kubernetes_namespace
    - source_labels: [__meta_kubernetes_pod_name]
    action: replace
    target_label: kubernetes_pod_name