Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
speedtest-exporter-cli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Varac
speedtest-exporter-cli
Commits
3f98edd9
Verified
Commit
3f98edd9
authored
5 years ago
by
Varac
Browse files
Options
Downloads
Plain Diff
Merge branch 'improvements'
parents
d54cc632
2491c24a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#25452
passed
5 years ago
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlint
+2
-0
2 additions, 0 deletions
.gitlint
run-speedtest.py
+42
-24
42 additions, 24 deletions
run-speedtest.py
with
44 additions
and
24 deletions
.gitlint
0 → 100644
+
2
−
0
View file @
3f98edd9
[general]
ignore=body-is-missing
This diff is collapsed.
Click to expand it.
run-speedtest.py
+
42
−
24
View file @
3f98edd9
#!/usr/bin/python
#!/usr/bin/python3
"""
Export speedtest up- and download speed metrics to prometheus.
"""
import
os
import
socket
import
speedtest
import
time
from
prometheus_client
import
start_http_server
,
Summary
,
Gauge
from
prometheus_client
import
start_http_server
,
Gauge
servers
=
[]
# If you want to test against a specific server
# servers = [1234]
if
'
SPEEDTEST_INTERVAL
'
in
os
.
environ
:
test_interval
=
os
.
environ
[
'
SPEEDTEST_INTERVAL
'
]
else
:
test_interval
=
60
# initiate speed test every 60 seconds
port
=
9104
s
=
speedtest
.
Speedtest
()
g_download
=
Gauge
(
'
download_speed
'
,
'
Download speed
'
)
g_upload
=
Gauge
(
'
upload_speed
'
,
'
Upload speed
'
)
def
process_request
(
t
):
"""
Measure up- and download speed using speedtest.
"""
print
(
"
Get servers
"
)
s
.
get_servers
(
servers
)
print
(
"
Get best servers
"
)
s
.
get_best_server
()
print
(
"
Test download speed
"
)
s
.
download
()
print
(
"
Test upload speed
"
)
s
.
upload
()
results_dict
=
s
.
results
.
dict
()
g_download
.
set
(
results_dict
[
"
download
"
])
g_upload
.
set
(
results_dict
[
"
upload
"
])
print
(
"
upload: %s
"
%
(
results_dict
[
"
upload
"
]))
print
(
"
download: %s
"
%
(
results_dict
[
"
download
"
]))
print
(
"
Sleeping {0} seconds
"
.
format
(
t
))
time
.
sleep
(
t
)
if
__name__
==
'
__main__
'
:
# Start up the server to expose the metrics.
start_http_server
(
9104
)
print
(
"
Start http server on port {0}
"
.
format
(
port
))
start_http_server
(
port
)
# Generate some requests.
while
True
:
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment