Skip to content

Commit

Permalink
Export metrics for prometheus on localhost:9990/metrics
Browse files Browse the repository at this point in the history
Co-authored-by: Jose Luis Lucas <[email protected]>
  • Loading branch information
2 people authored and iknite committed Feb 19, 2019
1 parent 3b4f382 commit c74224e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type Config struct {
// Enables tampering endpoint.
EnableTampering bool

// Enables metrics endpoint.
EnableMetrics bool

// Enable TLS service
EnableTLS bool

Expand Down Expand Up @@ -92,6 +95,7 @@ func DefaultConfig() *Config {
RaftPath: currentDir + "/wal",
EnableProfiling: false,
EnableTampering: false,
EnableMetrics: true,
EnableTLS: false,
SSLCertificate: "",
SSLCertificateKey: "",
Expand Down
13 changes: 13 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/bbva/qed/sign"
"github.com/bbva/qed/storage/badger"
"github.com/bbva/qed/util"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// Server encapsulates the data and login to start/stop a QED server
Expand Down Expand Up @@ -164,6 +165,9 @@ func NewServer(conf *Config) (*Server, error) {
if conf.EnableProfiling {
server.profilingServer = newHTTPServer("localhost:6060", nil)
}
if conf.EnableMetrics {
http.Handle("/metrics", promhttp.Handler())
}

return server, nil
}
Expand Down Expand Up @@ -194,6 +198,15 @@ func (s *Server) Start() error {
return err
}

if s.conf.EnableMetrics {
go func() {
log.Debugf(" * Starting metrics HTTP server in addr: localhost:9990")
if err := http.ListenAndServe("localhost:9990", nil); err != http.ErrServerClosed {
log.Errorf("Can't start metrics HTTP server: %s", err)
}
}()
}

if s.profilingServer != nil {
go func() {
log.Debugf(" * Starting profiling HTTP server in addr: localhost:6060")
Expand Down

0 comments on commit c74224e

Please sign in to comment.