various issues fixing (#49)

* arm64 Dockerfile and Makefile update
* #46 version flag
This commit is contained in:
Steve Brunton 2019-09-02 14:51:14 -04:00 committed by GitHub
parent f1f09b42bb
commit 9bb5a0cee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 15 deletions

8
Dockerfile.arm64 Normal file
View File

@ -0,0 +1,8 @@
FROM arm64v8/busybox:1.31.0
EXPOSE 9090
COPY scripts/start.sh /app/
COPY dist/mikrotik-exporter_linux_arm64 /app/mikrotik-exporter
ENTRYPOINT ["/app/start.sh"]

View File

@ -3,8 +3,8 @@
VERSION=`cat VERSION` VERSION=`cat VERSION`
SHORTSHA=`git rev-parse --short HEAD` SHORTSHA=`git rev-parse --short HEAD`
LDFLAGS=-X github.com/nshttpd/mikrotik-exporter/cmd.version=$(VERSION) LDFLAGS=-X main.appVersion=$(VERSION)
LDFLAGS+=-X github.com/nshttpd/mikrotik-exporter/cmd.shortSha=$(SHORTSHA) LDFLAGS+=-X main.shortSha=$(SHORTSHA)
build: build:
go build -ldflags "$(LDFLAGS)" . go build -ldflags "$(LDFLAGS)" .
@ -21,3 +21,5 @@ dockerhub: deploy
@docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) @docker login -u $(DOCKER_USER) -p $(DOCKER_PASS)
docker build -t $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME):$(VERSION) . docker build -t $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME):$(VERSION) .
docker push $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME):$(VERSION) docker push $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME):$(VERSION)
docker build -f Dockerfile.arm64 -t $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME)-linux-arm64:$(VERSION) .
docker push $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME)-linux-arm64:$(VERSION)

36
main.go
View File

@ -6,6 +6,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/prometheus/common/version"
"fmt" "fmt"
"net/http" "net/http"
@ -13,21 +15,25 @@ import (
"github.com/nshttpd/mikrotik-exporter/config" "github.com/nshttpd/mikrotik-exporter/config"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// single device can be defined via CLI flags, mutliple via config file. // single device can be defined via CLI flags, multiple via config file.
var ( var (
device = flag.String("device", "", "single device to monitor")
address = flag.String("address", "", "address of the device to monitor") address = flag.String("address", "", "address of the device to monitor")
user = flag.String("user", "", "user for authentication with single device")
password = flag.String("password", "", "password for authentication for single device")
logLevel = flag.String("log-level", "info", "log level")
logFormat = flag.String("log-format", "json", "logformat text or json (default json)")
port = flag.String("port", ":9436", "port number to listen on")
metricsPath = flag.String("path", "/metrics", "path to answer requests on")
configFile = flag.String("config-file", "", "config file to load") configFile = flag.String("config-file", "", "config file to load")
device = flag.String("device", "", "single device to monitor")
insecure = flag.Bool("insecure", false, "skips verification of server certificate when using TLS (not recommended)")
logFormat = flag.String("log-format", "json", "logformat text or json (default json)")
logLevel = flag.String("log-level", "info", "log level")
metricsPath = flag.String("path", "/metrics", "path to answer requests on")
password = flag.String("password", "", "password for authentication for single device")
port = flag.String("port", ":9436", "port number to listen on")
timeout = flag.Duration("timeout", collector.DefaultTimeout, "timeout when connecting to devices")
tls = flag.Bool("tls", false, "use tls to connect to routers")
user = flag.String("user", "", "user for authentication with single device")
ver = flag.Bool("version", false, "find the version of binary")
withBgp = flag.Bool("with-bgp", false, "retrieves BGP routing infrormation") withBgp = flag.Bool("with-bgp", false, "retrieves BGP routing infrormation")
withRoutes = flag.Bool("with-routes", false, "retrieves routing table information") withRoutes = flag.Bool("with-routes", false, "retrieves routing table information")
withDHCP = flag.Bool("with-dhcp", false, "retrieves DHCP server metrics") withDHCP = flag.Bool("with-dhcp", false, "retrieves DHCP server metrics")
@ -37,10 +43,11 @@ var (
withWlanSTA = flag.Bool("with-wlansta", false, "retrieves connected wlan station metrics") withWlanSTA = flag.Bool("with-wlansta", false, "retrieves connected wlan station metrics")
withWlanIF = flag.Bool("with-wlanif", false, "retrieves wlan interface metrics") withWlanIF = flag.Bool("with-wlanif", false, "retrieves wlan interface metrics")
withMonitor = flag.Bool("with-monitor", false, "retrieves ethernet interface monitor info") withMonitor = flag.Bool("with-monitor", false, "retrieves ethernet interface monitor info")
timeout = flag.Duration("timeout", collector.DefaultTimeout, "timeout when connecting to devices")
tls = flag.Bool("tls", false, "use tls to connect to routers")
insecure = flag.Bool("insecure", false, "skips verification of server certificate when using TLS (not recommended)")
cfg *config.Config cfg *config.Config
appVersion = "DEVELOPMENT"
shortSha = "0xDEADBEEF"
) )
func init() { func init() {
@ -50,6 +57,11 @@ func init() {
func main() { func main() {
flag.Parse() flag.Parse()
if *ver {
fmt.Printf("\nVersion: %s\nShort SHA: %s\n\n", appVersion, shortSha)
os.Exit(0)
}
configureLog() configureLog()
c, err := loadConfig() c, err := loadConfig()

View File

@ -1,5 +1,9 @@
#!/bin/sh #!/bin/sh
if [ ! -x /app/mikrotik-exporter ]; then
chmod 755 /app/mikrotik-expoter
fi
if [ -z "$CONFIG_FILE" ] if [ -z "$CONFIG_FILE" ]
then then
/app/mikrotik-exporter -device $DEVICE -address $ADDRESS -user $USER -password $PASSWORD /app/mikrotik-exporter -device $DEVICE -address $ADDRESS -user $USER -password $PASSWORD