bandwidth/bandwidth.py

57 lines
1.4 KiB
Python

import matplotlib.pyplot as plt
import mysql.connector
def Average(lst):
return sum(lst) / len(lst)
# mariadb
mariadbConnection = mysql.connector.connect(host="192.168.177.7", port="3306", user="root", password="Lungretter1!", database="bandwidth")
mariadbCursor = mariadbConnection.cursor()
mariadbCursor.execute("SELECT times, ping, download, upload FROM speedtest")
mariadbResult = mariadbCursor.fetchall()
times = []
pings = []
downloads = []
uploads = []
sum_ping = 0.0
for i in mariadbResult:
times.append(i[0])
pings.append(i[1])
downloads.append(i[2])
uploads.append(i[3])
print("i = ", len(times))
print("avg ping = ", Average(pings), "ms")
print("avg download = ", Average(downloads) / 1000000, "mbit/s")
print("avg upload = ", Average(uploads) / 1000000, "mbit/s")
# plotall
plt.plot(times, pings, label="Ping")
plt.plot(times, downloads, label="Download")
plt.plot(times, uploads, label="Upload")
plt.title("bandwidth from mariadb")
plt.legend()
plt.show()
# plotping
#plt.plot(times, pings, label="Ping")
#plt.title("pings from mariadb")
# plt.legend()
# plt.show()
# plotdownloads
#plt.plot(times, downloads, label="Download")
#plt.title("downloads from mariadb")
# plt.legend()
# plt.show()
# plotuploads
#plt.plot(times, uploads, label="Upload")
#plt.title("uploads from mariadb")
# plt.legend()
# plt.show()