Added ability to disable endpoints, alerts and
recording rules and override alerts/recording rules from reclass Change-Id: Ie79409f350f4e7d223955c177718350c38ed8302
This commit is contained in:
parent
91d5be301a
commit
1404088f3c
3 changed files with 34 additions and 41 deletions
|
@ -1,4 +1,4 @@
|
||||||
{%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': [], 'target': {}}}} %}
|
{%- 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' %}
|
||||||
|
|
|
@ -3,43 +3,33 @@
|
||||||
{%- set alerts = {} %}
|
{%- set alerts = {} %}
|
||||||
{%- set recordings = {} %}
|
{%- set recordings = {} %}
|
||||||
|
|
||||||
|
|
||||||
{%- for recording_rule in server.get('recording', []) %}
|
|
||||||
{%- if recording_rule.name not in recordings %}
|
|
||||||
{%- do recordings.update({recording_rule.name: recording_rule.query}) %}
|
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
|
||||||
|
|
||||||
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
||||||
{%- set server_grain = node_grains.get('prometheus', {}).get('server', {}) %}
|
{%- set server_grain = node_grains.get('prometheus', {}).get('server', {}) %}
|
||||||
{%- for recording_rule in server_grain.get('recording', []) %}
|
{%- for recordingname, recording in server_grain.get('recording', {}).iteritems() %}
|
||||||
{%- if recording_rule.name not in recordings %}
|
{%- do recordings.update({recordingname: recording}) %}
|
||||||
{%- do recordings.update({recording_rule.name: recording_rule.query}) %}
|
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- for recording_name, query in recordings.iteritems() %}
|
{%- set recordings = salt['grains.filter_by']({'default': recordings}, merge=server.get('recording', {})) %}
|
||||||
{{ recording_name }} = {{ query }}
|
|
||||||
{%- endfor %}
|
|
||||||
|
|
||||||
{%- for alertname, alert in server.get('alert', {}).iteritems() %}
|
{%- for recordingname, recording in recordings.iteritems() %}
|
||||||
{%- if alertname not in alerts %}
|
{%- if recording.get('enabled', True) %}
|
||||||
{%- do alerts.update({alertname: alert}) %}
|
{{ recordingname }} = {{ recording.query }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
||||||
{%- set server_grain = node_grains.get('prometheus', {}).get('server', {}) %}
|
{%- set server_grain = node_grains.get('prometheus', {}).get('server', {}) %}
|
||||||
{%- for alertname, alert in server_grain.get('alert', {}).iteritems() %}
|
{%- for alertname, alert in server_grain.get('alert', {}).iteritems() %}
|
||||||
{%- if alertname not in alerts %}
|
|
||||||
{%- do alerts.update({alertname: alert}) %}
|
{%- do alerts.update({alertname: alert}) %}
|
||||||
{%- endif %}
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
{%- set alerts = salt['grains.filter_by']({'default': alerts}, merge=server.get('alert', {})) %}
|
||||||
|
|
||||||
{%- for alertname, alert in alerts.iteritems() %}
|
{%- for alertname, alert in alerts.iteritems() %}
|
||||||
ALERT {{ alertname }}
|
{%- if alert.get('enabled', True) %}
|
||||||
|
ALERT {{ alertname }}
|
||||||
IF {{ alert.if }}
|
IF {{ alert.if }}
|
||||||
{%- if alert.for is defined %}FOR {{ alert.for }}{%- endif %}
|
{%- if alert.for is defined %}FOR {{ alert.for }}{%- endif %}
|
||||||
{%- if alert.labels is defined %}
|
{%- if alert.labels is defined %}
|
||||||
|
@ -56,4 +46,5 @@ ALERT {{ alertname }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
}
|
}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
|
@ -25,11 +25,11 @@ scrape_configs:
|
||||||
{%- for job_name, targets in static_target.iteritems() %}
|
{%- for job_name, targets in static_target.iteritems() %}
|
||||||
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
|
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
|
||||||
{%- set nodes = [] %}
|
{%- set nodes = [] %}
|
||||||
{%- for target in targets %}
|
{%- for target in targets + job.get('endpoint', []) %}
|
||||||
{%- set address = "'%s:%d'" | format(target.address, target.port) %}
|
{%- set address = "'%s:%d'" | format(target.address, target.port) %}
|
||||||
{%- do nodes.append(address) %}
|
{%- do nodes.append(address) %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- if nodes|length > 0 %}
|
{%- if nodes|length > 0 and job.get('enabled', True) %}
|
||||||
- job_name: {{ job_name }}
|
- job_name: {{ job_name }}
|
||||||
{% if job.get('scheme') %}scheme: {{ job.scheme }}{%- endif %}
|
{% if job.get('scheme') %}scheme: {{ job.scheme }}{%- endif %}
|
||||||
{%- if job.get('tls_config') %}
|
{%- if job.get('tls_config') %}
|
||||||
|
@ -43,7 +43,7 @@ scrape_configs:
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{% if server.get('target', {}).get('kubernetes') %}
|
{%- if server.get('target', {}).get('kubernetes', {}).get('enabled', True) %}
|
||||||
{%- set kubernetes_target = server.target.kubernetes %}
|
{%- set kubernetes_target = server.target.kubernetes %}
|
||||||
- job_name: 'kubernetes-api'
|
- job_name: 'kubernetes-api'
|
||||||
scheme: https
|
scheme: https
|
||||||
|
@ -164,7 +164,8 @@ scrape_configs:
|
||||||
target_label: kubernetes_pod_name
|
target_label: kubernetes_pod_name
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- for target in server.get('target', {}).get('dns', []) %}
|
{%- if server.get('target', {}).get('dns', {}).get('enabled', True) %}
|
||||||
|
{%- for target in server.get('target', {}).get('dns', {}).get('endpoint', []) %}
|
||||||
- job_name: {{ target.name }}
|
- job_name: {{ target.name }}
|
||||||
dns_sd_configs:
|
dns_sd_configs:
|
||||||
- names:
|
- names:
|
||||||
|
@ -173,4 +174,5 @@ scrape_configs:
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
type: {{ target.type }}
|
type: {{ target.type }}
|
||||||
port: {{ target.port }}
|
port: {{ target.port }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
{%- endif %}
|
||||||
|
|
Loading…
Reference in a new issue