Skip to content

Commit

Permalink
Merge pull request #12 from odenio/modit
Browse files Browse the repository at this point in the history
Break off main function to make module importable
  • Loading branch information
pengbo0328 authored Feb 7, 2022
2 parents b15dd39 + 299c942 commit fba2811
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 123 deletions.
5 changes: 4 additions & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ go:
version: 1.16
cgo: false
repository:
path: github.com/pengbo0328/pgpool2_exporter
path: github.com/pgpool/pgpool2_exporter
build:
binaries:
- name: pgpool2_exporter
path: ./cmd/pgpool2_exporter
flags: -a -tags 'netgo static_build'
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ crossbuild: promu
promu:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) get -u github.com/prometheus/promu
$(GO) install github.com/prometheus/promu

tarball: build
@echo ">> building release tarball"
Expand Down
54 changes: 54 additions & 0 deletions cmd/pgpool2_exporter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"fmt"
"net/http"
"os"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"

exp "github.com/pgpool/pgpool2_exporter"
)

func main() {
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("pgpool2_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()

exp.Logger = promlog.New(promlogConfig)

dsn := os.Getenv("DATA_SOURCE_NAME")
exporter := exp.NewExporter(dsn, exp.Namespace)
defer func() {
exporter.DB.Close()
}()
prometheus.MustRegister(exporter)

// Retrieve Pgpool-II version
v, err := exp.QueryVersion(exporter.DB)
if err != nil {
level.Error(exp.Logger).Log("err", err)
}
exp.PgpoolSemver = v

level.Info(exp.Logger).Log("msg", "Starting pgpool2_exporter", "version", version.Info(), "dsn", exp.MaskPassword(dsn))
level.Info(exp.Logger).Log("msg", "Listening on address", "address", *exp.ListenAddress)

http.Handle(*exp.MetricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf(exp.LandingPage, *exp.MetricsPath)))
})

if err := http.ListenAndServe(*exp.ListenAddress, nil); err != nil {
level.Error(exp.Logger).Log("err", err)
os.Exit(1)
}
}
37 changes: 28 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
module github.com/pengbo0328/pgpool2_exporter
module github.com/pgpool/pgpool2_exporter

go 1.14
go 1.17

require (
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/go-kit/log v0.1.0
github.com/go-kit/log v0.2.0
github.com/golang/protobuf v1.5.2 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/lib/pq v1.10.2
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.29.0
github.com/prometheus/procfs v0.7.0 // indirect
github.com/prometheus/client_golang v1.12.0
github.com/prometheus/common v0.32.1
github.com/prometheus/procfs v0.7.3 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-github/v25 v25.1.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/promu v0.13.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit fba2811

Please sign in to comment.