diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-10-24 08:26:06 +0200 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-10-24 08:26:06 +0200 |
| commit | 9582b45dab89ac551b8ba0e4991711255dae213a (patch) | |
| tree | d13ad0a3a9f53fb6601e0d97b75aa7f374b78919 /overlays | |
| parent | 0ad709470ef59e3007c0a11a83be47704390b561 (diff) | |
| download | nixos-quickshell.tar nixos-quickshell.tar.gz nixos-quickshell.tar.bz2 nixos-quickshell.tar.xz nixos-quickshell.zip | |
Diffstat (limited to 'overlays')
| -rw-r--r-- | overlays/zte-prometheus-exporter/zte-prometheus-exporter.py | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/overlays/zte-prometheus-exporter/zte-prometheus-exporter.py b/overlays/zte-prometheus-exporter/zte-prometheus-exporter.py index 01d2b9fc..bc8326ff 100644 --- a/overlays/zte-prometheus-exporter/zte-prometheus-exporter.py +++ b/overlays/zte-prometheus-exporter/zte-prometheus-exporter.py | |||
| @@ -59,8 +59,8 @@ class ZTEMetrics: | |||
| 59 | def __init__(self): | 59 | def __init__(self): |
| 60 | raise RuntimeError('Call instance() instead') | 60 | raise RuntimeError('Call instance() instead') |
| 61 | 61 | ||
| 62 | _error_pattern = re.compile('^IF_ERROR(PARAM|TYPE|STR|ID)$') | 62 | _error_pattern = re.compile(r'^IF_ERROR(PARAM|TYPE|STR|ID)$') |
| 63 | _obj_pattern = re.compile('^(?:OBJ_(.+)_ID)|(?:ID_(WAN_COMFIG))$') | 63 | _obj_pattern = re.compile(r'^(?:OBJ_(.+)_ID)|(?:ID_(WAN_COMFIG))$') |
| 64 | def update(self): | 64 | def update(self): |
| 65 | attrs = dict() | 65 | attrs = dict() |
| 66 | 66 | ||
| @@ -106,6 +106,8 @@ class ZTEMetrics: | |||
| 106 | value = child.text | 106 | value = child.text |
| 107 | case _: | 107 | case _: |
| 108 | pass | 108 | pass |
| 109 | if value == '0,0': | ||
| 110 | value = '0' | ||
| 109 | if not name is None and not value is None: | 111 | if not name is None and not value is None: |
| 110 | instance_dict[name] = value | 112 | instance_dict[name] = value |
| 111 | name = None | 113 | name = None |
| @@ -120,8 +122,8 @@ class ZTEMetrics: | |||
| 120 | def json_text(self): | 122 | def json_text(self): |
| 121 | return json.dumps(self.attrs) | 123 | return json.dumps(self.attrs) |
| 122 | 124 | ||
| 123 | _link_pattern = re.compile('^IGD\.WD1\.LINE([0-9]+)$') | 125 | _link_pattern = re.compile(r'^IGD\.WD1\.LINE([0-9]+)$') |
| 124 | _eth_pattern = re.compile('^IGD\.LD1\.ETH([0-9]+)$') | 126 | _eth_pattern = re.compile(r'^IGD\.LD1\.ETH([0-9]+)$') |
| 125 | def prometheus(self): | 127 | def prometheus(self): |
| 126 | metrics = '' | 128 | metrics = '' |
| 127 | 129 | ||
| @@ -133,34 +135,41 @@ class ZTEMetrics: | |||
| 133 | link_match = self._link_pattern.match(link) | 135 | link_match = self._link_pattern.match(link) |
| 134 | link_number = link_match.group(1) | 136 | link_number = link_match.group(1) |
| 135 | 137 | ||
| 136 | if 'crc_errors_count' not in link_metrics: | 138 | link_is_up = self.attrs['DSLINTERFACE'][link]['Status'] == 'Up' |
| 137 | link_metrics['crc_errors_count'] = {'type': 'counter', 'metrics': []} | ||
| 138 | link_metrics['crc_errors_count']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['UpCrc_errors']))] | ||
| 139 | link_metrics['crc_errors_count']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['DownCrc_errors']))] | ||
| 140 | 139 | ||
| 141 | if 'noise_margin_db' not in link_metrics: | 140 | if link_is_up: |
| 142 | link_metrics['noise_margin_db'] = {'type': 'gauge', 'metrics': []} | 141 | if 'crc_errors_count' not in link_metrics: |
| 143 | link_metrics['noise_margin_db']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_noise_margin']))] | 142 | link_metrics['crc_errors_count'] = {'type': 'counter', 'metrics': []} |
| 144 | link_metrics['noise_margin_db']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_noise_margin']))] | 143 | link_metrics['crc_errors_count']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['UpCrc_errors']))] |
| 144 | link_metrics['crc_errors_count']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['DownCrc_errors']))] | ||
| 145 | 145 | ||
| 146 | if 'attenuation_db' not in link_metrics: | 146 | if 'noise_margin_db' not in link_metrics: |
| 147 | link_metrics['attenuation_db'] = {'type': 'gauge', 'metrics': []} | 147 | link_metrics['noise_margin_db'] = {'type': 'gauge', 'metrics': []} |
| 148 | link_metrics['attenuation_db']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_attenuation']))] | 148 | link_metrics['noise_margin_db']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_noise_margin']) / 10)] |
| 149 | link_metrics['attenuation_db']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_attenuation']))] | 149 | link_metrics['noise_margin_db']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_noise_margin']) / 10)] |
| 150 | 150 | ||
| 151 | if 'max_rate_kbps' not in link_metrics: | 151 | if 'attenuation_db' not in link_metrics: |
| 152 | link_metrics['max_rate_kbps'] = {'type': 'gauge', 'metrics': []} | 152 | link_metrics['attenuation_db'] = {'type': 'gauge', 'metrics': []} |
| 153 | link_metrics['max_rate_kbps']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_max_rate']))] | 153 | link_metrics['attenuation_db']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_attenuation']) / 10)] |
| 154 | link_metrics['max_rate_kbps']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_max_rate']))] | 154 | link_metrics['attenuation_db']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_attenuation']) / 10)] |
| 155 | 155 | ||
| 156 | if 'current_rate_kbps' not in link_metrics: | 156 | if 'max_rate_kbps' not in link_metrics: |
| 157 | link_metrics['current_rate_kbps'] = {'type': 'gauge', 'metrics': []} | 157 | link_metrics['max_rate_kbps'] = {'type': 'gauge', 'metrics': []} |
| 158 | link_metrics['current_rate_kbps']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_current_rate']))] | 158 | link_metrics['max_rate_kbps']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_max_rate']))] |
| 159 | link_metrics['current_rate_kbps']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_current_rate']))] | 159 | link_metrics['max_rate_kbps']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_max_rate']))] |
| 160 | |||
| 161 | if 'current_rate_kbps' not in link_metrics: | ||
| 162 | link_metrics['current_rate_kbps'] = {'type': 'gauge', 'metrics': []} | ||
| 163 | link_metrics['current_rate_kbps']['metrics'] += [({"direction": "up", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Upstream_current_rate']))] | ||
| 164 | link_metrics['current_rate_kbps']['metrics'] += [({"direction": "down", "link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Downstream_current_rate']))] | ||
| 160 | 165 | ||
| 161 | if 'dsl_uptime_seconds' not in link_metrics: | 166 | if 'dsl_uptime_seconds' not in link_metrics: |
| 162 | link_metrics['dsl_uptime_seconds'] = {'type': 'gauge', 'metrics': []} | 167 | link_metrics['uptime_seconds'] = {'type': 'gauge', 'metrics': []} |
| 163 | link_metrics['dsl_uptime_seconds']['metrics'] += [({"link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Showtime_start']))] | 168 | link_metrics['uptime_seconds']['metrics'] += [({"link": link_number}, int(self.attrs['DSLINTERFACE'][link]['Showtime_start']) if link_is_up else 0)] |
| 169 | |||
| 170 | if 'status' not in link_metrics: | ||
| 171 | link_metrics['status'] = {'type': 'gauge', 'metrics': []} | ||
| 172 | link_metrics['status']['metrics'] += [({"link": link_number, "status": self.attrs['DSLINTERFACE'][link]['Status']}, 1)] | ||
| 164 | if link_metrics: | 173 | if link_metrics: |
| 165 | for metric_name in link_metrics: | 174 | for metric_name in link_metrics: |
| 166 | metrics += _format_prom_metrics(f'dsl_{metric_name}', link_metrics[metric_name]['type'], link_metrics[metric_name]['metrics']) | 175 | metrics += _format_prom_metrics(f'dsl_{metric_name}', link_metrics[metric_name]['type'], link_metrics[metric_name]['metrics']) |
