Skip to content

Commit

Permalink
grafana-agent: add grafana-agent-flow config
Browse files Browse the repository at this point in the history
  • Loading branch information
ohdearaugustin committed Apr 11, 2024
1 parent db3417a commit d4d2dd5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
25 changes: 25 additions & 0 deletions roles/grafana_agent/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,28 @@ grafana_agent_static_config:
disable_collectors:
- "mdadm"

grafana_agent_flow_config: |
logging {
level = "warn"
}
prometheus.exporter.unix "default" {
include_exporter_metrics = true
disable_collectors = ["mdadm"]
}
prometheus.scrape "default" {
targets = concat(
prometheus.exporter.unix.default.targets,
[{
// Self-collect metrics
job = "agent",
__address__ = "127.0.0.1:12345",
}],
)
forward_to = [
// TODO: components to forward metrics to (like prometheus.remote_write or
// prometheus.relabel).
]
}
10 changes: 8 additions & 2 deletions roles/grafana_agent/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
- name: Restart Grafana Agent with daemon reload
become: true
ansible.builtin.systemd:
name: grafana-agent
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: restarted
daemon_reload: true

- name: Restart Grafana Agent
become: true
ansible.builtin.systemd:
name: grafana-agent
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: restarted

- name: Reload Grafana Agent
become: true
ansible.builtin.systemd:
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: reloaded
10 changes: 10 additions & 0 deletions roles/grafana_agent/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
group: "{{ grafana_agent_user_group }}"
mode: "0640"
notify: Restart Grafana Agent

- name: Create Grafana Agent config - flow
when: grafana_agent_mode == 'flow'
ansible.builtin.template:
src: grafana-agent-flow.river.j2
dest: /etc/grafana-agent-flow.river
owner: root
group: "{{ grafana_agent_user_group }}"
mode: "0640"
notify: Reload Grafana Agent
7 changes: 7 additions & 0 deletions roles/grafana_agent/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
tags:
- grafana_agent_configure

- name: Flush handlers
ansible.builtin.meta: flush_handlers

- name: Start and enable Grafana Agent
become: true
ansible.builtin.service:
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: started
enabled: true
tags:
- grafana_agent_install
- grafana_agent_configure
3 changes: 3 additions & 0 deletions roles/grafana_agent/templates/grafana-agent-flow.river.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ ansible_managed | comment('c') }}
// For a full configuration reference, see https://grafana.com/docs/agent/latest/flow/
{{ grafana_agent_flow_config }}

0 comments on commit d4d2dd5

Please sign in to comment.