Skip to content

enhancement(node_exporter): use systemd to create node_exporter_textfile_dir if it doesn't exist#323

Open
ym wants to merge 1 commit into
prometheus-community:mainfrom
ym:main
Open

enhancement(node_exporter): use systemd to create node_exporter_textfile_dir if it doesn't exist#323
ym wants to merge 1 commit into
prometheus-community:mainfrom
ym:main

Conversation

@ym

@ym ym commented Mar 23, 2024

Copy link
Copy Markdown

We're currently using a directory inside tmpfs for textfile collectors to reduce possible unnecessary IO usage, and the directory will be removed after a reboot. This PR is to ensure that node_exporter_textfile_dir exists when node-exporter is started.

@github-actions github-actions Bot added enhancement New feature or request roles/node_exporter labels Mar 23, 2024
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 23, 2024
Comment thread roles/node_exporter/templates/node_exporter.service.j2 Outdated
…ile_dir if it

doesn't exist

Signed-off-by: Siyuan Miao <i@xswan.net>
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 24, 2024
{% if node_exporter_textfile_dir | length > 0 %}
{% if (ansible_facts.packages.systemd | first).version is version('235', '>=') %}
ExecStartPre=+/bin/mkdir -p {{ node_exporter_textfile_dir }}
ExecStartPre=+/bin/chown -R {{ node_exporter_system_user }}:{{ node_exporter_system_group }} {{ node_exporter_textfile_dir }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wonder if this should be -R. I'm not sure we want all of the prom files changed, just the dir.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our environment, the text file exporters are started after node_exporter.service and the directory is used exclusively for text file exporters, so it doesn't really matter, but I think we can remove the -R, or should we go further and only change the owner if the directory is empty?

@SuperQ SuperQ requested a review from gardar March 24, 2024 15:30

@gardar gardar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if using systemd tmpfiles in this scenario would be a better solution? https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html

@gardar

gardar commented Oct 17, 2024

Copy link
Copy Markdown
Member

I wonder if using systemd tmpfiles in this scenario would be a better solution? https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html

ping @ym

@ym

ym commented Oct 17, 2024

Copy link
Copy Markdown
Author

I wonder if using systemd tmpfiles in this scenario would be a better solution? https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html

ping @ym

External scripts will also need to write to node_exporter_textfile_dir, so I think a predictable and static path might be a better idea. But if you have any good suggestions, I'm all ears.

@gardar

gardar commented Oct 17, 2024

Copy link
Copy Markdown
Member

The path is not dynamic like what you get with mktemp, you define the path you wish to be created in a config file under tmpfiles.d and then systemd will take care of creating it.

Type=simple
User={{ node_exporter_system_user }}
Group={{ node_exporter_system_group }}
{% if node_exporter_textfile_dir | length > 0 %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would affect the common user who does not use tmpfs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants