r/vmalert: Deploy vmalert
`vmalert` is a component of Victoria Metrics. It handles alerting and recording rules, periodically executing queries and dispatching alerts or writing aggregated data back to the TSDB.
This commit is contained in:
2
roles/vmalert/defaults/main.yml
Normal file
2
roles/vmalert/defaults/main.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
vmalert_rules:
|
||||||
|
groups: []
|
||||||
9
roles/vmalert/handlers/main.yml
Normal file
9
roles/vmalert/handlers/main.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
- name: restart vmalert
|
||||||
|
service:
|
||||||
|
name: vmalert
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: reload vmalert
|
||||||
|
uri:
|
||||||
|
url: http://[::1]:8880/-/reload
|
||||||
|
changed_when: true
|
||||||
59
roles/vmalert/tasks/deploy.yml
Normal file
59
roles/vmalert/tasks/deploy.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
- name: ensure victoria metrics config directory exists
|
||||||
|
file:
|
||||||
|
path: /etc/victoria-metrics
|
||||||
|
mode: u=rwx,go=rx
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
state: directory
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
- name: ensure vmalert rules directory exists
|
||||||
|
file:
|
||||||
|
path: /etc/victoria-metrics/rules
|
||||||
|
mode: u=rwx,go=rx
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
state: directory
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
|
- name: ensure vmalert alert rules are configured
|
||||||
|
copy:
|
||||||
|
dest: /etc/victoria-metrics/rules/alerts.yml
|
||||||
|
content: |+
|
||||||
|
{{ vmalert_rules | to_nice_yaml(indent=2) }}
|
||||||
|
mode: u=rw,go=r
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
notify:
|
||||||
|
- reload vmalert
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
- alerts-config
|
||||||
|
|
||||||
|
- name: ensure vmalert environment variables are set
|
||||||
|
template:
|
||||||
|
src: vmalert.sysconfig.j2
|
||||||
|
dest: /etc/sysconfig/vmalert
|
||||||
|
mode: u=rw,go=r
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
notify:
|
||||||
|
- restart vmalert
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
|
- name: ensure vmalert starts at boot
|
||||||
|
service:
|
||||||
|
name: vmalert
|
||||||
|
enabled: true
|
||||||
|
tags:
|
||||||
|
- service
|
||||||
|
- name: flush handlers
|
||||||
|
meta: flush_handlers
|
||||||
|
- name: ensure vmalert is running
|
||||||
|
service:
|
||||||
|
name: vmalert
|
||||||
|
state: started
|
||||||
|
tags:
|
||||||
|
- service
|
||||||
7
roles/vmalert/tasks/main.yml
Normal file
7
roles/vmalert/tasks/main.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
- block:
|
||||||
|
# - import_tasks: install.yml
|
||||||
|
# tags:
|
||||||
|
# - install
|
||||||
|
- import_tasks: deploy.yml
|
||||||
|
tags:
|
||||||
|
- vmalert
|
||||||
12
roles/vmalert/templates/vmalert.sysconfig.j2
Normal file
12
roles/vmalert/templates/vmalert.sysconfig.j2
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{% if vmalert_datasource_url|d %}
|
||||||
|
datasource_url={{ vmalert_datasource_url }}
|
||||||
|
{% endif %}
|
||||||
|
{% if vmalert_notifier_url|d %}
|
||||||
|
notifier_url={{ vmalert_notifier_url }}
|
||||||
|
{% endif %}
|
||||||
|
{% if vmalert_remote_read_url|d %}
|
||||||
|
remoteRead_url={{ vmalert_remote_read_url }}
|
||||||
|
{% endif %}
|
||||||
|
{% if vmalert_remote_write_url|d %}
|
||||||
|
remoteWrite_url={{ vmalert_remote_write_url }}
|
||||||
|
{% endif %}
|
||||||
@@ -6,3 +6,7 @@
|
|||||||
- hosts: vmagent
|
- hosts: vmagent
|
||||||
roles:
|
roles:
|
||||||
- vmagent
|
- vmagent
|
||||||
|
|
||||||
|
- hosts: vmalert
|
||||||
|
roles:
|
||||||
|
- vmalert
|
||||||
|
|||||||
Reference in New Issue
Block a user