master
Sascha 2022-08-10 19:09:53 +07:00
parent c40f378a55
commit 735465ba31
2 changed files with 66 additions and 66 deletions

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

@ -1,27 +1,27 @@
#!/bin/bash #!/bin/bash
function writeMariaDB () function writeMariaDB ()
{ {
echo "write data to mariadb" echo "write data to mariadb"
mariadb-import --host server0 --user root -plungretter1 --local --fields-terminated-by=',' bandwidth speedtest.tmp mariadb-import --host server0 --user root -plungretter1 --local --fields-terminated-by=',' bandwidth speedtest.tmp
} }
function runTest () function runTest ()
{ {
# run speedtest against named server with csv output saved in tmp file # run speedtest against named server with csv output saved in tmp file
echo "running speedtest-cli" echo "running speedtest-cli"
speedtest-cli --secure --csv > speedtest.tmp speedtest-cli --secure --csv > speedtest.tmp
bat speedtest.tmp bat speedtest.tmp
# write output to db # write output to db
writeMariaDB writeMariaDB
# write output to csv # write output to csv
echo "write data to csv" echo "write data to csv"
cat speedtest.tmp >> speedtest.csv cat speedtest.tmp >> speedtest.csv
} }
# main # main
echo "bandwidth V0.1 by DJh2o2" echo "bandwidth V0.1 by DJh2o2"
runTest runTest
echo "Ready!" echo "Ready!"