Skip to content

Commit c9abd8b

Browse files
Merge pull request #140 from MiguelNdeCarvalho/check-for-speetest-binary
Add check for Speedtest-CLI
2 parents 996e516 + 131c714 commit c9abd8b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/exporter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from prometheus_client import make_wsgi_app, Gauge
77
from flask import Flask
88
from waitress import serve
9+
from shutil import which
910

1011
app = Flask("Speedtest-Exporter") # Create flask app
1112

@@ -132,7 +133,23 @@ def mainPage():
132133
"Click <a href='/metrics'>here</a> to see metrics.")
133134

134135

136+
def checkForBinary():
137+
if which("speedtest") is None:
138+
logging.error("Speedtest CLI binary not found. Please install it by" +
139+
" going to the official website.\n" +
140+
"https://www.speedtest.net/apps/cli")
141+
exit(1)
142+
speedtestVersionDialog = (subprocess.run(['speedtest', '--version'],
143+
capture_output=True, text=True))
144+
if "Speedtest by Ookla" not in speedtestVersionDialog.stdout:
145+
logging.error("Speedtest CLI that is installed is not the official" +
146+
" one. Please install it by going to the official" +
147+
" website.\nhttps://www.speedtest.net/apps/cli")
148+
exit(1)
149+
150+
135151
if __name__ == '__main__':
152+
checkForBinary()
136153
PORT = os.getenv('SPEEDTEST_PORT', 9798)
137154
logging.info("Starting Speedtest-Exporter on http://localhost:" +
138155
str(PORT))

0 commit comments

Comments
 (0)