This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: update binaries version Update copyright Refactoring using official zpeters speedtest repo Add ignore files Change port listening Bump version
- Loading branch information
Showing
9 changed files
with
93 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Go | ||
speedtest_exporter | ||
|
||
# Files | ||
.DS_Store | ||
|
||
# Editor swap files | ||
*.swp | ||
*.swo | ||
*.swn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
ChangeLog | ||
============== | ||
|
||
|
||
# Version 0.2.0 (01/17/2017) | ||
|
||
- `FIX` Initialize correctly client. | ||
- Update dependency to zpeters Speedtest code | ||
|
||
# Version 0.1.0 (10/05/2016) | ||
|
||
- Prometheus exporter for Speedtest measures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (C) 2016 Nicolas Lamirault <[email protected]> | ||
# Copyright (C) 2016, 2017 Nicolas Lamirault <[email protected]> | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (C) 2016 Nicolas Lamirault <[email protected]> | ||
// Copyright (C) 2016, 2017 Nicolas Lamirault <[email protected]> | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -18,10 +18,15 @@ import ( | |
"time" | ||
|
||
"github.com/prometheus/common/log" | ||
"github.com/zpeters/speedtest/print" | ||
"github.com/zpeters/speedtest/sthttp" | ||
"github.com/zpeters/speedtest/tests" | ||
) | ||
|
||
const ( | ||
userAgent = "speedtest_exporter" | ||
) | ||
|
||
// Client defines the Speedtest client | ||
type Client struct { | ||
Server sthttp.Server | ||
|
@@ -34,8 +39,8 @@ type Client struct { | |
func NewClient(configURL string, serversURL string) (*Client, error) { | ||
log.Debugf("New Speedtest client %s %s", configURL, serversURL) | ||
configTimeout, _ := time.ParseDuration("15s") | ||
latencyTimeout, _ := time.ParseDuration("15s") | ||
downloadTimeout, _ := time.ParseDuration("15s") | ||
// latencyTimeout, _ := time.ParseDuration("15s") | ||
// downloadTimeout, _ := time.ParseDuration("15s") | ||
stClient := sthttp.NewClient( | ||
&sthttp.SpeedtestConfig{ | ||
ConfigURL: configURL, | ||
|
@@ -44,27 +49,38 @@ func NewClient(configURL string, serversURL string) (*Client, error) { | |
NumClosest: 3, | ||
NumLatencyTests: 5, | ||
Interface: "", | ||
Blacklist: "", | ||
Blacklist: []string{}, | ||
UserAgent: userAgent, | ||
}, | ||
&sthttp.HTTPConfig{ | ||
ConfigTimeout: configTimeout, | ||
LatencyTimeout: latencyTimeout, | ||
DownloadTimeout: downloadTimeout, | ||
// ConfigTimeout: configTimeout, | ||
// LatencyTimeout: latencyTimeout, | ||
// DownloadTimeout: downloadTimeout, | ||
HTTPTimeout: configTimeout, | ||
}, | ||
true, | ||
"|") | ||
|
||
log.Debug("Retrieve configuration") | ||
config, err := stClient.GetConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
stClient.Config = &config | ||
|
||
print.EnvironmentReport(stClient) | ||
|
||
log.Debugf("Retrieve all servers") | ||
var allServers []sthttp.Server | ||
allServers, err := stClient.GetServers() | ||
allServers, err = stClient.GetServers() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Debugf("Retrieve closest servers") | ||
closestServers := stClient.GetClosestServers(allServers) | ||
log.Debugf("Find test server") | ||
// log.Infof("Closest Servers: %s", closestServers) | ||
testServer := stClient.GetFastestServer(closestServers) | ||
log.Infof("Test server: %s", testServer) | ||
|
||
return &Client{ | ||
Server: testServer, | ||
|
@@ -78,11 +94,14 @@ func (client *Client) NetworkMetrics() map[string]float64 { | |
result := map[string]float64{} | ||
tester := tests.NewTester(client.SpeedtestClient, tests.DefaultDLSizes, tests.DefaultULSizes, false, false) | ||
downloadMbps := tester.Download(client.Server) | ||
log.Infof("Speedtest Download: %v Mbps", downloadMbps) | ||
uploadMbps := tester.Upload(client.Server) | ||
log.Infof("Speedtest Upload: %v Mbps", uploadMbps) | ||
ping := client.Server.Latency | ||
log.Infof("Speedtest Latency: %v ms", ping) | ||
result["download"] = downloadMbps | ||
result["upload"] = uploadMbps | ||
result["ping"] = ping | ||
log.Debugf("Speedtest results: %s", result) | ||
log.Infof("Speedtest results: %s", result) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (C) 2016 Nicolas Lamirault <[email protected]> | ||
// Copyright (C) 2016, 2017 Nicolas Lamirault <[email protected]> | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -61,7 +61,7 @@ type Exporter struct { | |
|
||
// NewExporter returns an initialized Exporter. | ||
func NewExporter(config string, server string, interval time.Duration) (*Exporter, error) { | ||
log.Infoln("Setup Speedtest client with interval %s", interval) | ||
log.Infof("Setup Speedtest client with interval %s", interval) | ||
client, err := speedtest.NewClient(config, server) | ||
if err != nil { | ||
return nil, fmt.Errorf("Can't create the Speedtest client: %s", err) | ||
|
@@ -105,7 +105,7 @@ func init() { | |
func main() { | ||
var ( | ||
showVersion = flag.Bool("version", false, "Print version information.") | ||
listenAddress = flag.String("web.listen-address", ":9111", "Address to listen on for web interface and telemetry.") | ||
listenAddress = flag.String("web.listen-address", ":9112", "Address to listen on for web interface and telemetry.") | ||
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") | ||
configURL = flag.String("speedtest.config-url", "http://c.speedtest.net/speedtest-config.php?x="+uniuri.New(), "Speedtest configuration URL") | ||
serverURL = flag.String("speedtest.server-url", "http://c.speedtest.net/speedtest-servers-static.php?x="+uniuri.New(), "Speedtest server URL") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (C) 2016 Nicolas Lamirault <[email protected]> | ||
// Copyright (C) 2016, 2017 Nicolas Lamirault <[email protected]> | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (C) 2016 Nicolas Lamirault <[email protected]> | ||
// Copyright (C) 2016, 2017 Nicolas Lamirault <[email protected]> | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -15,4 +15,4 @@ | |
package version | ||
|
||
// Version represents the application version using SemVer | ||
const Version string = "0.1.0" | ||
const Version string = "0.2.0" |