Add more generic auto-discovery for statics
Change-Id: I4d20d6f126ec4698bbdae34c8476fe325363bced
This commit is contained in:
parent
5f644a1921
commit
9f4d99cb3a
2 changed files with 53 additions and 53 deletions
|
@ -1,4 +1,4 @@
|
||||||
{%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': []}}} %}
|
{%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': [], 'target': {}}}} %}
|
||||||
{%- for service_name, service in pillar.items() %}
|
{%- for service_name, service in pillar.items() %}
|
||||||
{%- if service.get('_support', {}).get('prometheus', {}).get('enabled', False) %}
|
{%- if service.get('_support', {}).get('prometheus', {}).get('enabled', False) %}
|
||||||
{%- set grains_fragment_file = service_name+'/meta/prometheus.yml' %}
|
{%- set grains_fragment_file = service_name+'/meta/prometheus.yml' %}
|
||||||
|
|
|
@ -8,56 +8,56 @@ global:
|
||||||
rule_files:
|
rule_files:
|
||||||
- {{ server.dir.config_in_container }}/alerts.yml
|
- {{ server.dir.config_in_container }}/alerts.yml
|
||||||
|
|
||||||
scrape_configs:
|
{%- set static_target = {} %}
|
||||||
{%- set telegraf_nodes = [] %}
|
|
||||||
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
||||||
{%- if 'telegraf' in node_grains.get('services') %}
|
{%- set static_grain = node_grains.get('prometheus', {}).get('server', {}).get('target', {}).get('static', {}) %}
|
||||||
{%- set prometheus_client = node_grains.get('telegraf').get('prometheus_client') %}
|
{%- for job_name, job in static_grain.iteritems() %}
|
||||||
{%- set node_ip = prometheus_client.get('address') %}
|
{%- if static_target[job_name] is not defined %}
|
||||||
{%- set node_port = prometheus_client.get('port') %}
|
{%- do static_target.update({job_name: []}) %}
|
||||||
{%- set telegraf_address = "'%s:%d'" | format(node_ip, node_port) %}
|
|
||||||
{%- do telegraf_nodes.append(telegraf_address) %}
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- for target in job.get('endpoint') %}
|
||||||
|
{%- do static_target[job_name].append(target) %}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- endfor %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- if telegraf_nodes|length > 0 %}
|
|
||||||
- job_name: 'telegraf'
|
|
||||||
static_configs:
|
|
||||||
- targets: [{{ telegraf_nodes | join(',') }}]
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
{% if server.get('target', {}).get('etcd') %}
|
scrape_configs:
|
||||||
{%- set etcd_nodes = [] %}
|
{%- for job_name, targets in static_target.iteritems() %}
|
||||||
{%- set etcd_target = server.target.etcd %}
|
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
|
||||||
{%- for node in etcd_target.member %}
|
{%- set nodes = [] %}
|
||||||
{%- set etcd_address = "'%s:%d'" | format(node.host, node.port) %}
|
{%- for target in targets %}
|
||||||
{%- do etcd_nodes.append(etcd_address) %}
|
{%- set address = "'%s:%d'" | format(target.address, target.port) %}
|
||||||
|
{%- do nodes.append(address) %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- if etcd_nodes|length > 0 %}
|
{%- if nodes|length > 0 %}
|
||||||
- job_name: 'etcd'
|
- job_name: {{ job_name }}
|
||||||
{% if etcd_target.scheme %}scheme: {{ etcd_target.scheme }}{%- endif %}
|
{% if job.get('scheme') %}scheme: {{ job.scheme }}{%- endif %}
|
||||||
|
{%- if job.get('tls_config') %}
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
{% if job.tls_config.get('skip_verify') is defined %}insecure_skip_verify: {{ job.tls_config.skip_verify | lower }}{%- endif %}
|
||||||
{% if etcd_target.cert_name is defined %}cert_file: {{ etcd_target.ssl_dir }}/{{ etcd_target.cert_name }}{%- endif %}
|
{% if job.tls_config.get('cert_name') %}cert_file: {{ job.tls_config.ssl_dir }}/{{ job.tls_config.cert_name }}{%- endif %}
|
||||||
{% if etcd_target.key_name is defined %}key_file: {{ etcd_target.ssl_dir }}/{{ etcd_target.key_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:
|
static_configs:
|
||||||
- targets: [{{ etcd_nodes | join(',') }}]
|
- targets: [{{ nodes | join(',') }}]
|
||||||
{%- endif %}
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
|
||||||
{% if server.get('target', {}).get('kubernetes') %}
|
{% if server.get('target', {}).get('kubernetes') %}
|
||||||
|
{%- set kubernetes_target = server.target.kubernetes %}
|
||||||
- job_name: 'kubernetes-api'
|
- job_name: 'kubernetes-api'
|
||||||
scheme: https
|
scheme: https
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
kubernetes_sd_configs:
|
kubernetes_sd_configs:
|
||||||
- api_server: {{ server.target.kubernetes.api_ip }}
|
- api_server: {{ kubernetes_target.api_ip }}
|
||||||
role: endpoints
|
role: endpoints
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
relabel_configs:
|
relabel_configs:
|
||||||
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
|
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
|
||||||
action: keep
|
action: keep
|
||||||
|
@ -68,15 +68,15 @@ scrape_configs:
|
||||||
scheme: https
|
scheme: https
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
kubernetes_sd_configs:
|
kubernetes_sd_configs:
|
||||||
- api_server: {{ server.target.kubernetes.api_ip }}
|
- api_server: {{ kubernetes_target.api_ip }}
|
||||||
role: node
|
role: node
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
relabel_configs:
|
relabel_configs:
|
||||||
- action: labelmap
|
- action: labelmap
|
||||||
regex: __meta_kubernetes_node_label_(.+)
|
regex: __meta_kubernetes_node_label_(.+)
|
||||||
|
@ -86,15 +86,15 @@ scrape_configs:
|
||||||
scheme: https
|
scheme: https
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
kubernetes_sd_configs:
|
kubernetes_sd_configs:
|
||||||
- api_server: {{ server.target.kubernetes.api_ip }}
|
- api_server: {{ kubernetes_target.api_ip }}
|
||||||
role: endpoints
|
role: endpoints
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
relabel_configs:
|
relabel_configs:
|
||||||
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
|
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
|
||||||
action: keep
|
action: keep
|
||||||
|
@ -132,15 +132,15 @@ scrape_configs:
|
||||||
scheme: https
|
scheme: https
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
kubernetes_sd_configs:
|
kubernetes_sd_configs:
|
||||||
- api_server: {{ server.target.kubernetes.api_ip }}
|
- api_server: {{ kubernetes_target.api_ip }}
|
||||||
role: pod
|
role: pod
|
||||||
tls_config:
|
tls_config:
|
||||||
insecure_skip_verify: true
|
insecure_skip_verify: true
|
||||||
{% if server.target.kubernetes.cert_name is defined %}cert_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.cert_name }}{%- endif %}
|
{% if kubernetes_target.get('cert_name') %}cert_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.cert_name }}{%- endif %}
|
||||||
{% if server.target.kubernetes.key_name is defined %}key_file: {{ server.target.kubernetes.ssl_dir }}/{{ server.target.kubernetes.key_name }}{%- endif %}
|
{% if kubernetes_target.get('key_name') %}key_file: {{ kubernetes_target.ssl_dir }}/{{ kubernetes_target.key_name }}{%- endif %}
|
||||||
relabel_configs:
|
relabel_configs:
|
||||||
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
|
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
|
||||||
action: keep
|
action: keep
|
||||||
|
|
Loading…
Reference in a new issue