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

T6994: Add textfile collector config option #4271

Merged
merged 1 commit into from
Jan 4, 2025
Merged
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
5 changes: 5 additions & 0 deletions data/templates/prometheus/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ ExecStart={{ vrf_command }}/usr/sbin/node_exporter \
{% else %}
--web.listen-address=:{{ port }}
{% endif %}
{% if collectors is vyos_defined %}
{% if collectors.textfile is vyos_defined %}
--collector.textfile.directory=/run/node_exporter/collector
{% endif %}
{% endif %}
[Install]
WantedBy=multi-user.target
13 changes: 13 additions & 0 deletions interface-definitions/service_monitoring_prometheus.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
<defaultValue>9100</defaultValue>
</leafNode>
#include <include/interface/vrf.xml.i>
<node name="collectors">
<properties>
<help>Collectors specific configuration</help>
</properties>
<children>
<leafNode name="textfile">
<properties>
<help>Enables textfile collector to read from /run/node_exporter/collector</help>
<valueless/>
</properties>
</leafNode>
</children>
</node>
</children>
</node>
<node name="frr-exporter">
Expand Down
7 changes: 7 additions & 0 deletions smoketest/scripts/cli/test_service_monitoring_prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import unittest

from base_vyostest_shim import VyOSUnitTestSHIM
Expand Down Expand Up @@ -55,13 +56,19 @@ def tearDown(self):

def test_01_node_exporter(self):
self.cli_set(base_path + ['node-exporter', 'listen-address', listen_ip])
self.cli_set(base_path + ['node-exporter', 'collectors', 'textfile'])

# commit changes
self.cli_commit()

file_content = read_file(node_exporter_service_file)
self.assertIn(f'{listen_ip}:9100', file_content)

self.assertTrue(os.path.isdir('/run/node_exporter/collector'))
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it may be worthwile to make this path a reusable constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've defined a constant in service_monitoring_prometheus.py, if it would be reusable from there then maybe, otherwise I don't think it is worthwhile to make it reusable, as I don't see much reason for changing it.

self.assertIn(
'--collector.textfile.directory=/run/node_exporter/collector', file_content
)

# Check for running process
self.assertTrue(process_named_running(NODE_EXPORTER_PROCESS_NAME))

Expand Down
9 changes: 8 additions & 1 deletion src/conf_mode/service_monitoring_prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
from vyos import ConfigError
from vyos import airbag


airbag.enable()

node_exporter_service_file = '/etc/systemd/system/node_exporter.service'
node_exporter_systemd_service = 'node_exporter.service'
node_exporter_collector_path = '/run/node_exporter/collector'

frr_exporter_service_file = '/etc/systemd/system/frr_exporter.service'
frr_exporter_systemd_service = 'frr_exporter.service'
Expand Down Expand Up @@ -124,6 +124,13 @@ def generate(monitoring):
'prometheus/node_exporter.service.j2',
monitoring['node_exporter'],
)
if (
'collectors' in monitoring['node_exporter']
and 'textfile' in monitoring['node_exporter']['collectors']
):
# Create textcollector folder
if not os.path.isdir(node_exporter_collector_path):
os.makedirs(node_exporter_collector_path)

if 'frr_exporter' in monitoring:
# Render frr_exporter service_file
Expand Down
Loading