Created
February 13, 2020 00:06
-
-
Save sbz/ccb0f310e5ff76ac64565bc60ddec4de to your computer and use it in GitHub Desktop.
tcollector ntp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import subprocess | |
import socket | |
import shlex | |
NTPQ_BIN='/usr/bin/ntpq' | |
METRICS=[ | |
'stratum', | |
'offset', | |
'rootdelay', | |
'clk_jitter', | |
'sys_jitter', | |
'clk_wander', | |
] | |
class NTPError(Exception): pass | |
class NTPCollector(object): | |
def __init__(self): | |
self.hostname = socket.getfqdn() | |
self.metrics = {} | |
def collect(self): | |
ntq_command = shlex.split("{} -c 'rv 0 {}'".format(NTPQ_BIN, ','.join(METRICS))) | |
print("Executing {}\n".format(ntq_command)) | |
data = subprocess.check_output(ntq_command) | |
data = "".join([ c.strip() for c in data]) | |
print(data.split(',')) | |
def main(): | |
collector = NTPCollector() | |
collector.collect() | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment