chrony_status: cleanup: use f-strings and fix/ignore pylint warnings
This commit is contained in:
parent
4b733228d6
commit
08361c2178
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
@ -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__':
|
||||
|
|
Loading…
Reference in New Issue