r/vmagent: Deploy vmagent

The *vmagent* role installs and configures the scraping and routing
agent used in the Victoria Metrics ecosystem.
btop
Dustin 2022-07-18 18:13:31 -05:00
parent 956a40f054
commit 60505657f3
8 changed files with 124 additions and 0 deletions

View 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 }}"

View 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

View 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

View 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

View 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

View File

@ -0,0 +1,7 @@
- block:
- import_tasks: install.yml
tags:
- install
- import_tasks: deploy.yml
tags:
- vmagent

View File

@ -0,0 +1,4 @@
remoteWrite_url={{ vmagent_remotewrite_url }}
{% if vmagent_config is not none %}
promscrape_config=/etc/victoria-metrics/scrape.yml
{% endif %}

View File

@ -2,3 +2,7 @@
roles: roles:
- role: victoria-metrics - role: victoria-metrics
tags: victoria-metrics tags: victoria-metrics
- hosts: vmagent
roles:
- vmagent