Skip to content

Commit

Permalink
initial makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
schweikert committed Jun 30, 2019
1 parent 9312795 commit 734287d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VERSION = 0.1

build:
gox -os="linux darwin windows" -arch="amd64" -verbose \
-ldflags "-X main.buildCommit=`git rev-parse --short HEAD` \
-X main.buildDate=`date +%Y-%m-%d` \
-X main.buildVersion=$(VERSION)" \
./...

before_build:
go get github.com/mitchellh/gox

lint:
golangci-lint run *.go
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f // indirect
github.com/mitchellh/gox v1.0.1 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmg
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.2/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
Expand Down Expand Up @@ -245,6 +247,10 @@ github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down
24 changes: 18 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"net/http"
"os"
Expand All @@ -11,17 +12,24 @@ import (
)

var opts struct {
Listen string `short:"l" long:"listen" description:"Listen address" value-name:"[HOST]:PORT" default:":8080"`
Period uint `short:"p" long:"period" description:"Period in seconds, should match Prometheus scrape interval" value-name:"SECS" default:"60"`
Fping string `short:"f" long:"fping" description:"Fping binary path" value-name:"PATH" default:"/usr/bin/fping"`
Count uint `short:"c" long:"count" description:"Number of pings to send at each period" value-name:"N" default:"20"`
Listen string `short:"l" long:"listen" description:"Listen address" value-name:"[HOST]:PORT" default:":8080"`
Period uint `short:"p" long:"period" description:"Period in seconds, should match Prometheus scrape interval" value-name:"SECS" default:"60"`
Fping string `short:"f" long:"fping" description:"Fping binary path" value-name:"PATH" default:"/usr/bin/fping"`
Count uint `short:"c" long:"count" description:"Number of pings to send at each period" value-name:"N" default:"20"`
Version bool `long:"version" description:"Show version"`
}

var (
buildVersion = "dev"
buildCommit = "none"
buildDate = "unknown"
)

func probeHandler(w http.ResponseWriter, r *http.Request) {
targetParam := r.URL.Query().Get("target")
if targetParam == "" {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(`<html>
_, _ = w.Write([]byte(`<html>
<head><title>Fping Exporter</title></head>
<body>
<b>ERROR: missing target parameter</b>
Expand All @@ -31,7 +39,7 @@ func probeHandler(w http.ResponseWriter, r *http.Request) {

target := GetTarget(
WorkerSpec{
period: time.Second * 60,
period: time.Second * time.Duration(opts.Period),
},
TargetSpec{
host: targetParam,
Expand All @@ -46,6 +54,10 @@ func main() {
if _, err := flags.Parse(&opts); err != nil {
os.Exit(0)
}
if opts.Version {
fmt.Printf("fping-exporter %v (commit %v, built %v)\n", buildVersion, buildCommit, buildDate)
os.Exit(0)
}
http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/probe", probeHandler)
log.Fatal(http.ListenAndServe(opts.Listen, nil))
Expand Down

0 comments on commit 734287d

Please sign in to comment.