commit inicial do projeto
This commit is contained in:
61
internal/monitoring/metrics.go
Normal file
61
internal/monitoring/metrics.go
Normal file
@ -0,0 +1,61 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
var (
|
||||
txCounter = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "dejo_tx_total",
|
||||
Help: "Total de transações recebidas pelo nó",
|
||||
},
|
||||
)
|
||||
|
||||
finalizedBlocks = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "dejo_finalized_blocks_total",
|
||||
Help: "Total de blocos finalizados pelo nó",
|
||||
},
|
||||
)
|
||||
|
||||
uptimeGauge = prometheus.NewGaugeFunc(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "dejo_uptime_seconds",
|
||||
Help: "Tempo desde que o nó foi iniciado",
|
||||
},
|
||||
func() float64 {
|
||||
return time.Since(startTime).Seconds()
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
var startTime = time.Now()
|
||||
|
||||
// Init inicializa o endpoint /metrics
|
||||
func Init() {
|
||||
prometheus.MustRegister(txCounter)
|
||||
prometheus.MustRegister(finalizedBlocks)
|
||||
prometheus.MustRegister(uptimeGauge)
|
||||
|
||||
go func() {
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
log.Println("📊 Endpoint de métricas disponível em /metrics")
|
||||
http.ListenAndServe(":9100", nil)
|
||||
}()
|
||||
}
|
||||
|
||||
// IncTxCount incrementa o total de transações recebidas
|
||||
func IncTxCount() {
|
||||
txCounter.Inc()
|
||||
}
|
||||
|
||||
// IncFinalizedBlocks incrementa o total de blocos finalizados
|
||||
func IncFinalizedBlocks() {
|
||||
finalizedBlocks.Inc()
|
||||
}
|
||||
Reference in New Issue
Block a user