d949dcef88
This reverts commit db1f492198
.
Change-Id: I4db9c61f1061021e02e2e28ce6132449a7cb5586
245 lines
10 KiB
YAML
245 lines
10 KiB
YAML
{%- 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 %}
|
|
|
|
{%- 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 %}
|
|
|
|
{%- 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 %}
|
|
|
|
rule_files:
|
|
- alerts.yml
|
|
|
|
{%- set static_target = server.target.static %}
|
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
|
{%- 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: {
|
|
'enabled': job.get('enabled', True),
|
|
'scheme': job.get('scheme', 'http')}
|
|
}) %}
|
|
{%- if job.get('tls_config') %}
|
|
{%- do static_target[job_name].update({
|
|
'tls_config': {
|
|
'skip_verify': job.get('tls_config', {}).get('skip_verify', False),
|
|
'cert_name': job.get('tls_config', {}).get('cert_name'),
|
|
'key_name': job.get('tls_config', {}).get('key_name')
|
|
}
|
|
}) %}
|
|
{%- endif %}
|
|
{%- endif %}
|
|
{%- if static_target[job_name]['endpoint'] is not defined %}
|
|
{%- do static_target[job_name].update({'endpoint': []}) %}
|
|
{%- endif %}
|
|
{%- if static_target[job_name]['metric_relabel'] is not defined %}
|
|
{%- do static_target[job_name].update({'metric_relabel': []}) %}
|
|
{%- endif %}
|
|
{%- for target in job.get('endpoint', []) %}
|
|
{%- do static_target[job_name]['endpoint'].append(target) %}
|
|
{%- endfor %}
|
|
{%- for label in job.get('metric_relabel', []) %}
|
|
{%- do static_target[job_name]['metric_relabel'].append(label) %}
|
|
{%- endfor %}
|
|
{%- endfor %}
|
|
{%- endfor %}
|
|
|
|
scrape_configs:
|
|
{%- for job_name, job in static_target.iteritems() %}
|
|
{%- set nodes = [] %}
|
|
{%- for target in job.get('endpoint', []) %}
|
|
{%- set address = "'%s:%d'" | format(target.address, target.port) %}
|
|
{%- do nodes.append(address) %}
|
|
{%- endfor %}
|
|
{%- if nodes|length > 0 and job.get('enabled', True) %}
|
|
- job_name: {{ job_name }}
|
|
{% if job.get('scheme') %}scheme: {{ job.scheme }}{%- endif %}
|
|
{%- if job.get('tls_config') %}
|
|
tls_config:
|
|
{% 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: {{ server.dir.config_in_container }}/{{ job.tls_config.cert_name }}{%- endif %}
|
|
{% if job.tls_config.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ job.tls_config.key_name }}{%- endif %}
|
|
{%- endif %}
|
|
static_configs:
|
|
- targets: [{{ nodes | join(',') }}]
|
|
{%- if job.get('metric_relabel') %}
|
|
metric_relabel_configs:
|
|
{%- for label in job.get('metric_relabel', []) %}
|
|
{%- if label.source_labels is string %}
|
|
{%- set label_list = label.source_labels.split(',') %}
|
|
{%- elif label.source_labels is list %}
|
|
{%- set label_list = label.source_labels %}
|
|
{%- endif %}
|
|
{%- if label_list is defined %}
|
|
- source_labels: {{ label_list }}
|
|
regex: "{{ label.regex }}"
|
|
target_label: "{{ label.target_label }}"
|
|
replacement: {{ label.replacement }}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
|
|
{%- if server.get('target', {}).get('kubernetes', {}).get('enabled', False) %}
|
|
{%- set kubernetes_target = server.target.kubernetes %}
|
|
|
|
- job_name: 'kubernetes-api'
|
|
scheme: https
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
kubernetes_sd_configs:
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
|
role: endpoints
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
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
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
kubernetes_sd_configs:
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
|
role: node
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
relabel_configs:
|
|
- action: labelmap
|
|
regex: __meta_kubernetes_node_label_(.+)
|
|
|
|
{%- if kubernetes_target.get('endpoint', {}).get('enabled') %}
|
|
- job_name: 'kubernetes-service-endpoints'
|
|
scheme: https
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
kubernetes_sd_configs:
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
|
role: endpoints
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
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
|
|
{%- endif %}
|
|
|
|
{%- if kubernetes_target.get('pod', {}).get('enabled') %}
|
|
- job_name: 'kubernetes-pod'
|
|
scheme: https
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
kubernetes_sd_configs:
|
|
- api_server: {{ kubernetes_target.api_ip }}
|
|
role: pod
|
|
tls_config:
|
|
insecure_skip_verify: true
|
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
|
{% if kubernetes_target.get('key_name') %}key_file: {{ server.dir.config_in_container }}/{{ kubernetes_target.key_name }}{%- endif %}
|
|
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 %}
|
|
{%- endif %}
|
|
|
|
{%- if server.get('target', {}).get('dns', {}).get('enabled', False) %}
|
|
{%- for target in server.get('target', {}).get('dns', {}).get('endpoint', []) %}
|
|
- job_name: {{ target.name }}
|
|
dns_sd_configs:
|
|
- names:
|
|
{%- for domain in target.domain %}
|
|
- {{ domain }}
|
|
{%- endfor %}
|
|
type: {{ target.type }}
|
|
port: {{ target.port }}
|
|
{%- endfor %}
|
|
{%- endif %}
|