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

enhancement: Add systemd socket listener activation #290

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions roles/node_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ node_exporter_disabled_collectors: []
node_exporter_binary_install_dir: "/usr/local/bin"
node_exporter_system_group: "node-exp"
node_exporter_system_user: "{{ node_exporter_system_group }}"
node_exporter_systemd_socket_activation: false
4 changes: 4 additions & 0 deletions roles/node_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ argument_specs:
- "I(Advanced)"
- "Node exporter user"
default: "node-exp"
node_exporter_systemd_socket_activation:
description:
- "Node exporter systemd socket activation task is executed when set to true."
default: false
10 changes: 10 additions & 0 deletions roles/node_exporter/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
mode: 0644
notify: restart node_exporter

- name: Copy the node_exporter systemd socket file
ansible.builtin.template:
src: node_exporter.socket.j2
dest: /usr/lib/systemd/system/node_exporter.socket
owner: root
group: root
mode: 0644
notify: restart node_exporter
when: node_exporter_systemd_socket_activation

- name: Create node_exporter config directory
ansible.builtin.file:
path: "/etc/node_exporter"
Expand Down
6 changes: 6 additions & 0 deletions roles/node_exporter/templates/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
[Unit]
Description=Prometheus Node Exporter
After=network-online.target
{% if node_exporter_systemd_socket_activation %}
Requires=node_exporter.socket
{% endif -%}

[Service]
Type=simple
User={{ node_exporter_system_user }}
Group={{ node_exporter_system_group }}
ExecStart={{ node_exporter_binary_install_dir }}/node_exporter \
{% if node_exporter_systemd_socket_activation %}
--web.systemd-socket \
{% endif -%}
{% for collector in node_exporter_enabled_collectors -%}
{% if not collector is mapping %}
'--collector.{{ collector }}' \
Expand Down
8 changes: 8 additions & 0 deletions roles/node_exporter/templates/node_exporter.socket.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Node Exporter

[Socket]
ListenStream={{ node_exporter_web_listen_address.split(':') | last }}

[Install]
WantedBy=socket.target