Skip to content

Commit

Permalink
basic prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
kikht authored and fujita committed Apr 1, 2023
1 parent 58d96f3 commit 41566d1
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 31 deletions.
17 changes: 16 additions & 1 deletion cmd/gobgpd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/coreos/go-systemd/v22/daemon"
"github.com/jessevdk/go-flags"
"github.com/kr/pretty"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -61,6 +63,7 @@ func main() {
Dry bool `short:"d" long:"dry-run" description:"check configuration"`
PProfHost string `long:"pprof-host" description:"specify the host that gobgpd listens on for pprof" default:"localhost:6060"`
PProfDisable bool `long:"pprof-disable" description:"disable pprof profiling"`
MetricsPath string `long:"metrics-path" description:"specify path for prometheus metrics" default:"/metrics"`
UseSdNotify bool `long:"sdnotify" description:"use sd_notify protocol"`
TLS bool `long:"tls" description:"enable TLS authentication for gRPC API"`
TLSCertFile string `long:"tls-cert-file" description:"The TLS cert file"`
Expand Down Expand Up @@ -88,7 +91,14 @@ func main() {
runtime.GOMAXPROCS(opts.CPUs)
}

metricRegistry := prometheus.NewRegistry()

if !opts.PProfDisable {
http.Handle(opts.MetricsPath, promhttp.InstrumentMetricHandler(
metricRegistry,
promhttp.HandlerFor(metricRegistry, promhttp.HandlerOpts{}),
))

go func() {
logger.Println(http.ListenAndServe(opts.PProfHost, nil))
}()
Expand Down Expand Up @@ -170,7 +180,12 @@ func main() {
}

logger.Info("gobgpd started")
bgpServer := server.NewBgpServer(server.GrpcListenAddress(opts.GrpcHosts), server.GrpcOption(grpcOpts), server.LoggerOption(&builtinLogger{logger: logger}))
bgpServer := server.NewBgpServer(
server.GrpcListenAddress(opts.GrpcHosts),
server.GrpcOption(grpcOpts),
server.LoggerOption(&builtinLogger{logger: logger}),
server.Metrics(metricRegistry),
)
go bgpServer.Serve()

if opts.UseSdNotify {
Expand Down
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ require (
github.com/go-test/deep v1.1.0
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/jessevdk/go-flags v1.5.0
github.com/k-sone/critbitgo v1.4.0
github.com/kr/pretty v0.3.1
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
Expand All @@ -24,6 +26,8 @@ require (
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand All @@ -32,10 +36,13 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -44,9 +51,7 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
google.golang.org/genproto v0.0.0-20230320184635-7606e756e683 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down

0 comments on commit 41566d1

Please sign in to comment.