extra commentaar en select hosts blok
This commit is contained in:
parent
fdb87ece2f
commit
631d32d914
@ -10,7 +10,7 @@ tree = ET.parse('config.xml') # parseer xml
|
||||
root = tree.getroot()
|
||||
|
||||
# laad config items in python variabelen
|
||||
flask_debug = bool(root.find('flask_debug').text == 'True') # vind node in xml en als waarde 'True' is zet variablele op True
|
||||
flask_debug = bool(root.find('flask_debug').text == 'True') # vind node in xml en als waarde 'True' is zet True
|
||||
db_location = root.find('sqlite_location').text
|
||||
|
||||
# initialiseer flask
|
||||
@ -83,12 +83,14 @@ class Mydb:
|
||||
% (metric, self.get_hostdbid(hostname), points))
|
||||
return self.cur.fetchall()
|
||||
|
||||
def get_hosts(self):
|
||||
self.cur.execute(''' SELECT * FROM hosts ''')
|
||||
return self.cur.fetchall()
|
||||
|
||||
def __del__(self):
|
||||
self.conn.commit()
|
||||
self.conn.close()
|
||||
|
||||
db = Mydb()
|
||||
|
||||
|
||||
def calc_ram(total, used):
|
||||
"""
|
||||
@ -101,15 +103,15 @@ def calc_ram(total, used):
|
||||
return f'{percentage:.1f}%' # return percentage afrondend naar 1 decimaal
|
||||
|
||||
|
||||
def host_create_plot(points, metric, hostname) -> Figure:
|
||||
data = db.get_xlatesthostmetric(hostname, metric, points)
|
||||
fig = Figure()
|
||||
fig.set_dpi(256)
|
||||
axis = fig.add_subplot(1, 1, 1)
|
||||
xs = [str(data[x][1]) for x in range(len(data))]
|
||||
ys = [int(data[x][0]) for x in range(len(data))]
|
||||
axis.plot(xs, ys)
|
||||
return fig
|
||||
def host_create_plot(points, metric, hostname):
|
||||
data = db.get_xlatesthostmetric(hostname, metric, points) # vraag de data op uit de database
|
||||
fig = Figure() # maak leeg figuur aan
|
||||
fig.set_dpi(256) # maak de details grooter van figuur
|
||||
axis = fig.add_subplot(1, 1, 1) # geen idee, moet toegevoegd worden, ik ben geen pro in wiskunde ok
|
||||
xs = [str(data[x][1]) for x in range(len(data))] # voeg alle x waardes(tijddatum) aan een lijst
|
||||
ys = [int(data[x][0]) for x in range(len(data))] # voeg alle y waardes(metric data) aan een lijst
|
||||
axis.plot(xs, ys) # plot de waardes
|
||||
return fig # return de figuur
|
||||
|
||||
|
||||
# dit is de document root
|
||||
@ -122,16 +124,17 @@ def index():
|
||||
@app.route('/api/v1/host/post', methods=['POST'])
|
||||
def host_post():
|
||||
data = request.get_json() # sla json data op in dict
|
||||
return '{"status": 200}' # return een json dict met waarde status 200
|
||||
return '{"status": 200}', 200 # return een json dict met waarde status 200
|
||||
|
||||
|
||||
@app.route('/api/v1/plot-metric-host/<metric>/<hostname>/<points>.png')
|
||||
@app.route('/api/v1/plot-metric-host/<metric>/<hostname>/<points>.png') # dit vraagt om problemen
|
||||
def plot_metric_host(metric, hostname, points):
|
||||
fig = host_create_plot(int(points), metric, hostname)
|
||||
fig = host_create_plot(int(points), metric, hostname) # deze int blok ook
|
||||
output = io.BytesIO()
|
||||
FigureCanvas(fig).print_png(output)
|
||||
return Response(output.getvalue(), mimetype='image/png')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
db = Mydb() # initialiseer db
|
||||
app.run(debug=flask_debug) # start flask
|
||||
|
Reference in New Issue
Block a user