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.
Signed-off-by: Nicolas Lamirault <[email protected]>
- Loading branch information
1 parent
4c60ea7
commit 9c7f866
Showing
562 changed files
with
208,785 additions
and
0 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,6 @@ | ||
ChangeLog | ||
============== | ||
|
||
# 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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Copyright (C) 2016 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. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
APP = speedtest_exporter | ||
|
||
VERSION=$(shell \ | ||
grep "const Version" version/version.go \ | ||
|awk -F'=' '{print $$2}' \ | ||
|sed -e "s/[^0-9.]//g" \ | ||
|sed -e "s/ //g") | ||
|
||
SHELL = /bin/bash | ||
|
||
DIR = $(shell pwd) | ||
|
||
DOCKER = docker | ||
|
||
GO = go | ||
GLIDE = glide | ||
|
||
GOX = gox -os="linux darwin windows freebsd openbsd netbsd" | ||
GOX_ARGS = "-output={{.Dir}}-$(VERSION)_{{.OS}}_{{.Arch}}" | ||
|
||
BINTRAY_URI = https://api.bintray.com | ||
BINTRAY_USERNAME = nlamirault | ||
BINTRAY_REPOSITORY= oss | ||
|
||
NO_COLOR=\033[0m | ||
OK_COLOR=\033[32;01m | ||
ERROR_COLOR=\033[31;01m | ||
WARN_COLOR=\033[33;01m | ||
|
||
MAKE_COLOR=\033[33;01m%-20s\033[0m | ||
|
||
MAIN = github.com/nlamirault/speedtest_exporter | ||
SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/') | ||
PKGS = $(shell glide novendor) | ||
EXE = $(shell ls speedtest_exporter-${VERSION}_*) | ||
|
||
PACKAGE=$(APP)-$(VERSION) | ||
ARCHIVE=$(PACKAGE).tar | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
.PHONY: help | ||
help: | ||
@echo -e "$(OK_COLOR)==== $(APP) [$(VERSION)] ====$(NO_COLOR)" | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(MAKE_COLOR) : %s\n", $$1, $$2}' | ||
|
||
clean: ## Cleanup | ||
@echo -e "$(OK_COLOR)[$(APP)] Cleanup$(NO_COLOR)" | ||
@rm -fr $(EXE) $(APP) $(APP)-*.tar.gz | ||
|
||
.PHONY: init | ||
init: ## Install requirements | ||
@echo -e "$(OK_COLOR)[$(APP)] Install requirements$(NO_COLOR)" | ||
@go get -u github.com/golang/glog | ||
@go get -u github.com/kardianos/govendor | ||
@go get -u github.com/Masterminds/rmvcsdir | ||
@go get -u github.com/golang/lint/golint | ||
@go get -u github.com/kisielk/errcheck | ||
@go get -u golang.org/x/tools/cmd/oracle | ||
@go get -u github.com/mitchellh/gox | ||
|
||
.PHONY: deps | ||
deps: ## Install dependencies | ||
@echo -e "$(OK_COLOR)[$(APP)] Update dependencies$(NO_COLOR)" | ||
@glide up -u -s -v | ||
|
||
.PHONY: build | ||
build: ## Make binary | ||
@echo -e "$(OK_COLOR)[$(APP)] Build $(NO_COLOR)" | ||
@$(GO) build . | ||
|
||
.PHONY: test | ||
test: ## Launch unit tests | ||
@echo -e "$(OK_COLOR)[$(APP)] Launch unit tests $(NO_COLOR)" | ||
@$(GO) test -v $$(glide nv) | ||
|
||
.PHONY: run | ||
run: ## Start exporter | ||
@echo -e "$(OK_COLOR)[$(APP)] Start the exporter $(NO_COLOR)" | ||
@./$(APP) -log.level DEBUG | ||
|
||
.PHONY: lint | ||
lint: ## Launch golint | ||
@$(foreach file,$(SRCS),golint $(file) || exit;) | ||
|
||
.PHONY: vet | ||
vet: ## Launch go vet | ||
@$(foreach file,$(SRCS),$(GO) vet $(file) || exit;) | ||
|
||
.PHONY: errcheck | ||
errcheck: ## Launch go errcheck | ||
@echo -e "$(OK_COLOR)[$(APP)] Go Errcheck $(NO_COLOR)" | ||
@$(foreach pkg,$(PKGS),errcheck $(pkg) $(glide novendor) || exit;) | ||
|
||
.PHONY: coverage | ||
coverage: ## Launch code coverage | ||
@$(foreach pkg,$(PKGS),$(GO) test -cover $(pkg) $(glide novendor) || exit;) | ||
|
||
gox: ## Make all binaries | ||
@echo -e "$(OK_COLOR)[$(APP)] Create binaries $(NO_COLOR)" | ||
$(GOX) $(GOX_ARGS) github.com/nlamirault/speedtest_exporter | ||
|
||
.PHONY: binaries | ||
binaries: ## Upload all binaries | ||
@echo -e "$(OK_COLOR)[$(APP)] Upload binaries to Bintray $(NO_COLOR)" | ||
for i in $(EXE); do \ | ||
curl -T $$i \ | ||
-u$(BINTRAY_USERNAME):$(BINTRAY_APIKEY) \ | ||
"$(BINTRAY_URI)/content/$(BINTRAY_USERNAME)/$(BINTRAY_REPOSITORY)/$(APP)/${VERSION}/$$i;publish=1"; \ | ||
done | ||
|
||
# for goprojectile | ||
.PHONY: gopath | ||
gopath: | ||
@echo `pwd`:`pwd`/vendor |
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,78 @@ | ||
# speedtest_exporter | ||
|
||
[![License Apache 2][badge-license]](LICENSE) | ||
[![GitHub version](https://badge.fury.io/gh/nlamirault%2Fspeedtest_exporter.svg)](https://badge.fury.io/gh/nlamirault%2Fspeedtest_exporter) | ||
|
||
* Master : [![Circle CI](https://circleci.com/gh/nlamirault/speedtest_exporter/tree/master.svg?style=svg)](https://circleci.com/gh/nlamirault/speedtest_exporter/tree/master) | ||
* Develop : [![Circle CI](https://circleci.com/gh/nlamirault/speedtest_exporter/tree/develop.svg?style=svg)](https://circleci.com/gh/nlamirault/speedtest_exporter/tree/develop) | ||
|
||
This Prometheus exporter check your network connection. Metrics are : | ||
* Latency | ||
* Download bandwidth | ||
* Upload bandwidth | ||
|
||
|
||
## Installation | ||
|
||
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) ] | ||
|
||
|
||
## Usage | ||
|
||
Launch the Prometheus exporter : | ||
|
||
$ speedtest_exporter -log.level=debug | ||
|
||
|
||
## Development | ||
|
||
* Initialize environment | ||
|
||
$ make init | ||
|
||
* Build tool : | ||
|
||
$ make build | ||
|
||
* Launch unit tests : | ||
|
||
$ make test | ||
|
||
|
||
## Local Deployment | ||
|
||
* Launch Prometheus using the configuration file in this repository: | ||
|
||
$ prometheus -config.file=prometheus.yml | ||
|
||
* Launch exporter: | ||
|
||
$ speedtest_exporter -log.level=debug | ||
|
||
* Check that Prometheus find the exporter on `http://localhost:9090/targets` | ||
|
||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING](CONTRIBUTING.md). | ||
|
||
|
||
## License | ||
|
||
See [LICENSE](LICENSE) for the complete license. | ||
|
||
|
||
## Changelog | ||
|
||
A [changelog](ChangeLog.md) is available | ||
|
||
|
||
## Contact | ||
|
||
Nicolas Lamirault <[email protected]> | ||
|
||
[badge-license]: https://img.shields.io/badge/license-Apache2-green.svg?style=flat |
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,34 @@ | ||
|
||
global: | ||
scrape_interval: 15s # By default, scrape targets every 15 seconds. | ||
evaluation_interval: 15s # By default, scrape targets every 15 seconds. | ||
# scrape_timeout is set to the global default (10s). | ||
|
||
# Attach these labels to any time series or alerts when communicating with | ||
# external systems (federation, remote storage, Alertmanager). | ||
external_labels: | ||
monitor: 'speedtest-monitor' | ||
|
||
# Load and evaluate rules in this file every 'evaluation_interval' seconds. | ||
rule_files: | ||
# - "first.rules" | ||
# - "second.rules" | ||
|
||
# A scrape configuration containing exactly one endpoint to scrape: | ||
# Here it's Prometheus itself. | ||
scrape_configs: | ||
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. | ||
- job_name: 'prometheus' | ||
|
||
# Override the global default and scrape targets from this job every 5 seconds. | ||
scrape_interval: 5s | ||
|
||
# metrics_path defaults to '/metrics' | ||
# scheme defaults to 'http'. | ||
|
||
static_configs: | ||
- targets: ['localhost:9191'] | ||
|
||
- job_name: 'speedtest' | ||
target_groups: | ||
- targets: ['localhost:9111'] |
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,74 @@ | ||
// Copyright (C) 2016 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. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package speedtest | ||
|
||
import ( | ||
"github.com/prometheus/common/log" | ||
"github.com/zpeters/speedtest/sthttp" | ||
"github.com/zpeters/speedtest/tests" | ||
) | ||
|
||
// Client defines the Speedtest client | ||
type Client struct { | ||
Server sthttp.Server | ||
Config sthttp.Config | ||
AllServers []sthttp.Server | ||
ClosestServers []sthttp.Server | ||
} | ||
|
||
// NewClient defines a new client for Speedtest | ||
func NewClient(configURL string, serversURL string) (*Client, error) { | ||
log.Debugf("New Speedtest client") | ||
var testServer sthttp.Server | ||
|
||
log.Debugf("Retrieve Speedtest configuration from: %s", configURL) | ||
config, err := sthttp.GetConfig(configURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// sthttp.CONFIG = config | ||
|
||
log.Debugf("Retrieve all servers") | ||
var allServers []sthttp.Server | ||
allServers, err = sthttp.GetServers(serversURL, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Debugf("Retrieve closest servers") | ||
closestServers := sthttp.GetClosestServers(allServers, config.Lat, config.Lon) | ||
log.Debugf("Find test server") | ||
testServer = sthttp.GetFastestServer(closestServers) | ||
|
||
return &Client{ | ||
Server: testServer, | ||
Config: config, | ||
AllServers: allServers, | ||
ClosestServers: closestServers, | ||
}, nil | ||
} | ||
|
||
func (client *Client) NetworkMetrics() map[string]float64 { | ||
result := map[string]float64{} | ||
tester := tests.NewTester(tests.DefaultDLSizes, tests.DefaultULSizes, false, false) | ||
downloadMbps := tester.Download(client.Server) | ||
uploadMbps := tester.Upload(client.Server) | ||
ping := client.Server.Latency | ||
result["download"] = downloadMbps | ||
result["upload"] = uploadMbps | ||
result["ping"] = ping | ||
log.Debugf("Speedtest results: %s", result) | ||
return result | ||
} |
Oops, something went wrong.