From 7e8e06b239ed11c26a84862d1258ff6dcfd74a63 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Mon, 17 Oct 2016 17:05:50 +0200 Subject: [PATCH 1/6] Bump version Signed-off-by: Nicolas Lamirault --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index d43f317..3456482 100644 --- a/version/version.go +++ b/version/version.go @@ -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" From fd861df1f526e37d2f050e4c2cc1ca57e98ced5a Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Mon, 17 Oct 2016 17:07:24 +0200 Subject: [PATCH 2/6] Change port listening Signed-off-by: Nicolas Lamirault --- speedtest_exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speedtest_exporter.go b/speedtest_exporter.go index 46840fe..da78d8a 100644 --- a/speedtest_exporter.go +++ b/speedtest_exporter.go @@ -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") From 16481f5bff3d8a9892798cdd70205990cce8f520 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Tue, 17 Jan 2017 11:07:46 +0100 Subject: [PATCH 3/6] Add ignore files Signed-off-by: Nicolas Lamirault --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b816477 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Go +speedtest_exporter + +# Files +.DS_Store + +# Editor swap files +*.swp +*.swo +*.swn From 5e3d116850b02e0934009450d0775ba5e3605a39 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Tue, 17 Jan 2017 11:08:45 +0100 Subject: [PATCH 4/6] Refactoring using official zpeters speedtest repo Due to refactoring on the https://github.com/zpeters/speedtest repository, update dependency and code. Signed-off-by: Nicolas Lamirault --- speedtest/client.go | 41 ++++++++++++++++++++++++++++++----------- speedtest_exporter.go | 4 ++-- vendor/vendor.json | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/speedtest/client.go b/speedtest/client.go index 638aa60..0a3c6d6 100644 --- a/speedtest/client.go +++ b/speedtest/client.go @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Nicolas Lamirault +// Copyright (C) 2016, 2017 Nicolas Lamirault // 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 } diff --git a/speedtest_exporter.go b/speedtest_exporter.go index 46840fe..b3dbaf2 100644 --- a/speedtest_exporter.go +++ b/speedtest_exporter.go @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Nicolas Lamirault +// Copyright (C) 2016, 2017 Nicolas Lamirault // 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) diff --git a/vendor/vendor.json b/vendor/vendor.json index 035cfec..c8cc353 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -218,6 +218,12 @@ "revision": "382f87b929b84ce13e9c8a375a4b217f224e6c65", "revisionTime": "2016-09-26T15:04:02Z" }, + { + "checksumSHA1": "Cy6n4iTn6RtXOULn1+vufS2MWpc=", + "path": "github.com/zpeters/speedtest/coords", + "revision": "58d62245401b2a60ebc0c4acaf1d5bb5b8571aa8", + "revisionTime": "2016-12-15T03:44:06Z" + }, { "checksumSHA1": "CvvMRMDv3/NJpVjOiLb3Kr+qOtY=", "path": "github.com/zpeters/speedtest/internal/coords", @@ -242,6 +248,36 @@ "revision": "f77fc9e744a209979c966d1e1c33b464cb007861", "revisionTime": "2016-09-01T00:53:20Z" }, + { + "checksumSHA1": "vdgf5XOtpWaQpTV5nPz7QjqE3gA=", + "path": "github.com/zpeters/speedtest/misc", + "revision": "58d62245401b2a60ebc0c4acaf1d5bb5b8571aa8", + "revisionTime": "2016-12-15T03:44:06Z" + }, + { + "checksumSHA1": "BKKXhxf3hfAw/EnpRMOOQVtr6co=", + "path": "github.com/zpeters/speedtest/print", + "revision": "58d62245401b2a60ebc0c4acaf1d5bb5b8571aa8", + "revisionTime": "2016-12-15T03:44:06Z" + }, + { + "checksumSHA1": "qI/41r8fHJiicgcAnDicQziXDN8=", + "path": "github.com/zpeters/speedtest/sthttp", + "revision": "58d62245401b2a60ebc0c4acaf1d5bb5b8571aa8", + "revisionTime": "2016-12-15T03:44:06Z" + }, + { + "checksumSHA1": "EqWlhKYeHtJhxQMXfyvT6sQOf2g=", + "path": "github.com/zpeters/speedtest/stxml", + "revision": "58d62245401b2a60ebc0c4acaf1d5bb5b8571aa8", + "revisionTime": "2016-12-15T03:44:06Z" + }, + { + "checksumSHA1": "W069qAawDjVk0mrUmQVnO6xVm0Q=", + "path": "github.com/zpeters/speedtest/tests", + "revision": "58d62245401b2a60ebc0c4acaf1d5bb5b8571aa8", + "revisionTime": "2016-12-15T03:44:06Z" + }, { "checksumSHA1": "h+pFYiRHBogczS8/F1NoN3Ata44=", "path": "golang.org/x/crypto/curve25519", From 169d4e85c10d0a8519821e8f91ec8d14bc47ff6e Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Tue, 17 Jan 2017 11:11:38 +0100 Subject: [PATCH 5/6] Update copyright Signed-off-by: Nicolas Lamirault --- ChangeLog.md | 6 ++++++ Makefile | 2 +- speedtest_exporter_test.go | 2 +- version/version.go | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f42c872..b0eec47 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/Makefile b/Makefile index 179d73e..7b12164 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 2016 Nicolas Lamirault +# Copyright (C) 2016, 2017 Nicolas Lamirault # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/speedtest_exporter_test.go b/speedtest_exporter_test.go index 0e2d2d9..996d1b8 100644 --- a/speedtest_exporter_test.go +++ b/speedtest_exporter_test.go @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Nicolas Lamirault +// Copyright (C) 2016, 2017 Nicolas Lamirault // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/version/version.go b/version/version.go index d43f317..0a3bd9d 100644 --- a/version/version.go +++ b/version/version.go @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Nicolas Lamirault +// Copyright (C) 2016, 2017 Nicolas Lamirault // 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" From 2b2f463a70ab853f89f00ef0ecc4df7acda39eac Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Tue, 17 Jan 2017 11:20:09 +0100 Subject: [PATCH 6/6] update binaries version Signed-off-by: Nicolas Lamirault --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 059ab94..1c9374d 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,16 @@ This Prometheus exporter check your network connection. Metrics are : You can download the binaries : -* Architecture i386 [ [linux](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_linux_386) / [darwin](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_darwin_386) / [freebsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_freebsd_386) / [netbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_netbsd_386) / [openbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_openbsd_386) / [windows](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_windows_386.exe) ] -* Architecture amd64 [ [linux](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_linux_amd64) / [darwin](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_darwin_amd64) / [freebsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_freebsd_amd64) / [netbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_netbsd_amd64) / [openbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_openbsd_amd64) / [windows](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_windows_amd64.exe) ] -* Architecture arm [ [linux](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_linux_arm) / [freebsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_freebsd_arm) / [netbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.1.0_netbsd_arm) ] +* Architecture i386 [ [linux](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_linux_386) / [darwin](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_darwin_386) / [freebsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_freebsd_386) / [netbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_netbsd_386) / [openbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_openbsd_386) / [windows](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_windows_386.exe) ] +* Architecture amd64 [ [linux](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_linux_amd64) / [darwin](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_darwin_amd64) / [freebsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_freebsd_amd64) / [netbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_netbsd_amd64) / [openbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_openbsd_amd64) / [windows](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_windows_amd64.exe) ] +* Architecture arm [ [linux](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_linux_arm) / [freebsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_freebsd_arm) / [netbsd](https://bintray.com/artifact/download/nlamirault/oss/speedtest_exporter-0.2.0_netbsd_arm) ] ## Usage Launch the Prometheus exporter : - $ speedtest_exporter -log.level=debug + $ speedtest_exporter -log.level=debug ## Development