Skip to content

Commit

Permalink
Merge pull request #5 from peschmae/feature/merge-kully
Browse files Browse the repository at this point in the history
Feature/merge kully
  • Loading branch information
peschmae authored Aug 29, 2022
2 parents 857e50f + aa58484 commit 64d17d5
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 178 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: install stringer
run: go install golang.org/x/tools/cmd/stringer@latest

- name: Generate
run: go generate ./...

- name: Build
run: go build -v ./...

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mystrom-exporter
output/*
*_string.go

# Created by https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,intellij+all,windows
Expand Down Expand Up @@ -148,4 +149,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows
# End of https://www.toptal.com/developers/gitignore/api/osx,intellij+all,windows
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:alpine as build

WORKDIR /root
COPY . /root
RUN go build .
RUN go install golang.org/x/tools/cmd/stringer@latest && go generate ./... && go build .

FROM alpine:latest

Expand Down
63 changes: 53 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
.PHONY: clean run
##
#
.DEFAULT_GOAL := help
.PHONY: generate go-tools

linux:
GOOS=linux GOARCH=amd64 go build -o output/mystrom-exporter_linux-amd64
mac:
GOOS=darwin GOARCH=amd64 go build -o output/mystrom-exporter_mac-amd64
arm64:
GOOS=linux GOARCH=arm64 go build -o output/mystrom-exporter_linux-arm64
arm:
GOOS=linux GOARCH=arm go build -o output/mystrom-exporter_linux-arm
version := $(shell git describe --tags --always)
revision := $(shell git rev-parse HEAD)
branch := $(shell git rev-parse --abbrev-ref HEAD)
builduser := $(shell whoami)
builddate := $(shell date '+%FT%T_%Z')

versionPkgPrefix := mystrom-exporter/pkg/version

all: linux mac arm64 arm
BINDIR := $(CURDIR)/output
GO ?= go
GOPATH ?= $(shell $(GO) env GOPATH)
LDFLAGS := -w -s \
-X $(versionPkgPrefix).Version=${version} \
-X $(versionPkgPrefix).Revision=${revision} \
-X $(versionPkgPrefix).Branch=${branch} \
-X $(versionPkgPrefix).BuildUser=${builduser} \
-X $(versionPkgPrefix).BuildDate=${builddate}
GOFLAGS := -v
GOX_FLAGS := -mod=vendor
GO_BUILD_FLAGS := -v
export GO111MODULE := on

build: go-tools generate ## builds the all platform binaries of the exporter
$(GOPATH)/bin/gox \
-os="darwin linux" \
-arch="amd64 arm arm64" \
-osarch="!darwin/arm" \
-output "${BINDIR}/{{.Dir}}-{{.OS}}-{{.Arch}}" \
-gcflags "$(GO_BUILD_FLAGS)" \
-ldflags '$(LDFLAGS)' \
-tags '$(TAGS)' \
./...

run:
${BINDIR}/mystrom-exporter-$(shell $(GO) env GOOS)-$(shell $(GO) env GOARCH)


generate: go-tools
$(GO) generate ./...

go-tools: $(GOPATH)/bin/stringer $(GOPATH)/bin/gox

# -- see more info on https://pkg.go.dev/golang.org/x/tools/cmd/stringer
$(GOPATH)/bin/stringer:
$(GO) install golang.org/x/tools/cmd/stringer@latest

$(GOPATH)/bin/gox:
$(GO) install github.com/mitchellh/gox@latest
# --
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,31 @@ $ ./mystrom-exporter --help
```
| Flag | Description | Default |
| ---- | ----------- | ------- |
| switch.ip-address | IP address of the switch you try to monitor | `` |
| web.listen-address | Address to listen on | `:9452` |
| web.metrics-path | Path under which to expose metrics | `/metrics` |
| web.metrics-path | Path under which to expose exporters own metrics | `/metrics` |
| web.device-path | Path under which the metrics of the devices are fetched | `/device` |

## Prometheus configuration
A enhancement has been made to have only one exporter which can scrape multiple devices. This is configured in
Prometheus as follows assuming we have 4 mystrom devices and the exporter is running locally on the smae machine as
the Prometheus.
```yaml
- job_name: mystrom
scrape_interval: 30s
metrics_path: /device
honor_labels: true
static_configs:
- targets:
- '192.168.105.11'
- '192.168.105.12'
- '192.168.105.13'
- '192.168.105.14'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 127.0.0.1:9452
```
## Supported architectures
Using the make file, you can easily build for the following architectures, those can also be considered the tested ones:
Expand All @@ -40,6 +62,7 @@ Using the make file, you can easily build for the following architectures, those
| Linux | arm64 |
| Linux | arm |
| Mac | amd64 |
| Mac | arm64 |
Since go is cross compatible with windows, and mac arm as well, you should be able to build the binary for those as well, but they aren't tested.
The docker image is only built & tested for amd64.
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ module mystrom-exporter

go 1.15

require github.com/prometheus/client_golang v1.10.0
require (
github.com/gorilla/mux v1.7.3
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.18.0
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
golang.org/x/tools v0.1.12
)
Loading

0 comments on commit 64d17d5

Please sign in to comment.