Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit 8a4730d

Browse files
committed
feat: GitHub Workflow for binaries and container images
Build binaries for all platforms and container manifest images. Upload binaries to tagged releases. Push container images to ghcr.io.
1 parent e1b06c6 commit 8a4730d

File tree

15 files changed

+206
-223
lines changed

15 files changed

+206
-223
lines changed

.github/workflows/release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
release:
16+
name: Release binaries and container images
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: actions/setup-go@v5
23+
with:
24+
go-version-file: go.mod
25+
26+
- uses: ko-build/[email protected]
27+
28+
- name: Build
29+
env:
30+
VERSION: ${{ github.ref_name }}
31+
TAGS: ${{ github.ref_name }},${{ github.sha }},latest
32+
shell: bash
33+
run: |
34+
./build.sh "$VERSION"
35+
export KO_DOCKER_REPO="ghcr.io/${GITHUB_REPOSITORY}"
36+
ko build --bare --platform=all --tags=$TAGS .
37+
38+
- uses: actions/upload-artifact@v3
39+
with:
40+
name: mikrotik-exporter
41+
path: |
42+
bin/*
43+
44+
- uses: softprops/action-gh-release@v1
45+
with:
46+
append_body: true
47+
generate_release_notes: true
48+
files: |
49+
bin/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.dll
44
*.so
55
*.dylib
6+
bin/
67

78
# Test binary, build with `go test -c`
89
*.test

Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

Dockerfile.arm64

Lines changed: 0 additions & 8 deletions
This file was deleted.

Dockerfile.armhf

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
[![Docker Pulls](https://img.shields.io/docker/pulls/nshttpd/mikrotik-exporter.svg)](https://hub.docker.com/r/nshttpd/mikrotik-exporter/)
2-
3-
## prometheus-mikrotik
1+
# prometheus-mikrotik
42

53
tl;dr - prometheus exporter for mikrotik devices
64

7-
This is still a work in progress .. consider `master` at the moment as a preview
8-
release.
9-
10-
#### Description
5+
## Description
116

127
A Prometheus Exporter for Mikrotik devices. Can be configured to collect metrics
138
from a single device or multiple devices. Single device monitoring can be configured
@@ -17,7 +12,7 @@ be required that has read-only access to the device configuration via the API.
1712
Currently the exporter collects metrics for interfaces and system resources. Others
1813
can be added as long as published via the API.
1914

20-
#### Mikrotik Config
15+
## Mikrotik Config
2116

2217
Create a user on the device that has API and read-only access.
2318

@@ -31,7 +26,7 @@ Create the user to access the API via.
3126

3227
`/user add name=prometheus group=prometheus password=changeme`
3328

34-
#### Single Device
29+
## Single Device
3530

3631
`./mikrotik-exporter -address 10.10.0.1 -device my_router -password changeme -user prometheus`
3732

@@ -41,19 +36,20 @@ created for the exporter to use to access the API.
4136

4237
User and password flags can be set with the `MIKROTIK_USER` and `MIKROTIK_PASSWORD` environment variables, respectively.
4338

44-
```
39+
```console
4540
MIKROTIK_USER=prometheus
4641
MIKROTIK_PASSWORD=changeme
4742
./mikrotik-exporter -address 10.10.0.1 -device my_router
4843
```
4944

50-
#### Config File
45+
## Config File
5146

5247
`./mikrotik-exporter -config-file config.yml`
5348

5449
where `config-file` is the path to a config file in YAML format.
5550

56-
###### example config
51+
### example config
52+
5753
```yaml
5854
devices:
5955
- name: my_router
@@ -93,10 +89,9 @@ If you add a devices with the `srv` parameter instead of `address` the exporter
9389
to obtain the SRV record and discover the devices dynamically. Also, you can specify a DNS server to use
9490
on the query.
9591

92+
## example output
9693

97-
###### example output
98-
99-
```
94+
```console
10095
mikrotik_interface_tx_byte{address="10.10.0.1",interface="ether2",name="my_router"} 1.4189902583e+10
10196
mikrotik_interface_tx_byte{address="10.10.0.1",interface="ether3",name="my_router"} 2.263768666e+09
10297
mikrotik_interface_tx_byte{address="10.10.0.1",interface="ether4",name="my_router"} 1.6572299e+08
@@ -105,5 +100,3 @@ mikrotik_interface_tx_byte{address="10.10.0.1",interface="ether6",name="my_route
105100
mikrotik_interface_tx_byte{address="10.10.0.1",interface="ether7",name="my_router"} 3.18354425e+08
106101
mikrotik_interface_tx_byte{address="10.10.0.1",interface="ether8",name="my_router"} 1.86405031e+08
107102
```
108-
109-

build.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
#
3+
# $1 - The version number to use for the build. If not provided, the current git
4+
# commit hash will be used.
5+
#
6+
7+
set -euo pipefail
8+
9+
app="$(basename "$PWD")"
10+
11+
version="${1:-$(git rev-parse --short HEAD)}"
12+
13+
rm -rf bin
14+
mkdir -p bin
15+
pushd bin
16+
trap popd EXIT
17+
18+
gobuild() {
19+
mkdir -p "$1/$2"
20+
pushd "$1/$2"
21+
env GOOS="$1" GOARCH="$2" go build ../../../.
22+
case "$1" in
23+
"windows")
24+
zip ../../"${app}_${1}_${2}_${version}".zip ./*.exe
25+
;;
26+
"linux")
27+
tar -c --zstd --numeric-owner \
28+
-f ../../"${app}_${1}_${2}_${version}".tar.zst .
29+
;;
30+
*)
31+
tar -c --numeric-owner \
32+
-f ../../"${app}_${1}_${2}_${version}".tar.bz2 .
33+
;;
34+
esac
35+
rm ./*
36+
popd
37+
rmdir "${1:?}/${2:?}" "${1:?}"
38+
}
39+
40+
export CGO_ENABLED=0
41+
42+
# Binaries for all platforms
43+
gobuild linux amd64
44+
gobuild linux arm64
45+
gobuild darwin amd64
46+
gobuild darwin arm64
47+
gobuild windows amd64
48+
49+
sha1sum ./*.tar.* ./*.zip >sha1sums.txt

config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package config
22

33
import (
44
"io"
5-
"io/ioutil"
65

76
yaml "gopkg.in/yaml.v2"
87
)
@@ -54,7 +53,7 @@ type DnsServer struct {
5453

5554
// Load reads YAML from reader and unmashals in Config
5655
func Load(r io.Reader) (*Config, error) {
57-
b, err := ioutil.ReadAll(r)
56+
b, err := io.ReadAll(r)
5857
if err != nil {
5958
return nil, err
6059
}

config/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package config
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"os"
66
"testing"
77
)
88

@@ -34,7 +34,7 @@ func TestShouldParse(t *testing.T) {
3434
}
3535

3636
func loadTestFile(t *testing.T) []byte {
37-
b, err := ioutil.ReadFile("config.test.yml")
37+
b, err := os.ReadFile("config.test.yml")
3838
if err != nil {
3939
t.Fatalf("could not load config: %v", err)
4040
}

go.mod

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
module mikrotik-exporter
22

3-
go 1.13
3+
go 1.22.4
44

55
require (
6-
github.com/miekg/dns v1.1.43
7-
github.com/prometheus/client_golang v1.4.1
8-
github.com/prometheus/common v0.9.1
9-
github.com/sirupsen/logrus v1.8.1
10-
github.com/stretchr/testify v1.4.0
11-
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
12-
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
6+
github.com/miekg/dns v1.1.61
7+
github.com/prometheus/client_golang v1.19.1
8+
github.com/prometheus/common v0.54.0
9+
github.com/sirupsen/logrus v1.9.3
10+
github.com/stretchr/testify v1.8.2
1311
gopkg.in/routeros.v2 v2.0.0-20190905230420-1bbf141cdd91
1412
gopkg.in/yaml.v2 v2.4.0
1513
)
14+
15+
require (
16+
github.com/beorn7/perks v1.0.1 // indirect
17+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
18+
github.com/davecgh/go-spew v1.1.1 // indirect
19+
github.com/kr/text v0.2.0 // indirect
20+
github.com/pmezard/go-difflib v1.0.0 // indirect
21+
github.com/prometheus/client_model v0.6.1 // indirect
22+
github.com/prometheus/procfs v0.15.1 // indirect
23+
golang.org/x/mod v0.18.0 // indirect
24+
golang.org/x/net v0.26.0 // indirect
25+
golang.org/x/sync v0.7.0 // indirect
26+
golang.org/x/sys v0.21.0 // indirect
27+
golang.org/x/tools v0.22.0 // indirect
28+
google.golang.org/protobuf v1.34.2 // indirect
29+
gopkg.in/yaml.v3 v3.0.1 // indirect
30+
)

0 commit comments

Comments
 (0)