formula-prometheus/prometheus/files/prometheus.yml

179 lines
7.7 KiB
YAML
Raw Normal View History

{%- 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 %}
rule_files:
- {{ server.dir.config_in_container }}/alerts.yml
{%- set static_target = {} %}
{%- 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: []}) %}
{%- endif %}
{%- for target in job.get('endpoint') %}
{%- do static_target[job_name].append(target) %}
{%- endfor %}
{%- endfor %}
{%- endfor %}
scrape_configs:
{%- for job_name, targets in static_target.iteritems() %}
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
{%- set nodes = [] %}
{%- for target in targets + 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: {{ 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 %}
static_configs:
- targets: [{{ nodes | join(',') }}]
{%- endif %}
{%- endfor %}
{%- if server.get('target', {}).get('kubernetes', {}).get('enabled', True) %}
{%- 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: {{ 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 %}
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: {{ 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 %}
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: {{ 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 %}
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: {{ 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 %}
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
- job_name: 'kubernetes-service-endpoint'
scheme: https
tls_config:
insecure_skip_verify: true
{% 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 %}
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: {{ 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 %}
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
{% 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 %}
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: {{ 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 %}
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 %}
{%- if server.get('target', {}).get('dns', {}).get('enabled', True) %}
{%- 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 %}