Skip to content
Snippets Groups Projects
Commit 87af26e8 authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

#12 expose prometheus metrics endpoint

parent 739e47e5
No related branches found
No related tags found
1 merge request!11Expose prometheus metrics
Pipeline #52537 failed with stages
in 1 minute and 8 seconds
Showing
with 100 additions and 2 deletions
......@@ -3,12 +3,14 @@ package main
import (
"context"
"errors"
"fmt"
"log"
"net"
"net/http"
"time"
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
......@@ -151,6 +153,9 @@ func main() {
goahealthsrv.Mount(mux, healthServer)
goaopenapisrv.Mount(mux, openapiServer)
// expose metrics
go exposeMetrics(cfg.Metrics.Addr, logger)
var handler http.Handler = mux
srv := &http.Server{
Addr: cfg.HTTP.Host + ":" + cfg.HTTP.Port,
......@@ -211,3 +216,12 @@ func httpClient() *http.Client {
Timeout: 30 * time.Second,
}
}
func exposeMetrics(addr string, logger *zap.Logger) {
promMux := http.NewServeMux()
promMux.Handle("/metrics", promhttp.Handler())
logger.Info(fmt.Sprintf("exposing prometheus metrics at %s/metrics", addr))
if err := http.ListenAndServe(addr, promMux); err != nil {
logger.Error("error exposing prometheus metrics", zap.Error(err))
}
}
......@@ -8,6 +8,7 @@ require (
github.com/hyperledger/aries-framework-go v0.1.8
github.com/kelseyhightower/envconfig v1.4.0
github.com/piprate/json-gold v0.4.1
github.com/prometheus/client_golang v1.12.2
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693
github.com/stretchr/testify v1.7.1
go.mongodb.org/mongo-driver v1.9.1
......@@ -18,9 +19,10 @@ require (
require (
github.com/VictoriaMetrics/fastcache v1.5.7 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
github.com/dimfeld/httptreemux/v5 v5.4.0 // indirect
......@@ -37,6 +39,7 @@ require (
github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/minio/sha256-simd v0.1.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
......@@ -48,6 +51,9 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/smartystreets/assertions v1.13.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
......
This diff is collapsed.
......@@ -9,6 +9,7 @@ type Config struct {
Cache cacheConfig
Credential credentialConfig
Signer signerConfig
Metrics metricsConfig
LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"`
}
......@@ -44,3 +45,7 @@ type cacheConfig struct {
type signerConfig struct {
Addr string `envconfig:"SIGNER_ADDR" required:"true"`
}
type metricsConfig struct {
Addr string `envconfig:"METRICS_ADDR" default:":2112"`
}
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment