Skip to content

Commit

Permalink
feat: create frr_exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswiggins committed Oct 10, 2024
1 parent 752fee0 commit aa3a5cd
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 131 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: CI

defaults:
run:
working-directory: 'geerlingguy.node_exporter'
working-directory: 'vgrid.frr_exporter'

jobs:

Expand All @@ -21,7 +21,7 @@ jobs:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'geerlingguy.node_exporter'
path: 'vgrid.frr_exporter'

- name: Set up Python 3.
uses: actions/setup-python@v5
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'geerlingguy.node_exporter'
path: 'vgrid.frr_exporter'

- name: Set up Python 3.
uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: Release

defaults:
run:
working-directory: 'geerlingguy.node_exporter'
working-directory: 'vgrid.frr_exporter'

jobs:

Expand All @@ -24,7 +24,7 @@ jobs:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'geerlingguy.node_exporter'
path: 'vgrid.frr_exporter'

- name: Set up Python 3.
uses: actions/setup-python@v5
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/stale.yml

This file was deleted.

47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Ansible Role: Node exporter
# Ansible Role: FRR exporter

[![CI](https://github.com/geerlingguy/ansible-role-node_exporter/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-role-node_exporter/actions?query=workflow%3ACI)
[![CI](https://github.com/vgrid/ansible-role-frr_exporter/workflows/CI/badge.svg?event=push)](https://github.com/vgrid/ansible-role-frr_exporter/actions?query=workflow%3ACI)

This role installs Prometheus' [Node exporter](https://github.com/prometheus/node_exporter) on Linux hosts, and configures a systemd unit file so the service can run and be controlled by systemd.
This role installs Prometheus' [FRR Exporter](https://github.com/tynany/frr_exporter) on Linux hosts, and configures a systemd unit file so the service can run and be controlled by systemd.

**Note**: If you're running in a Kubernetes cluster, you could run Node exporter as a DaemonSet in the cluster, instead of installing it on individual nodes.
## Credit

This role is a modified version of the ansible-role-node exporter by by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). Thanks to Jeff it was very quick to get this up and running.

## Requirements

Expand All @@ -14,34 +16,34 @@ N/A

Available variables are listed below, along with default values (see `defaults/main.yml`):

node_exporter_version: '0.18.1'
frr_exporter_version: '1.1.3'

The version of Node exporter to install. Available releases can be found on the [tags](https://github.com/prometheus/node_exporter/tags) listing in the Node exporter repository. Drop the `v` off the tag.
The version of FRR Exporter to install. Available releases can be found on the [tags](https://github.com/tynany/frr_exporter/tags) listing in the FRR Exporter repository. Drop the `v` off the tag.

If you change the version, the `node_exporter` binary will be replaced with the updated version, and the service will be restarted.
If you change the version, the `frr_exporter` binary will be replaced with the updated version, and the service will be restarted.

node_exporter_arch: 'amd64'
node_exporter_download_url: https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ node_exporter_arch }}.tar.gz
frr_exporter_arch: 'amd64'
frr_exporter_download_url: https://github.com/tynany/frr_exporter/releases/download/v{{ frr_exporter_version }}/frr_exporter-{{ frr_exporter_version }}.linux-{{ frr_exporter_arch }}.tar.gz

The architecture and download URL for Node exporter. If you're on a Raspberry Pi running Raspbian, you may need to override the `arch` value with `armv7`.
The architecture and download URL for FRR Exporter. If you're on a Raspberry Pi running Raspbian, you may need to override the `arch` value with `armv7`.

node_exporter_bin_path: /usr/local/bin/node_exporter
frr_exporter_bin_path: /usr/local/bin/frr_exporter

The path where the `node_exporter` binary will be installed.
The path where the `frr_exporter` binary will be installed.

node_exporter_host: 'localhost'
node_exporter_port: 9100
frr_exporter_host: 'localhost'
frr_exporter_port: 9100

Host and port on which node exporter will listen.
Host and port on which FRR Exporter will listen.

node_exporter_options: ''
frr_exporter_options: ''

Any additional options to pass to `node_exporter` when it starts, e.g. `--no-collector.wifi` if you want to ignore any WiFi data.
Any additional options to pass to `frr_exporter` when it starts, e.g. `--no-collector.bgp` if you want to ignore BGP collection

node_exporter_state: started
node_exporter_enabled: true
frr_exporter_state: started
frr_exporter_enabled: true

Controls for the `node_exporter` service.
Controls for the `frr_exporter` service.

## Dependencies

Expand All @@ -51,12 +53,9 @@ None.

- hosts: all
roles:
- role: geerlingguy.node_exporter
- role: vgrid.frr_exporter

## License

MIT / BSD

## Author Information

This role was created in 2020 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
28 changes: 14 additions & 14 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
# Use the latest node_exporter release
node_exporter_version: 'latest'
# Use the latest frr_exporter release
frr_exporter_version: 'latest'

# Alternatively, set a specific version
# See available releases: https://github.com/prometheus/node_exporter/releases/
# node_exporter_version: '0.18.1'
# See available releases: https://github.com/tynany/frr_exporter/releases/
# frr_exporter_version: '1.1.3'

node_exporter_arch: 'amd64'
node_exporter_download_url: https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ node_exporter_arch }}.tar.gz
frr_exporter_arch: 'amd64'
frr_exporter_download_url: https://github.com/tynany/frr_exporter/releases/download/v{{ frr_exporter_version }}/frr_exporter-{{ frr_exporter_version }}.linux-{{ frr_exporter_arch }}.tar.gz

node_exporter_bin_path: /usr/local/bin/node_exporter
frr_exporter_bin_path: /usr/local/bin/frr_exporter

# Set node_exporter_host to localhost if you wish to expose node_exporter on localhost only.
node_exporter_host: ''
node_exporter_port: 9100
node_exporter_options: ''
# Set frr_exporter_host to localhost if you wish to expose frr_exporter on localhost only.
frr_exporter_host: ''
frr_exporter_port: 9432
frr_exporter_options: ''

node_exporter_state: started
node_exporter_enabled: true
node_exporter_restart: on-failure
frr_exporter_state: started
frr_exporter_enabled: true
frr_exporter_restart: on-failure
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: restart node_exporter
- name: restart frr_exporter
service:
name: node_exporter
name: frr_exporter
state: restarted
10 changes: 5 additions & 5 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
dependencies: []
galaxy_info:
author: geerlingguy
role_name: node_exporter
description: Prometheus' node_exporter for Linux hosts.
company: Midwestern Mac, LLC
author: vgrid
role_name: frr_exporter
description: Prometheus' frr_exporter for Linux hosts.
company: SaferCities
license: license (MIT)
min_ansible_version: 2.10
platforms:
Expand Down Expand Up @@ -41,6 +41,6 @@ galaxy_info:
- containers
- monitoring
- prometheus
- node
- frr
- exporter
- metrics
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
changed_when: false

roles:
- role: geerlingguy.node_exporter
- role: vgrid.frr_exporter
10 changes: 5 additions & 5 deletions tasks/config-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
delegate_to: localhost
become: false
uri:
url: "https://api.github.com/repos/prometheus/node_exporter/releases/latest"
url: "https://api.github.com/repos/tynany/frr_exporter/releases/latest"
body_format: json
register: _github_release
until: _github_release.status == 200
run_once: true
retries: 5

- name: Set node_exporter_version
- name: Set frr_exporter_version
set_fact:
node_exporter_version: "{{ _github_release.json.tag_name
frr_exporter_version: "{{ _github_release.json.tag_name
| regex_replace('^v?([0-9\\.]+)$', '\\1') }}"

- name: Set node_exporter_download_url
- name: Set frr_exporter_download_url
set_fact:
node_exporter_download_url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ node_exporter_arch }}.tar.gz"
frr_exporter_download_url: "https://github.com/tynany/frr_exporter/releases/download/v{{ frr_exporter_version }}/frr_exporter-{{ frr_exporter_version }}.linux-{{ frr_exporter_arch }}.tar.gz"
65 changes: 35 additions & 30 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,71 @@
---
- name: Check current node_exporter version.
command: "{{ node_exporter_bin_path }} --version"
- name: Check current frr_exporter version.
command: "{{ frr_exporter_bin_path }} --version"
failed_when: false
changed_when: false
register: node_exporter_version_check
register: frr_exporter_version_check

- name: Configure latest version
include_tasks: config-version.yaml
when: >
node_exporter_version is match("latest")
or node_exporter_version is not defined
frr_exporter_version is match("latest")
or frr_exporter_version is not defined
- name: Download and unarchive node_exporter into temporary location.
- name: Download and unarchive frr_exporter into temporary location.
unarchive:
src: "{{ node_exporter_download_url }}"
src: "{{ frr_exporter_download_url }}"
dest: /tmp
remote_src: true
mode: 0755
when: >
node_exporter_version_check.stdout is not defined
or node_exporter_version not in node_exporter_version_check.stdout
register: node_exporter_download_check
frr_exporter_version_check.stdout is not defined
or frr_exporter_version not in frr_exporter_version_check.stdout
register: frr_exporter_download_check

- name: Move node_exporter binary into place.
- name: Move frr_exporter binary into place.
copy:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ node_exporter_arch }}/node_exporter"
dest: "{{ node_exporter_bin_path }}"
src: "/tmp/frr_exporter-{{ frr_exporter_version }}.linux-{{ frr_exporter_arch }}/frr_exporter"
dest: "{{ frr_exporter_bin_path }}"
mode: 0755
remote_src: true
notify: restart node_exporter
notify: restart frr_exporter
when: >
node_exporter_download_check is changed
or node_exporter_version_check.stdout | length == 0
frr_exporter_download_check is changed
or frr_exporter_version_check.stdout | length == 0
- name: Create node_exporter user.
- name: Create frr_exporter user.
user:
name: node_exporter
name: frr_exporter
shell: /sbin/nologin
state: present

- name: Copy the node_exporter systemd unit file.
- name: Add frr_exporter user to frr group
user:
name: frr_exporter
groups: frrvty

- name: Copy the frr_exporter systemd unit file.
template:
src: node_exporter.service.j2
dest: /etc/systemd/system/node_exporter.service
src: frr_exporter.service.j2
dest: /etc/systemd/system/frr_exporter.service
mode: 0644
register: node_exporter_service
register: frr_exporter_service

- name: Reload systemd daemon if unit file is changed.
systemd:
daemon_reload: true
notify: restart node_exporter
when: node_exporter_service is changed
notify: restart frr_exporter
when: frr_exporter_service is changed

- name: Ensure node_exporter is running and enabled at boot.
- name: Ensure frr_exporter is running and enabled at boot.
service:
name: node_exporter
state: "{{ node_exporter_state }}"
enabled: "{{ node_exporter_enabled }}"
name: frr_exporter
state: "{{ frr_exporter_state }}"
enabled: "{{ frr_exporter_enabled }}"

- name: Verify node_exporter is responding to requests.
- name: Verify frr_exporter is responding to requests.
uri:
url: "http://{% if node_exporter_host !='' %}{{ node_exporter_host }}{% else %}localhost{% endif %}:{{ node_exporter_port }}/"
url: "http://{% if frr_exporter_host !='' %}{{ frr_exporter_host }}{% else %}localhost{% endif %}:{{ frr_exporter_port }}/"
return_content: true
register: metrics_output
failed_when: "'Metrics' not in metrics_output.content"
11 changes: 11 additions & 0 deletions templates/frr_exporter.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=FrrExporter

[Service]
TimeoutStartSec=0
User=frr_exporter
ExecStart={{ frr_exporter_bin_path }} --web.listen-address={{ frr_exporter_host }}:{{ frr_exporter_port }} {{ frr_exporter_options }}
Restart={{ frr_exporter_restart }}

[Install]
WantedBy=multi-user.target
11 changes: 0 additions & 11 deletions templates/node_exporter.service.j2

This file was deleted.

0 comments on commit aa3a5cd

Please sign in to comment.