1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-23 06:35:42 +00:00

Merge pull request #1408 from kimheino/master

chrony_status: cleanup: use f-strings and fix/ignore pylint warnings
This commit is contained in:
Kenyon Ralph 2024-02-01 10:22:59 -08:00 committed by GitHub
commit d3386b8a74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,10 +21,10 @@ Unix domain socket which chronyc uses to communicate with chronyd. Example
=head1 INTERPRETATION =head1 INTERPRETATION
Monitor Chrony's stratum value (with warning), time offset, network delay, clock Monitor Chrony's stratum value (with warning), time offset, network delay,
frequency, packets received, and packets dropped. It would be very easy to clock frequency, packets received, and packets dropped. It would be very easy
monitor all of Chrony's values, but IMHO they aren't needed. The most important to monitor all of Chrony's values, but IMHO they aren't needed. The most
information is stratum, giving "synced" / "not synced" value. important information is stratum, giving "synced" / "not synced" value.
=head1 AUTHOR =head1 AUTHOR
@ -94,9 +94,9 @@ def get_values():
return {} return {}
lines = output.stdout.splitlines() lines = output.stdout.splitlines()
ret = {} ret = {}
for label in FIELDS: for label, prefix in FIELDS.items():
for line in lines: for line in lines:
if line.startswith(FIELDS[label]): if line.startswith(prefix):
value = line.split(':', 1)[1].split()[0] value = line.split(':', 1)[1].split()[0]
if ' slow' in line: if ' slow' in line:
value = -float(value) value = -float(value)
@ -106,6 +106,7 @@ def get_values():
def config(): def config():
"""Print plugin config.""" """Print plugin config."""
# pylint: disable=too-many-statements
print('multigraph chrony_stratum') print('multigraph chrony_stratum')
print('graph_title Chrony stratum') print('graph_title Chrony stratum')
print('graph_vlabel stratum') print('graph_vlabel stratum')
@ -176,15 +177,15 @@ def fetch():
"""Print values.""" """Print values."""
values = get_values() values = get_values()
for graph in GRAPHS: for graph in GRAPHS:
print('multigraph chrony_{}'.format(graph)) print(f'multigraph chrony_{graph}')
if graph == 'stratum' and values[graph] == '0': if graph == 'stratum' and values[graph] == '0':
print('{}.value U'.format(graph)) print(f'{graph}.value U')
elif graph == 'serverstats': elif graph == 'serverstats':
for stat in SERVERSTATS: for stat in SERVERSTATS:
if stat in values: if stat in values:
print('{}.value {}'.format(stat, values[stat])) print(f'{stat}.value {values[stat]}')
else: else:
print('{}.value {}'.format(graph, values[graph])) print(f'{graph}.value {values[graph]}')
if __name__ == '__main__': if __name__ == '__main__':