Skip to content

Commit

Permalink
Merge pull request #1 from eumel8/feat/metrics
Browse files Browse the repository at this point in the history
WIP: init prometheus
  • Loading branch information
y-eight authored Mar 27, 2023
2 parents 2e20db0 + 1a0350a commit 41d3a4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
connect "github.com/bufbuild/connect-go"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/telekom/canary-bot/data"
h "github.com/telekom/canary-bot/helper"
"github.com/telekom/canary-bot/proto/api/third_party"
Expand Down Expand Up @@ -133,6 +134,7 @@ func StartApi(data data.Database, config *Configuration, log *zap.SugaredLogger)

mux.Handle(apiv1connect.NewApiServiceHandler(a, interceptors))
mux.Handle("/api/v1/", gwmux)
mux.Handle("/metrics", promhttp.Handler())
server := &http.Server{
Addr: addr,
Handler: h2c.NewHandler(mux, &http2.Server{}),
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

const (
envPrefix = "MESH"
)

// prometheus metrics for nodes and samples and cluster

var (
nodecounts = promauto.NewGauge(prometheus.GaugeOpts{
Name: "mesh_nodes",
Help: "The total number of nodes",
})
samplecounts = promauto.NewGauge(prometheus.GaugeOpts{
Name: "mesh_samples",
Help: "The total number of samples",
})
)

var cmd = &cobra.Command{
Use: "cbot",
Short: "Canary Bot collecting & distributing sample data in a mesh",
Expand Down
2 changes: 2 additions & 0 deletions mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func CreateCanaryMesh(routineConfig *RoutineConfiguration, setupConfig *SetupCon
CaCert: setupConfig.CaCert,
}

// init prometheus metrics to fetch data from database

// start the mesh API
if err = api.StartApi(database, apiConfig, logger.Named("api")); err != nil {
logger.Fatal("Could not start API - Error: %+v", err)
Expand Down

0 comments on commit 41d3a4c

Please sign in to comment.