-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from odenio/modit
Break off main function to make module importable
- Loading branch information
Showing
6 changed files
with
178 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.