Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
add more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
okedeji committed Jul 4, 2024
1 parent 8a91f12 commit c782f27
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cmd/node/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/allora-network/b7s/api"
"github.com/allora-network/b7s/models/blockless"
Expand Down Expand Up @@ -110,6 +111,10 @@ func createExecutor(a api.API) func(ctx echo.Context) error {
res.Message = err.Error()
}

// record metics
headRequestEveryHour.Observe(float64(time.Now().Hour()))
headRequests.Inc()

// Send the response.
return ctx.JSON(http.StatusOK, res)
}
Expand Down
33 changes: 30 additions & 3 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,37 @@ const (

var (
opsProcessed = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_node_operations",
Name: "allora_node_total_operations",
Help: "The total number of processed operations",
})

headRequests = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_head_node_total_requests",
Help: "The total number of request made by head node",
})

headRequestEveryHour = prometheus.NewHistogram(
prometheus.HistogramOpts{
Name: "allora_head_node_request_every_hour",
Help: "The number of requests made by head node every hour",
Buckets: prometheus.LinearBuckets(0, 3600, 24), // 24 buckets, one for each hour
},
)

workerLatestInference = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "allora_worker_node_latest_inference_value",
Help: "The latest inference value from the worker node",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
)
)

func init() {
prometheus.MustRegister(opsProcessed)
prometheus.MustRegister(headRequests)
prometheus.MustRegister(headRequestEveryHour)
prometheus.MustRegister(workerLatestInference)
}

func main() {
Expand Down Expand Up @@ -160,6 +184,8 @@ func (e *AlloraExecutor) ExecuteFunction(requestID string, req execute.Request)
// Build inference if existent
if responseValue.InfererValue != "" {
infererValue := alloraMath.MustNewDecFromString(responseValue.InfererValue)
// record inferer value as summary
workerLatestInference.Observe(infererValue.SdkLegacyDec().MustFloat64())
inference := &types.Inference{
TopicId: topicId,
Inferer: e.appChain.Address,
Expand Down Expand Up @@ -424,6 +450,7 @@ func (e *AlloraExecutor) ExecuteFunction(requestID string, req execute.Request)
}
}

// increament the number of operations processed by worker or reputer
opsProcessed.Inc()
return result, err
}
Expand Down Expand Up @@ -668,10 +695,10 @@ func run() int {
go func() {
log.Info().Str("role", role.String()).Msg("Starting metrics server on :2112")
if err := http.ListenAndServe(":2112", nil); err != nil {
log.Error().Err(err).Msg("could not start metric server")
log.Error().Err(err).Msg("Could not start metric server")
}

log.Info().Msg("Allora Node stopped")
log.Info().Msg("Metrics server stopped")
}()

// If we're a head node - start the REST API.
Expand Down

0 comments on commit c782f27

Please sign in to comment.