Skip to content

Commit

Permalink
Merge pull request #46 from MiguelNdeCarvalho/add-up-metric
Browse files Browse the repository at this point in the history
Add speedtest_up metric
  • Loading branch information
MiguelNdeCarvalho authored Mar 4, 2021
2 parents 5dd3983 + 1c8ea78 commit 8a5ef54
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'Speedtest current Download Speed in bit/s')
upload_speed = Gauge('speedtest_upload_bits_per_second',
'Speedtest current Upload speed in bits/s')
up = Gauge('speedtest_up', 'Speedtest status whether the scrape worked')


def bytes_to_bits(bytes_per_sec):
Expand Down Expand Up @@ -49,7 +50,7 @@ def runTest():
# Socket error
print('Something went wrong')
print(data['error'])
return None
return (0, 0, 0, 0, 0, 0) # Return all data as 0
if "type" in data:
if data['type'] == 'log':
print(str(data["timestamp"]) + " - " + str(data["message"]))
Expand All @@ -60,17 +61,18 @@ def runTest():
download = bytes_to_bits(data['download']['bandwidth'])
upload = bytes_to_bits(data['upload']['bandwidth'])
return (actual_server, actual_jitter,
actual_ping, download, upload)
actual_ping, download, upload, 1)


@app.route("/metrics")
def updateResults():
r_server, r_jitter, r_ping, r_download, r_upload = runTest()
r_server, r_jitter, r_ping, r_download, r_upload, r_status = runTest()
server.set(r_server)
jitter.set(r_jitter)
ping.set(r_ping)
download_speed.set(r_download)
upload_speed.set(r_upload)
up.set(r_status)
current_dt = datetime.datetime.now()
print(current_dt.strftime("%d/%m/%Y %H:%M:%S - ") + "Server: "
+ str(r_server) + " | Jitter: " + str(r_jitter) + " ms | Ping: "
Expand Down

0 comments on commit 8a5ef54

Please sign in to comment.