2017-03-09 06:12:27 -05:00
|
|
|
{%- from "prometheus/map.jinja" import server with context %}
|
|
|
|
|
|
|
|
global:
|
|
|
|
{%- if server.get('config', {}).global is defined %}
|
|
|
|
{{ server.config.global | yaml(False) | indent(2, true) }}
|
|
|
|
{%- endif %}
|
|
|
|
|
2017-05-24 07:20:21 -04:00
|
|
|
{%- if server.get('config', {}).get('alertmanager') %}
|
|
|
|
alerting:
|
|
|
|
alertmanagers:
|
|
|
|
{%- for name, alertmanager in server.config.alertmanager.iteritems() %}
|
|
|
|
{%- if alertmanager.get('enabled', True) %}
|
|
|
|
# {{ name }}
|
|
|
|
{%- if alertmanager.static_configs is defined %}
|
|
|
|
- static_configs:
|
|
|
|
- targets: {{ alertmanager.static_configs.get('target', [])|yaml }}
|
|
|
|
{%- elif alertmanager.dns_sd_configs is defined %}
|
|
|
|
- dns_sd_configs:
|
|
|
|
- names: {{ alertmanager.dns_sd_configs.get('domain', [])|yaml }}
|
|
|
|
type: {{ alertmanager.dns_sd_configs.type }}
|
|
|
|
port: {{ alertmanager.dns_sd_configs.port }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
|
2017-05-29 09:05:06 -04:00
|
|
|
{%- if server.get('config', {}).get('remote_write') %}
|
|
|
|
remote_write:
|
|
|
|
{%- for name, remote_endpoint in server.config.remote_write.iteritems() %}
|
|
|
|
{%- if remote_endpoint.get('enabled', True) %}
|
|
|
|
# {{ name }}
|
|
|
|
- url: {{ remote_endpoint.url }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
|
2017-03-09 06:12:27 -05:00
|
|
|
rule_files:
|
2017-05-17 10:00:52 -04:00
|
|
|
- alerts.yml
|
2017-03-09 06:12:27 -05:00
|
|
|
|
2017-04-13 04:21:19 -04:00
|
|
|
{%- set static_target = {} %}
|
2017-03-09 06:12:27 -05:00
|
|
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
2017-04-13 04:21:19 -04:00
|
|
|
{%- set static_grain = node_grains.get('prometheus', {}).get('server', {}).get('target', {}).get('static', {}) %}
|
|
|
|
{%- for job_name, job in static_grain.iteritems() %}
|
|
|
|
{%- if static_target[job_name] is not defined %}
|
|
|
|
{%- do static_target.update({job_name: []}) %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- for target in job.get('endpoint') %}
|
|
|
|
{%- do static_target[job_name].append(target) %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endfor %}
|
2017-03-09 06:12:27 -05:00
|
|
|
{%- endfor %}
|
|
|
|
|
2017-04-13 04:21:19 -04:00
|
|
|
scrape_configs:
|
|
|
|
{%- for job_name, targets in static_target.iteritems() %}
|
|
|
|
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
|
|
|
|
{%- set nodes = [] %}
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- for target in targets + job.get('endpoint', []) %}
|
2017-04-13 04:21:19 -04:00
|
|
|
{%- set address = "'%s:%d'" | format(target.address, target.port) %}
|
|
|
|
{%- do nodes.append(address) %}
|
2017-03-09 06:12:27 -05:00
|
|
|
{%- endfor %}
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- if nodes|length > 0 and job.get('enabled', True) %}
|
2017-04-13 04:21:19 -04:00
|
|
|
- job_name: {{ job_name }}
|
|
|
|
{% if job.get('scheme') %}scheme: {{ job.scheme }}{%- endif %}
|
|
|
|
{%- if job.get('tls_config') %}
|
2017-03-30 09:43:41 -04:00
|
|
|
tls_config:
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if job.tls_config.get('skip_verify') is defined %}insecure_skip_verify: {{ job.tls_config.skip_verify | lower }}{%- endif %}
|
|
|
|
{% if job.tls_config.get('cert_name') %}cert_file: {{ job.tls_config.ssl_dir }}/{{ job.tls_config.cert_name }}{%- endif %}
|
|
|
|
{% if job.tls_config.get('key_name') %}key_file: {{ job.tls_config.ssl_dir }}/{{ job.tls_config.key_name }}{%- endif %}
|
|
|
|
{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
static_configs:
|
2017-04-13 04:21:19 -04:00
|
|
|
- targets: [{{ nodes | join(',') }}]
|
2017-03-09 06:12:27 -05:00
|
|
|
{%- endif %}
|
2017-04-13 04:21:19 -04:00
|
|
|
{%- endfor %}
|
2017-03-09 06:12:27 -05:00
|
|
|
|
2017-05-12 11:30:35 -04:00
|
|
|
{%- if server.get('target', {}).get('kubernetes', {}).get('enabled', False) %}
|
2017-04-13 04:21:19 -04:00
|
|
|
{%- set kubernetes_target = server.target.kubernetes %}
|
2017-03-09 06:12:27 -05:00
|
|
|
- job_name: 'kubernetes-api'
|
|
|
|
scheme: https
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
kubernetes_sd_configs:
|
2017-04-13 04:21:19 -04:00
|
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
2017-03-09 06:12:27 -05:00
|
|
|
role: endpoints
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
relabel_configs:
|
|
|
|
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
|
|
|
|
action: keep
|
|
|
|
regex: default;kubernetes;https
|
|
|
|
|
|
|
|
|
|
|
|
- job_name: 'kubernetes-node'
|
|
|
|
scheme: https
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
kubernetes_sd_configs:
|
2017-04-13 04:21:19 -04:00
|
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
2017-03-09 06:12:27 -05:00
|
|
|
role: node
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
relabel_configs:
|
|
|
|
- action: labelmap
|
|
|
|
regex: __meta_kubernetes_node_label_(.+)
|
|
|
|
|
|
|
|
|
|
|
|
- job_name: 'kubernetes-service-endpoint'
|
|
|
|
scheme: https
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
kubernetes_sd_configs:
|
2017-04-13 04:21:19 -04:00
|
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
2017-03-09 06:12:27 -05:00
|
|
|
role: endpoints
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
relabel_configs:
|
|
|
|
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
|
|
|
|
action: keep
|
|
|
|
regex: true
|
|
|
|
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
|
|
|
|
action: replace
|
|
|
|
target_label: __scheme__
|
|
|
|
regex: (https?)
|
|
|
|
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
|
|
|
|
action: replace
|
|
|
|
target_label: __metrics_path__
|
|
|
|
regex: (.+)
|
|
|
|
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
|
|
|
|
action: replace
|
|
|
|
target_label: __address__
|
|
|
|
regex: (.+)(?::\d+);(\d+)
|
|
|
|
replacement: $1:$2
|
|
|
|
- action: labelmap
|
|
|
|
regex: __meta_kubernetes_service_label_(.+)
|
|
|
|
- source_labels: [__meta_kubernetes_service_namespace]
|
|
|
|
action: replace
|
|
|
|
target_label: kubernetes_namespace
|
|
|
|
- source_labels: [__meta_kubernetes_service_name]
|
|
|
|
action: replace
|
|
|
|
target_label: kubernetes_name
|
|
|
|
- source_labels: [__meta_kubernetes_pod_node_name]
|
|
|
|
action: replace
|
|
|
|
target_label: kubernetes_io_hostname
|
|
|
|
- source_labels: [__meta_kubernetes_pod_name]
|
|
|
|
action: replace
|
|
|
|
target_label: kubernetes_pod_name
|
|
|
|
|
|
|
|
|
|
|
|
- job_name: 'kubernetes-pod'
|
|
|
|
scheme: https
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
kubernetes_sd_configs:
|
2017-04-13 04:21:19 -04:00
|
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
2017-03-09 06:12:27 -05:00
|
|
|
role: pod
|
|
|
|
tls_config:
|
|
|
|
insecure_skip_verify: true
|
2017-04-13 04:21:19 -04:00
|
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
relabel_configs:
|
|
|
|
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
|
|
|
|
action: keep
|
|
|
|
regex: true
|
|
|
|
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
|
|
|
|
action: replace
|
|
|
|
target_label: __metrics_path__
|
|
|
|
regex: (.+)
|
|
|
|
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
|
|
|
|
action: replace
|
|
|
|
regex: (.+):(?:\d+);(\d+)
|
|
|
|
replacement: ${1}:${2}
|
|
|
|
target_label: __address__
|
|
|
|
- action: labelmap
|
|
|
|
regex: __meta_kubernetes_pod_label_(.+)
|
|
|
|
- source_labels: [__meta_kubernetes_pod_namespace]
|
|
|
|
action: replace
|
|
|
|
target_label: kubernetes_namespace
|
|
|
|
- source_labels: [__meta_kubernetes_pod_name]
|
|
|
|
action: replace
|
|
|
|
target_label: kubernetes_pod_name
|
|
|
|
{%- endif %}
|
|
|
|
|
2017-05-12 11:30:35 -04:00
|
|
|
{%- if server.get('target', {}).get('dns', {}).get('enabled', False) %}
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- for target in server.get('target', {}).get('dns', {}).get('endpoint', []) %}
|
2017-03-29 13:19:34 -04:00
|
|
|
- job_name: {{ target.name }}
|
2017-03-09 06:12:27 -05:00
|
|
|
dns_sd_configs:
|
|
|
|
- names:
|
2017-03-29 13:19:34 -04:00
|
|
|
{%- for domain in target.domain %}
|
|
|
|
- {{ domain }}
|
|
|
|
{%- endfor %}
|
|
|
|
type: {{ target.type }}
|
|
|
|
port: {{ target.port }}
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|