From 597b0678bfee968ade217f99b3df2334e934b85e Mon Sep 17 00:00:00 2001 From: Bartosz Kupidura Date: Wed, 29 Mar 2017 12:39:52 +0200 Subject: [PATCH] Better grain handling for telegraf Replace '-' to '_' in prometheus config dir Add possibility to add recording rules Change-Id: Ifc85a95ae62cb0f1b810a3b4f718e8d92f9c6209 --- README.rst | 8 ++++++-- prometheus/files/alerts.yml | 6 ++++++ prometheus/files/prometheus.yml | 5 +++-- prometheus/map.jinja | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 754a94e..627a517 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ Configure prometheus server server: enabled: true dir: - config: /srv/volumes/prometheus-config + config: /srv/volumes/prometheus config_in_container: /opt/prometheus/config bind: port: 9090 @@ -30,6 +30,10 @@ Configure prometheus server cert_name: kubelet-client.crt key_name: kubelet-client.key etcd: ${etcd:server:members} + recording: + - name: 'instance:fd_utilization' + query: >- + process_open_fds / process_max_fds alert: PrometheusTargetDown: if: 'up != 1' @@ -63,7 +67,7 @@ Configure alertmanager alertmanager: enabled: true dir: - config: /srv/volumes/prometheus-config + config: /srv/volumes/prometheus bind: address: 0.0.0.0 port: 9093 diff --git a/prometheus/files/alerts.yml b/prometheus/files/alerts.yml index ebafbed..68c1c88 100644 --- a/prometheus/files/alerts.yml +++ b/prometheus/files/alerts.yml @@ -1,5 +1,11 @@ {%- from "prometheus/map.jinja" import server with context %} +{%- if server.recording is defined %} +{%- for recording_rule in server.recording %} +{{ recording_rule.name }} = {{ recording_rule.query }} +{%- endfor %} +{%- endif %} + {%- if server.alert is defined %} {%- for alertname, alert in server.alert.iteritems() %} ALERT {{ alertname }} diff --git a/prometheus/files/prometheus.yml b/prometheus/files/prometheus.yml index 09cc042..0872c02 100644 --- a/prometheus/files/prometheus.yml +++ b/prometheus/files/prometheus.yml @@ -12,8 +12,9 @@ scrape_configs: {%- set telegraf_nodes = [] %} {%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %} {%- if 'telegraf' in node_grains.get('services') %} - {%- set node_ip = node_grains.get('prometheus_client').get('address') %} - {%- set node_port = node_grains.get('prometheus_client').get('port') %} + {%- set prometheus_client = node_grains.get('telegraf').get('prometheus_client') %} + {%- set node_ip = prometheus_client.get('address') %} + {%- set node_port = prometheus_client.get('port') %} {%- set telegraf_address = "'%s:%d'" | format(node_ip, node_port) %} {%- do telegraf_nodes.append(telegraf_address) %} {%- endif %} diff --git a/prometheus/map.jinja b/prometheus/map.jinja index f6a1c70..bdba327 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -1,7 +1,7 @@ {% set server = salt['grains.filter_by']({ 'default': { 'dir': { - 'config': '/srv/volumes/prometheus-config', + 'config': '/srv/volumes/prometheus', 'config_in_container': '/opt/prometheus/config' }, }, @@ -10,7 +10,7 @@ {% set alertmanager = salt['grains.filter_by']({ 'default': { 'dir': { - 'config': '/srv/volumes/prometheus-config', + 'config': '/srv/volumes/prometheus', }, }, }, merge=salt['pillar.get']('prometheus:alertmanager')) %}