Skip to content

Instantly share code, notes, and snippets.

@reachlin
Created April 19, 2017 07:06
Show Gist options
  • Save reachlin/a98b90afcbff4604c90c183a0169474f to your computer and use it in GitHub Desktop.
Save reachlin/a98b90afcbff4604c90c183a0169474f to your computer and use it in GitHub Desktop.

Revisions

  1. reachlin created this gist Apr 19, 2017.
    61 changes: 61 additions & 0 deletions prometheus.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    // For all the confusing Prometheus configuration and
    // regular expressions,
    // explained in examples.


    // Remember, there are default values for each item if it's missing.
    // regex is (.*),
    // replacement is $1,
    // separator is ;
    // ,and action is replace

    relabel_configs:
    - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
    action: keep
    regex: true
    // keep targets with label __meta_kubernetes_service_annotation_prometheus_io_scrape equals 'true',
    // which means the user added prometheus.io/scrape: true in the service's annotation.

    - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
    action: replace
    target_label: __scheme__
    regex: (https?)
    // if __meta_kubernetes_service_annotation_prometheus_io_scheme is http or https, replace __scheme__ with its value that is the default replacement: $1.
    // this means the user added prometheus.io/scheme in the service's annotation.

    - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
    action: replace
    target_label: __metrics_path__
    regex: (.+)
    // this is also for service annotation of prometheus, if the user overrides the scrape path,
    // its value will be put in __metrics_path__

    - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
    action: replace
    target_label: __address__
    regex: (.+)(?::\d+);(\d+)
    replacement: $1:$2
    // if the user added prometheus.io/port in the service annotation,
    // use this port to replace the port in __address__

    // all above rules are for handling prometheus annotation: https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml

    - action: labelmap
    regex: __meta_kubernetes_service_label_(.+)
    // all __meta_kubernetes_service_label_(.+) will be changed to the (.+)
    // e.g. __meta_kubernetes_service_label_app='armada-api' to app='armada-api'

    - source_labels: [__meta_kubernetes_namespace]
    action: replace
    target_label: kubernetes_namespace
    // if __meta_kubernetes_namespace matches .*, put its value in label kubernetes_namespace

    - source_labels: [__meta_kubernetes_service_name]
    action: replace
    target_label: service_name
    // if __meta_kubernetes_service_name matches .*, put its value in label service_name

    - source_labels: [__meta_kubernetes_pod_node_name]
    action: replace
    target_label: hostname
    // if __meta_kubernetes_pod_node_name matches .*, put its value in label hostname