Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/refactor grafana agent #154

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions roles/grafana_agent/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
grafana_agent_version: latest
# grafana_agent_mode: "flow"
grafana_agent_mode: "static"
grafana_agent_package: "grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}{{ (grafana_agent_version != 'latest') | ternary('=' ~ grafana_agent_version, '') }}"
grafana_agent_manage_repo: true
grafana_agent_dependencies: []

# Grafana Agent Apt Repository Configuration
grafana_agent_apt_release_channel: stable
grafana_agent_apt_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
grafana_agent_apt_repo: "deb [arch={{ grafana_agent_apt_arch }} signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com/ {{ grafana_agent_apt_release_channel }} main"
grafana_agent_apt_key: "https://apt.grafana.com/gpg.key"

# Grafana Agent Yum Repository Configuration
grafana_agent_yum_repo: https://rpm.grafana.com
grafana_agent_yum_key: https://rpm.grafana.com/gpg.key

grafana_agent_user_group: grafana-agent

grafana_agent_static_config:
server:
log_level: warn

metrics:
global:
scrape_interval: 1m
wal_directory: '/var/lib/grafana-agent'
configs:
# Example Prometheus scrape configuration to scrape the agent itself for metrics.
# This is not needed if the agent integration is enabled.
# - name: agent
# host_filter: false
# scrape_configs:
# - job_name: agent
# static_configs:
# - targets: ['127.0.0.1:9090']

integrations:
agent:
enabled: true
node_exporter:
enabled: true
include_exporter_metrics: true
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).
]
}
12 changes: 0 additions & 12 deletions roles/grafana_agent/handlers/main.yaml

This file was deleted.

19 changes: 19 additions & 0 deletions roles/grafana_agent/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Restart Grafana Agent with daemon reload
become: true
ansible.builtin.systemd:
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{% 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
25 changes: 0 additions & 25 deletions roles/grafana_agent/meta/main.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions roles/grafana_agent/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
gather_facts: true
roles:
- role: grafana_agent
1 change: 1 addition & 0 deletions roles/grafana_agent/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
gather_facts: true
vars:
grafana_agent_mode: flow
roles:
- role: grafana_agent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
51 changes: 0 additions & 51 deletions roles/grafana_agent/tasks/configure.yaml

This file was deleted.

20 changes: 20 additions & 0 deletions roles/grafana_agent/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Create Grafana Agent config - static
when: grafana_agent_mode == 'static'
ansible.builtin.template:
src: grafana-agent-static.yaml.j2
dest: /etc/grafana-agent.yaml
owner: root
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
29 changes: 0 additions & 29 deletions roles/grafana_agent/tasks/ga-started.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions roles/grafana_agent/tasks/install.yaml

This file was deleted.

60 changes: 60 additions & 0 deletions roles/grafana_agent/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
- name: Gather variables for each operating system
ansible.builtin.include_vars: "{{ distrovars }}"
vars:
distrovars: "{{ lookup('first_found', params, errors='ignore') }}"
params:
skip: true
files:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
paths:
- "vars/"
tags:
- grafana_agent_install
- grafana_agent_configure

- name: Install dependencies
ansible.builtin.package:
name: "{{ grafana_agent_dependencies }}"
state: present

- name: Prepare apt
when:
- "ansible_pkg_mgr == 'apt'"
- grafana_agent_manage_repo
block:
- name: Import Grafana apt gpg key
ansible.builtin.get_url:
url: "{{ grafana_agent_apt_key }}"
dest: /usr/share/keyrings/grafana.key
mode: "0644"

- name: Add Grafana apt repository
ansible.builtin.apt_repository:
repo: "{{ grafana_agent_apt_repo }}"
state: present
update_cache: true

- name: Add Grafana yum/dnf repository
when:
- "ansible_pkg_mgr in ['yum', 'dnf']"
- grafana_agent_manage_repo
ansible.builtin.yum_repository:
name: grafana
description: grafana
baseurl: "{{ grafana_agent_yum_repo }}"
enabled: true
gpgkey: "{{ grafana_agent_yum_key | default(omit) }}"
sslverify: true
repo_gpgcheck: "{{ true if (grafana_agent_yum_key) else omit }}"
gpgcheck: "{{ true if (grafana_agent_yum_key) else omit }}"

- name: "Install Grafana Agent"
ansible.builtin.package:
name: "{{ grafana_agent_package }}"
state: "{{ (grafana_agent_version == 'latest') | ternary('latest', 'present') }}"
notify: Restart Grafana Agent
26 changes: 0 additions & 26 deletions roles/grafana_agent/tasks/install/directories.yaml

This file was deleted.

Loading
Loading