[prometheus] Allow custom alert rules to be configured.
This patch extends the configuration task for prometheus to allow the operator to pass a(set) of prometheus alert rules files, that will be used by alertmanager to produce alerts. This functionality is only enabled when the prometheus-alertmanager service is enabled. Change-Id: I882759c3774f43640631c1058f8a9cb24e7a60d2 Closes-Bug: #1776529 Signed-off-by: Jorge Niedbalski <jorge.niedbalski@linaro.org>
This commit is contained in:
parent
9d2770db11
commit
0ec41f2092
@ -138,4 +138,5 @@
|
||||
- inventory_hostname in groups[service.group]
|
||||
- service.enabled | bool
|
||||
- config_json.changed | bool
|
||||
or prometheus_alertmanager_confs.changed | bool
|
||||
or prometheus_container.changed | bool
|
||||
|
@ -24,6 +24,32 @@
|
||||
notify:
|
||||
- Restart {{ item.key }} container
|
||||
|
||||
- name: Find custom prometheus alert rules files
|
||||
local_action:
|
||||
module: find
|
||||
path: "{{ node_custom_config }}/prometheus/"
|
||||
pattern: "*.rules"
|
||||
run_once: True
|
||||
register: prometheus_alert_rules
|
||||
when:
|
||||
- enable_prometheus_alertmanager | bool
|
||||
|
||||
- name: Copying over custom prometheus alert rules files
|
||||
vars:
|
||||
service: "{{ prometheus_services['prometheus-server']}}"
|
||||
copy:
|
||||
src: "{{ item.path }}"
|
||||
dest: "{{ node_config_directory }}/prometheus-server/{{ item.path | basename }}"
|
||||
mode: "0660"
|
||||
register: prometheus_confs
|
||||
when:
|
||||
- inventory_hostname in groups[service.group]
|
||||
- service.enabled | bool and enable_prometheus_alertmanager | bool
|
||||
- prometheus_alert_rules is defined and prometheus_alert_rules.files | length > 0
|
||||
with_items: "{{ prometheus_alert_rules.files }}"
|
||||
notify:
|
||||
- Restart prometheus-server container
|
||||
|
||||
- name: Copying over prometheus config file
|
||||
vars:
|
||||
service: "{{ prometheus_services['prometheus-server']}}"
|
||||
@ -44,16 +70,17 @@
|
||||
- name: Copying over prometheus alertmanager config file
|
||||
vars:
|
||||
service: "{{ prometheus_services['prometheus-alertmanager']}}"
|
||||
merge_yaml:
|
||||
sources:
|
||||
- "{{ node_custom_config }}/prometheus/{{ inventory_hostname }}/prometheus-alertmanager.yml"
|
||||
- "{{ node_custom_config }}/prometheus/prometheus-alertmanager.yml"
|
||||
- "{{ role_path }}/templates/prometheus-alertmanager.yml.j2"
|
||||
template:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ node_config_directory }}/prometheus-alertmanager/prometheus-alertmanager.yml"
|
||||
register: prometheus_confs
|
||||
register: prometheus_alertmanager_confs
|
||||
when:
|
||||
- inventory_hostname in groups[service.group]
|
||||
- service.enabled | bool
|
||||
with_first_found:
|
||||
- "{{ node_custom_config }}/prometheus/{{ inventory_hostname }}/prometheus-alertmanager.yml"
|
||||
- "{{ node_custom_config }}/prometheus/prometheus-alertmanager.yml"
|
||||
- "{{ role_path }}/templates/prometheus-alertmanager.yml.j2"
|
||||
notify:
|
||||
- Restart prometheus-alertmanager container
|
||||
|
||||
@ -81,6 +108,7 @@
|
||||
name: "{{ item.value.container_name }}"
|
||||
image: "{{ item.value.image }}"
|
||||
volumes: "{{ item.value.volumes }}"
|
||||
dimensions: "{{ item.value.dimensions }}"
|
||||
register: check_prometheus_containers
|
||||
when:
|
||||
- kolla_action != "config"
|
||||
|
@ -7,6 +7,15 @@
|
||||
"owner": "prometheus",
|
||||
"perm": "0600"
|
||||
}
|
||||
{% if enable_prometheus_alertmanager %}
|
||||
,{
|
||||
"source": "{{ container_config_directory }}/*.rules",
|
||||
"dest": "/etc/prometheus/",
|
||||
"optional": true,
|
||||
"owner": "prometheus",
|
||||
"perm": "0600"
|
||||
}
|
||||
{% endif %}
|
||||
],
|
||||
"permissions": [
|
||||
{
|
||||
|
@ -5,6 +5,13 @@ global:
|
||||
external_labels:
|
||||
monitor: 'kolla'
|
||||
|
||||
{% if prometheus_alert_rules is defined and prometheus_alert_rules.files | length > 0 %}
|
||||
rule_files:
|
||||
{% for rule in prometheus_alert_rules.files %}
|
||||
- "/etc/prometheus/{{ rule.path | basename }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
scrape_configs:
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
|
Loading…
Reference in New Issue
Block a user