r/vmagent: Deploy vmagent
The *vmagent* role installs and configures the scraping and routing agent used in the Victoria Metrics ecosystem.
This commit is contained in:
10
roles/vmagent/defaults/main.yml
Normal file
10
roles/vmagent/defaults/main.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
vmagent_remotewrite_url: http://[::1]:8428/api/v1/write
|
||||
|
||||
vmagent_scrape_interval: 1m
|
||||
vmagent_scrape_configs: []
|
||||
|
||||
vmagent_config:
|
||||
global:
|
||||
scrape_interval: '{{ vmagent_scrape_interval }}'
|
||||
|
||||
scrape_configs: "{{ vmagent_scrape_configs }}"
|
||||
13
roles/vmagent/files/vmagent.service
Normal file
13
roles/vmagent/files/vmagent.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Victoria Metrics vmagent
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
Environment=httpListenAddr=[::1]:8429
|
||||
Environment=loggerDisableTimestamps=true
|
||||
EnvironmentFile=-/etc/sysconfig/vmagent
|
||||
ExecStart=/usr/bin/vmagent -enableTCP6 -envflag.enable
|
||||
User=victoriametrics
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
13
roles/vmagent/handlers/main.yml
Normal file
13
roles/vmagent/handlers/main.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
- name: reload systemd
|
||||
systemd:
|
||||
daemon_reload: true
|
||||
|
||||
- name: restart vmagent
|
||||
service:
|
||||
name: vmagent
|
||||
state: restarted
|
||||
|
||||
- name: reload vmagent
|
||||
uri:
|
||||
url: http://[::1]:8429/-/reload
|
||||
changed_when: true
|
||||
62
roles/vmagent/tasks/deploy.yml
Normal file
62
roles/vmagent/tasks/deploy.yml
Normal file
@@ -0,0 +1,62 @@
|
||||
- name: ensure victoria metrics user exists
|
||||
user:
|
||||
name: victoriametrics
|
||||
system: true
|
||||
home: /var/lib/victoria-metrics
|
||||
createhome: false
|
||||
shell: /sbin/nologin
|
||||
state: present
|
||||
tags:
|
||||
- user
|
||||
|
||||
- name: ensure /etc/sysconfig directory exists
|
||||
file:
|
||||
path: /etc/sysconfig
|
||||
mode: u=rwx,go=rx
|
||||
owner: root
|
||||
group: root
|
||||
state: directory
|
||||
tags:
|
||||
- config
|
||||
- name: ensure vmagent is configured
|
||||
template:
|
||||
src: vmagent.sysconfig.j2
|
||||
dest: /etc/sysconfig/vmagent
|
||||
mode: '0644'
|
||||
notify:
|
||||
- restart vmagent
|
||||
tags:
|
||||
- config
|
||||
|
||||
- name: ensure victoria metrics config directory exists
|
||||
file:
|
||||
path: /etc/victoria-metrics
|
||||
mode: '0755'
|
||||
state: directory
|
||||
tags:
|
||||
- config
|
||||
- name: ensure vmagent scrape configuration is set
|
||||
copy:
|
||||
dest: /etc/victoria-metrics/scrape.yml
|
||||
content: '{{ vmagent_config|to_nice_yaml(indent=2) }}'
|
||||
mode: '0644'
|
||||
notify:
|
||||
- reload vmagent
|
||||
tags:
|
||||
- config
|
||||
- scrape-config
|
||||
|
||||
- name: ensure vmagent starts at boot
|
||||
service:
|
||||
name: vmagent
|
||||
enabled: true
|
||||
tags:
|
||||
- service
|
||||
- systemd
|
||||
- name: ensure vmagent is running
|
||||
service:
|
||||
name: vmagent
|
||||
state: started
|
||||
tags:
|
||||
- service
|
||||
- systemd
|
||||
11
roles/vmagent/tasks/install.yml
Normal file
11
roles/vmagent/tasks/install.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
- name: ensure vmagent systemd unit is installed
|
||||
copy:
|
||||
src: vmagent.service
|
||||
dest: /etc/systemd/system/vmagent.service
|
||||
mode: '0644'
|
||||
notify:
|
||||
- reload systemd
|
||||
- restart vmagent
|
||||
tags:
|
||||
- service
|
||||
- systemd
|
||||
7
roles/vmagent/tasks/main.yml
Normal file
7
roles/vmagent/tasks/main.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- block:
|
||||
- import_tasks: install.yml
|
||||
tags:
|
||||
- install
|
||||
- import_tasks: deploy.yml
|
||||
tags:
|
||||
- vmagent
|
||||
4
roles/vmagent/templates/vmagent.sysconfig.j2
Normal file
4
roles/vmagent/templates/vmagent.sysconfig.j2
Normal file
@@ -0,0 +1,4 @@
|
||||
remoteWrite_url={{ vmagent_remotewrite_url }}
|
||||
{% if vmagent_config is not none %}
|
||||
promscrape_config=/etc/victoria-metrics/scrape.yml
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user