Skip to content

Commit

Permalink
Merge pull request #4271 from nvollmar/T6994
Browse files Browse the repository at this point in the history
T6994: Add textfile collector config option
  • Loading branch information
c-po authored Jan 4, 2025
2 parents bb46115 + 20842f5 commit 9a5f14b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
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'))
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

0 comments on commit 9a5f14b

Please sign in to comment.