|
|
|
@ -10,10 +10,11 @@ from config import *
|
|
|
|
|
|
|
|
|
|
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_line(line):
|
|
|
|
|
if line[-2:] != "\r\n":
|
|
|
|
|
print("Failed to parse: newline broken")
|
|
|
|
|
return {key : None for key in FORMAT}
|
|
|
|
|
return {key: None for key in FORMAT}
|
|
|
|
|
line = line[:-2]
|
|
|
|
|
|
|
|
|
|
crc_str = line[-4:]
|
|
|
|
@ -22,7 +23,7 @@ def parse_line(line):
|
|
|
|
|
calced_crc = calc_crc(payload.encode('ascii'))
|
|
|
|
|
if crc != calc_crc(payload.encode('ascii')):
|
|
|
|
|
print("Failed to parse: CRC broken")
|
|
|
|
|
return {key : None for key in FORMAT}
|
|
|
|
|
return {key: None for key in FORMAT}
|
|
|
|
|
|
|
|
|
|
parts = payload.split(';')
|
|
|
|
|
parts = [p.strip() for p in parts]
|
|
|
|
@ -31,26 +32,31 @@ def parse_line(line):
|
|
|
|
|
|
|
|
|
|
return dict(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_database():
|
|
|
|
|
sources = []
|
|
|
|
|
for name, minval, maxval in STORED_VALUES:
|
|
|
|
|
sources += ["DS:%s:GAUGE:%d:%f:%f" % (name, DATA_INTERVAL * 2, minval, maxval)]
|
|
|
|
|
sources += [
|
|
|
|
|
"DS:%s:GAUGE:%d:%f:%f" % (name, DATA_INTERVAL * 2, minval, maxval)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
now = time.time()
|
|
|
|
|
now = now - (now % DATA_INTERVAL)
|
|
|
|
|
|
|
|
|
|
rrd_params = [DATA_FILE,
|
|
|
|
|
"--start", "%d" % now,
|
|
|
|
|
"--step", str(DATA_INTERVAL)]
|
|
|
|
|
rrd_params = [
|
|
|
|
|
DATA_FILE, "--start",
|
|
|
|
|
"%d" % now, "--step",
|
|
|
|
|
str(DATA_INTERVAL)
|
|
|
|
|
]
|
|
|
|
|
rrd_params += sources
|
|
|
|
|
rows = ARCHIVE_INTERVAL / DATA_INTERVAL
|
|
|
|
|
rrd_params += ["RRA:LAST:0.1:1:%d" % (rows,)]
|
|
|
|
|
rrd_params += ["RRA:LAST:0.1:1:%d" % (rows, )]
|
|
|
|
|
rrdtool.create(*rrd_params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rrd_archive_params = [ARCHIVE_DATA_FILE,
|
|
|
|
|
"--start", "now",
|
|
|
|
|
"--step", str(DATA_INTERVAL)]
|
|
|
|
|
rrd_archive_params = [
|
|
|
|
|
ARCHIVE_DATA_FILE, "--start", "now", "--step",
|
|
|
|
|
str(DATA_INTERVAL)
|
|
|
|
|
]
|
|
|
|
|
steps = ARCHIVE_INTERVAL / DATA_INTERVAL
|
|
|
|
|
rows = ARCHIVE_KEEP_INTERVAL / ARCHIVE_INTERVAL
|
|
|
|
|
rrd_archive_params += sources
|
|
|
|
@ -58,16 +64,14 @@ def create_database():
|
|
|
|
|
rrdtool.create(*rrd_archive_params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_database(line):
|
|
|
|
|
update_values = []
|
|
|
|
|
for name, _, _ in STORED_VALUES:
|
|
|
|
|
|
|
|
|
|
if line[name] != None:
|
|
|
|
|
update_values += ["%f" % float(line[name])]
|
|
|
|
|
else:
|
|
|
|
|
update_values += [""]
|
|
|
|
|
|
|
|
|
|
if line[name] != None:
|
|
|
|
|
update_values += ["%f" % float(line[name])]
|
|
|
|
|
else:
|
|
|
|
|
update_values += [""]
|
|
|
|
|
|
|
|
|
|
now = time.time()
|
|
|
|
|
now = now - (now % DATA_INTERVAL)
|
|
|
|
@ -80,13 +84,14 @@ def update_database(line):
|
|
|
|
|
print("Failed updating files")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_graphs():
|
|
|
|
|
for graph_name, lines in GRAPHS.items():
|
|
|
|
|
|
|
|
|
|
# Render current data
|
|
|
|
|
graph_params = ['%s.png' % graph_name, '-a',
|
|
|
|
|
'PNG', '-s', 'n-%d' % ARCHIVE_INTERVAL]
|
|
|
|
|
graph_params = [
|
|
|
|
|
'%s.png' % graph_name, '-a', 'PNG', '-s',
|
|
|
|
|
'n-%d' % ARCHIVE_INTERVAL
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for name, lable, color in lines:
|
|
|
|
|
graph_params += ['DEF:%s=%s:%s:LAST' % (name, DATA_FILE, name)]
|
|
|
|
@ -98,8 +103,10 @@ def update_graphs():
|
|
|
|
|
print("Failed to render current data")
|
|
|
|
|
|
|
|
|
|
# Also render Archives
|
|
|
|
|
graph_params = ['%s_archive.png' % graph_name, '-a',
|
|
|
|
|
'PNG', '-s', 'n-%d' % ARCHIVE_KEEP_INTERVAL]
|
|
|
|
|
graph_params = [
|
|
|
|
|
'%s_archive.png' % graph_name, '-a', 'PNG', '-s',
|
|
|
|
|
'n-%d' % ARCHIVE_KEEP_INTERVAL
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for name, lable, color in lines:
|
|
|
|
|
graph_params += ['DEF:%s=%s:%s:AVERAGE' % (name, DATA_FILE, name)]
|
|
|
|
@ -117,22 +124,24 @@ def _do_upload(sftp, src, dest):
|
|
|
|
|
except:
|
|
|
|
|
print("Unexpected error while uploading:", sys.exc_info()[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upload_graphs():
|
|
|
|
|
|
|
|
|
|
key = paramiko.RSAKey.from_private_key_file(SFTP_KEY)
|
|
|
|
|
transport = paramiko.Transport((SFTP_HOST, SFTP_PORT))
|
|
|
|
|
transport.connect()
|
|
|
|
|
transport.auth_publickey(SFTP_USER, key)
|
|
|
|
|
sftp = paramiko.SFTPClient.from_transport(transport)
|
|
|
|
|
key = paramiko.RSAKey.from_private_key_file(SFTP_KEY)
|
|
|
|
|
transport = paramiko.Transport((SFTP_HOST, SFTP_PORT))
|
|
|
|
|
transport.connect()
|
|
|
|
|
transport.auth_publickey(SFTP_USER, key)
|
|
|
|
|
sftp = paramiko.SFTPClient.from_transport(transport)
|
|
|
|
|
|
|
|
|
|
for name, _ in GRAPHS.items():
|
|
|
|
|
for name, _ in GRAPHS.items():
|
|
|
|
|
|
|
|
|
|
_do_upload(sftp, '%s.png' % name, 'solar/%s.png' % name)
|
|
|
|
|
_do_upload(sftp, '%s_archive.png' % name, 'solar/%s_archive.png' % name)
|
|
|
|
|
_do_upload(sftp, '%s.png' % name, 'solar/%s.png' % name)
|
|
|
|
|
_do_upload(sftp, '%s_archive.png' % name,
|
|
|
|
|
'solar/%s_archive.png' % name)
|
|
|
|
|
|
|
|
|
|
_do_upload(sftp, 'index.html', 'solar/index.html')
|
|
|
|
|
sftp.close()
|
|
|
|
|
transport.close()
|
|
|
|
|
_do_upload(sftp, 'index.html', 'solar/index.html')
|
|
|
|
|
sftp.close()
|
|
|
|
|
transport.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
@ -155,7 +164,5 @@ def main():
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|
|
|
|
|