Fixed ident
This commit is contained in:
parent
f28701d04e
commit
175ae64b75
43
update.py
43
update.py
|
@ -10,6 +10,7 @@ from config import *
|
||||||
|
|
||||||
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
|
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
|
||||||
|
|
||||||
|
|
||||||
def parse_line(line):
|
def parse_line(line):
|
||||||
if line[-2:] != "\r\n":
|
if line[-2:] != "\r\n":
|
||||||
print("Failed to parse: newline broken")
|
print("Failed to parse: newline broken")
|
||||||
|
@ -31,26 +32,31 @@ def parse_line(line):
|
||||||
|
|
||||||
return dict(data)
|
return dict(data)
|
||||||
|
|
||||||
|
|
||||||
def create_database():
|
def create_database():
|
||||||
sources = []
|
sources = []
|
||||||
for name, minval, maxval in STORED_VALUES:
|
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 = time.time()
|
||||||
now = now - (now % DATA_INTERVAL)
|
now = now - (now % DATA_INTERVAL)
|
||||||
|
|
||||||
rrd_params = [DATA_FILE,
|
rrd_params = [
|
||||||
"--start", "%d" % now,
|
DATA_FILE, "--start",
|
||||||
"--step", str(DATA_INTERVAL)]
|
"%d" % now, "--step",
|
||||||
|
str(DATA_INTERVAL)
|
||||||
|
]
|
||||||
rrd_params += sources
|
rrd_params += sources
|
||||||
rows = ARCHIVE_INTERVAL / DATA_INTERVAL
|
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)
|
rrdtool.create(*rrd_params)
|
||||||
|
|
||||||
|
rrd_archive_params = [
|
||||||
rrd_archive_params = [ARCHIVE_DATA_FILE,
|
ARCHIVE_DATA_FILE, "--start", "now", "--step",
|
||||||
"--start", "now",
|
str(DATA_INTERVAL)
|
||||||
"--step", str(DATA_INTERVAL)]
|
]
|
||||||
steps = ARCHIVE_INTERVAL / DATA_INTERVAL
|
steps = ARCHIVE_INTERVAL / DATA_INTERVAL
|
||||||
rows = ARCHIVE_KEEP_INTERVAL / ARCHIVE_INTERVAL
|
rows = ARCHIVE_KEEP_INTERVAL / ARCHIVE_INTERVAL
|
||||||
rrd_archive_params += sources
|
rrd_archive_params += sources
|
||||||
|
@ -58,7 +64,6 @@ def create_database():
|
||||||
rrdtool.create(*rrd_archive_params)
|
rrdtool.create(*rrd_archive_params)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_database(line):
|
def update_database(line):
|
||||||
update_values = []
|
update_values = []
|
||||||
for name, _, _ in STORED_VALUES:
|
for name, _, _ in STORED_VALUES:
|
||||||
|
@ -68,7 +73,6 @@ def update_database(line):
|
||||||
else:
|
else:
|
||||||
update_values += [""]
|
update_values += [""]
|
||||||
|
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
now = now - (now % DATA_INTERVAL)
|
now = now - (now % DATA_INTERVAL)
|
||||||
line = ("%d:" % now) + ":".join(update_values)
|
line = ("%d:" % now) + ":".join(update_values)
|
||||||
|
@ -80,13 +84,14 @@ def update_database(line):
|
||||||
print("Failed updating files")
|
print("Failed updating files")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_graphs():
|
def update_graphs():
|
||||||
for graph_name, lines in GRAPHS.items():
|
for graph_name, lines in GRAPHS.items():
|
||||||
|
|
||||||
# Render current data
|
# Render current data
|
||||||
graph_params = ['%s.png' % graph_name, '-a',
|
graph_params = [
|
||||||
'PNG', '-s', 'n-%d' % ARCHIVE_INTERVAL]
|
'%s.png' % graph_name, '-a', 'PNG', '-s',
|
||||||
|
'n-%d' % ARCHIVE_INTERVAL
|
||||||
|
]
|
||||||
|
|
||||||
for name, lable, color in lines:
|
for name, lable, color in lines:
|
||||||
graph_params += ['DEF:%s=%s:%s:LAST' % (name, DATA_FILE, name)]
|
graph_params += ['DEF:%s=%s:%s:LAST' % (name, DATA_FILE, name)]
|
||||||
|
@ -98,8 +103,10 @@ def update_graphs():
|
||||||
print("Failed to render current data")
|
print("Failed to render current data")
|
||||||
|
|
||||||
# Also render Archives
|
# Also render Archives
|
||||||
graph_params = ['%s_archive.png' % graph_name, '-a',
|
graph_params = [
|
||||||
'PNG', '-s', 'n-%d' % ARCHIVE_KEEP_INTERVAL]
|
'%s_archive.png' % graph_name, '-a', 'PNG', '-s',
|
||||||
|
'n-%d' % ARCHIVE_KEEP_INTERVAL
|
||||||
|
]
|
||||||
|
|
||||||
for name, lable, color in lines:
|
for name, lable, color in lines:
|
||||||
graph_params += ['DEF:%s=%s:%s:AVERAGE' % (name, DATA_FILE, name)]
|
graph_params += ['DEF:%s=%s:%s:AVERAGE' % (name, DATA_FILE, name)]
|
||||||
|
@ -117,6 +124,7 @@ def _do_upload(sftp, src, dest):
|
||||||
except:
|
except:
|
||||||
print("Unexpected error while uploading:", sys.exc_info()[1])
|
print("Unexpected error while uploading:", sys.exc_info()[1])
|
||||||
|
|
||||||
|
|
||||||
def upload_graphs():
|
def upload_graphs():
|
||||||
|
|
||||||
key = paramiko.RSAKey.from_private_key_file(SFTP_KEY)
|
key = paramiko.RSAKey.from_private_key_file(SFTP_KEY)
|
||||||
|
@ -128,7 +136,8 @@ def upload_graphs():
|
||||||
for name, _ in GRAPHS.items():
|
for name, _ in GRAPHS.items():
|
||||||
|
|
||||||
_do_upload(sftp, '%s.png' % name, 'solar/%s.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, '%s_archive.png' % name,
|
||||||
|
'solar/%s_archive.png' % name)
|
||||||
|
|
||||||
_do_upload(sftp, 'index.html', 'solar/index.html')
|
_do_upload(sftp, 'index.html', 'solar/index.html')
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
@ -155,7 +164,5 @@ def main():
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue