Projet

Général

Profil

Révision 0866add1

ID0866add183fc30cdac20e4b59eb031c90075e223
Parent 357c3586
Enfant b7617471

Ajouté par Kenyon Ralph il y a environ 4 ans

chrony_status: fix fetch output for serverstats graph

Was not expecting #1255 to be merged so quickly 🤪. Now the new
serverstats graph has been fully tested and actually works 😉.

This change also doesn't needlessly convert all values to floating
point numbers, instead provides the values to munin in the same format
as they are originally output by chrony.

Also this adds some server stats found in chrony 4.0 (but still works
with 3.4 and probably earlier).

Voir les différences:

plugins/chrony/chrony_status
46 46
import subprocess
47 47
import sys
48 48

  
49
GRAPHS = [
50
    'stratum',
51
    'systime',
52
    'delay',
53
    'frequency',
54
    'serverstats',
55
]
56

  
57
SERVERSTATS = [
58
    'received',
59
    'dropped',
60
    'command_received',
61
    'command_dropped',
62
    'client_log_records_dropped',
63
    'nts_ke_connections_accepted',
64
    'nts_ke_connections_dropped',
65
    'authenticated_packets',
66
]
49 67

  
50 68
FIELDS = {
51 69
    'stratum': 'Stratum',
......
57 75
    'command_received': 'Command packets received',
58 76
    'command_dropped': 'Command packets dropped',
59 77
    'client_log_records_dropped': 'Client log records dropped',
78
    'nts_ke_connections_accepted': 'NTS-KE connections accepted',
79
    'nts_ke_connections_dropped': 'NTS-KE connections dropped',
80
    'authenticated_packets': 'Authenticated NTP packets',
60 81
}
61 82

  
62 83

  
......
76 97
    for label in FIELDS:
77 98
        for line in lines:
78 99
            if line.startswith(FIELDS[label]):
79
                value = float(line.split(':', 1)[1].split()[0])
100
                value = line.split(':', 1)[1].split()[0]
80 101
                if ' slow' in line:
81
                    value = -value
102
                    value = -float(value)
82 103
                ret[label] = value
83 104
    return ret
84 105

  
......
137 158
    print('client_log_records_dropped.label Client log records dropped')
138 159
    print('client_log_records_dropped.type DERIVE')
139 160
    print('client_log_records_dropped.min 0')
161
    print('nts_ke_connections_accepted.label NTS-KE connections accepted')
162
    print('nts_ke_connections_accepted.type DERIVE')
163
    print('nts_ke_connections_accepted.min 0')
164
    print('nts_ke_connections_dropped.label NTS-KE connections dropped')
165
    print('nts_ke_connections_dropped.type DERIVE')
166
    print('nts_ke_connections_dropped.min 0')
167
    print('authenticated_packets.label Authenticated NTP packets')
168
    print('authenticated_packets.type DERIVE')
169
    print('authenticated_packets.min 0')
140 170

  
141 171
    if os.environ.get('MUNIN_CAP_DIRTYCONFIG') == '1':
142 172
        fetch()
......
145 175
def fetch():
146 176
    """Print values."""
147 177
    values = get_values()
148
    for key in FIELDS:
149
        print('multigraph chrony_{}'.format(key))
150
        if key == 'stratum' and values[key] == 0:
151
            print('{}.value U'.format(key))
178
    for graph in GRAPHS:
179
        print('multigraph chrony_{}'.format(graph))
180
        if graph == 'stratum' and values[graph] == 0:
181
            print('{}.value U'.format(graph))
182
        elif graph == 'serverstats':
183
            for stat in SERVERSTATS:
184
                if stat in values:
185
                    print('{}.value {}'.format(stat, values[stat]))
152 186
        else:
153
            print('{}.value {:.8f}'.format(key, values[key]))
187
            print('{}.value {}'.format(graph, values[graph]))
154 188

  
155 189

  
156 190
if __name__ == '__main__':

Formats disponibles : Unified diff