summaryrefslogtreecommitdiff
path: root/src/conf_mode/service_monitoring_prometheus.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/conf_mode/service_monitoring_prometheus.py')
-rwxr-xr-xsrc/conf_mode/service_monitoring_prometheus.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/conf_mode/service_monitoring_prometheus.py b/src/conf_mode/service_monitoring_prometheus.py
index 42628b05c..b02f9f154 100755
--- a/src/conf_mode/service_monitoring_prometheus.py
+++ b/src/conf_mode/service_monitoring_prometheus.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2024 VyOS maintainers and contributors
+# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -23,14 +23,15 @@ from vyos.configdict import is_node_changed
from vyos.configverify import verify_vrf
from vyos.template import render
from vyos.utils.process import call
+from vyos.utils.process import is_systemd_service_active
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'
@@ -48,9 +49,21 @@ def get_config(config=None):
if not conf.exists(base):
return None
- monitoring = conf.get_config_dict(
- base, key_mangling=('-', '_'), get_first_key=True, with_recursive_defaults=True
- )
+ monitoring = {}
+ exporters = {
+ 'node_exporter': base + ['node-exporter'],
+ 'frr_exporter': base + ['frr-exporter'],
+ 'blackbox_exporter': base + ['blackbox-exporter'],
+ }
+
+ for exporter_name, exporter_base in exporters.items():
+ if conf.exists(exporter_base):
+ monitoring[exporter_name] = conf.get_config_dict(
+ exporter_base,
+ key_mangling=('-', '_'),
+ get_first_key=True,
+ with_recursive_defaults=True,
+ )
tmp = is_node_changed(conf, base + ['node-exporter', 'vrf'])
if tmp:
@@ -124,6 +137,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
@@ -154,11 +174,14 @@ def apply(monitoring):
# Reload systemd manager configuration
call('systemctl daemon-reload')
if not monitoring or 'node_exporter' not in monitoring:
- call(f'systemctl stop {node_exporter_systemd_service}')
+ if is_systemd_service_active(node_exporter_systemd_service):
+ call(f'systemctl stop {node_exporter_systemd_service}')
if not monitoring or 'frr_exporter' not in monitoring:
- call(f'systemctl stop {frr_exporter_systemd_service}')
+ if is_systemd_service_active(frr_exporter_systemd_service):
+ call(f'systemctl stop {frr_exporter_systemd_service}')
if not monitoring or 'blackbox_exporter' not in monitoring:
- call(f'systemctl stop {blackbox_exporter_systemd_service}')
+ if is_systemd_service_active(blackbox_exporter_systemd_service):
+ call(f'systemctl stop {blackbox_exporter_systemd_service}')
if not monitoring:
return