Skip to content

Commit

Permalink
Merge pull request munin-monitoring#1408 from kimheino/master
Browse files Browse the repository at this point in the history
chrony_status: cleanup: use f-strings and fix/ignore pylint warnings
  • Loading branch information
kenyon authored Feb 1, 2024
2 parents 4b73322 + 08361c2 commit d3386b8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions plugins/chrony/chrony_status
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Unix domain socket which chronyc uses to communicate with chronyd. Example
=head1 INTERPRETATION
Monitor Chrony's stratum value (with warning), time offset, network delay, clock
frequency, packets received, and packets dropped. It would be very easy to
monitor all of Chrony's values, but IMHO they aren't needed. The most important
information is stratum, giving "synced" / "not synced" value.
Monitor Chrony's stratum value (with warning), time offset, network delay,
clock frequency, packets received, and packets dropped. It would be very easy
to monitor all of Chrony's values, but IMHO they aren't needed. The most
important information is stratum, giving "synced" / "not synced" value.
=head1 AUTHOR
Expand Down Expand Up @@ -94,9 +94,9 @@ def get_values():
return {}
lines = output.stdout.splitlines()
ret = {}
for label in FIELDS:
for label, prefix in FIELDS.items():
for line in lines:
if line.startswith(FIELDS[label]):
if line.startswith(prefix):
value = line.split(':', 1)[1].split()[0]
if ' slow' in line:
value = -float(value)
Expand All @@ -106,6 +106,7 @@ def get_values():

def config():
"""Print plugin config."""
# pylint: disable=too-many-statements
print('multigraph chrony_stratum')
print('graph_title Chrony stratum')
print('graph_vlabel stratum')
Expand Down Expand Up @@ -176,15 +177,15 @@ def fetch():
"""Print values."""
values = get_values()
for graph in GRAPHS:
print('multigraph chrony_{}'.format(graph))
print(f'multigraph chrony_{graph}')
if graph == 'stratum' and values[graph] == '0':
print('{}.value U'.format(graph))
print(f'{graph}.value U')
elif graph == 'serverstats':
for stat in SERVERSTATS:
if stat in values:
print('{}.value {}'.format(stat, values[stat]))
print(f'{stat}.value {values[stat]}')
else:
print('{}.value {}'.format(graph, values[graph]))
print(f'{graph}.value {values[graph]}')


if __name__ == '__main__':
Expand Down

0 comments on commit d3386b8

Please sign in to comment.