-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgoogle_chart_host_stats
More file actions
28 lines (25 loc) · 971 Bytes
/
google_chart_host_stats
File metadata and controls
28 lines (25 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
import pygooglechart
import sqlite3
def query_db_chartable(db_name, host, service):
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
sql_statement = """select value, time from data where host like ? and service like ? order by time"""
cursor.execute(sql_statement, (host, service) )
result = cursor.fetchall()
cursor.close()
return result
if __name__ =="__main__":
database_name = "it.db"
results = query_db_chartable(database_name, "iinet", "HTTP")
counts = [float(x[0]) for x in results]
time_lable = [str(x[1]) for x in results]
chart = pygooglechart.SimpleLineChart(700,400)
chart.add_data(counts)
chart.set_axis_range(pygooglechart.Axis.LEFT, 0, max(counts))
first = time_lable[0]
last = time_lable[int(len(time_lable) -1)]
index = chart.set_axis_labels(pygooglechart.Axis.BOTTOM, [first, last])
chart.set_axis_style(index, "202020", font_size=9, alignment=-1)
chart.set_title("iinet - http")
print chart.get_url()