Skip to content
Snippets Groups Projects
Unverified Commit 664da235 authored by capossele's avatar capossele
Browse files

:chart_with_upwards_trend: Add a bunch of metrics to prometheus

parent d79c595e
No related branches found
No related tags found
No related merge requests found
......@@ -8,24 +8,19 @@ import (
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/database"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/syncutils"
"go.uber.org/atomic"
)
var (
_dbSize uint64
dbSizeLock syncutils.RWMutex
dbSize atomic.Uint64
onDBSize = events.NewClosure(func(dbSize uint64) {
dbSizeLock.Lock()
defer dbSizeLock.Unlock()
_dbSize = dbSize
onDBSize = events.NewClosure(func(size uint64) {
dbSize.Store(size)
})
)
func DBSize() uint64 {
dbSizeLock.RLock()
defer dbSizeLock.RUnlock()
return _dbSize
return dbSize.Load()
}
func colectDBSize() {
......
......@@ -13,6 +13,8 @@ var (
previousNeighbors = make(map[identity.ID]gossipTrafficMetric)
gossipOldTx uint32
gossipOldRx uint32
gossipCurrentTx atomic.Uint64
gossipCurrentRx atomic.Uint64
analysisOutboundBytes atomic.Uint64
)
......@@ -25,6 +27,14 @@ func FPCOutboundBytes() uint64 {
return _FPCOutboundBytes.Load()
}
func GossipInboundBytes() uint64 {
return gossipCurrentRx.Load()
}
func GossipOutboundBytes() uint64 {
return gossipCurrentTx.Load()
}
func AnalysisOutboundBytes() uint64 {
return analysisOutboundBytes.Load()
}
......
......@@ -49,9 +49,7 @@ func configure(_ *node.Plugin) {
memUsageBytes.Store(memAllocBytes)
}))
metrics.Events().Synced.Attach(events.NewClosure(func(synced bool) {
syncLock.Lock()
defer syncLock.Unlock()
isSynced = synced
isSynced.Store(synced)
}))
metrics.Events().DBSize.Attach(onDBSize)
......@@ -70,6 +68,12 @@ func run(_ *node.Plugin) {
measureCPUUsage()
measureMemUsage()
measureSynced()
// gossip network traffic
g := gossipCurrentTraffic()
gossipCurrentRx.Store(uint64(g.BytesRead))
gossipCurrentTx.Store(uint64(g.BytesWritten))
}, 1*time.Second, shutdownSignal)
}, shutdown.PriorityMetrics); err != nil {
log.Panicf("Failed to start as daemon: %s", err)
......
......@@ -3,12 +3,11 @@ package metrics
import (
"github.com/iotaledger/goshimmer/packages/metrics"
"github.com/iotaledger/goshimmer/plugins/sync"
"github.com/iotaledger/hive.go/syncutils"
"go.uber.org/atomic"
)
var (
isSynced bool
syncLock syncutils.RWMutex
isSynced atomic.Bool
)
func measureSynced() {
......@@ -18,7 +17,5 @@ func measureSynced() {
// Synced returns if the node is synced.
func Synced() bool {
syncLock.RLock()
defer syncLock.RUnlock()
return isSynced
return isSynced.Load()
}
package metrics
import (
"sync/atomic"
"go.uber.org/atomic"
)
// ReceivedMessagesPerSecond retrieves the current messages per second number.
func ReceivedMessagesPerSecond() uint64 {
return atomic.LoadUint64(&measuredReceivedMPS)
return measuredReceivedMPS.Load()
}
// counter for the received MPS
var mpsReceivedSinceLastMeasurement uint64
var mpsReceivedSinceLastMeasurement atomic.Uint64
// measured value of the received MPS
var measuredReceivedMPS uint64
var measuredReceivedMPS atomic.Uint64
// increases the received MPS counter
func increaseReceivedMPSCounter() {
atomic.AddUint64(&mpsReceivedSinceLastMeasurement, 1)
mpsReceivedSinceLastMeasurement.Add(1)
}
// measures the received MPS value
func measureReceivedMPS() {
// sample the current counter value into a measured MPS value
sampledMPS := atomic.LoadUint64(&mpsReceivedSinceLastMeasurement)
sampledMPS := mpsReceivedSinceLastMeasurement.Load()
// store the measured value
atomic.StoreUint64(&measuredReceivedMPS, sampledMPS)
measuredReceivedMPS.Store(sampledMPS)
// reset the counter
atomic.StoreUint64(&mpsReceivedSinceLastMeasurement, 0)
mpsReceivedSinceLastMeasurement.Store(0)
// trigger events for outside listeners
Events.ReceivedMPSUpdated.Trigger(sampledMPS)
......
package prometheus
import (
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
neighborDropCount prometheus.Gauge
avgNeighborConnectionLifeTime prometheus.Gauge
connectionsCount prometheus.Gauge
minDistance prometheus.Gauge
maxDistance prometheus.Gauge
avgDistance prometheus.Gauge
)
func init() {
neighborDropCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "neighbor_drop_count",
Help: "Autopeering neighbor drop count.",
})
avgNeighborConnectionLifeTime = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "avg_neighbor_connection_lifetime",
Help: "Autopeering avgerage neighbor connection lifetime.",
})
connectionsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "neighbor_connections_count",
Help: "Autopeering neighbor connections count.",
})
minDistance = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "min_distance",
Help: "Autopeering minimum distance with all neighbors.",
})
maxDistance = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "max_distance",
Help: "Autopeering maximum distance with all neighbors.",
})
avgDistance = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "avg_distance",
Help: "Autopeering average distance with all neighbors.",
})
registry.MustRegister(neighborDropCount)
registry.MustRegister(avgNeighborConnectionLifeTime)
registry.MustRegister(connectionsCount)
registry.MustRegister(minDistance)
registry.MustRegister(maxDistance)
registry.MustRegister(avgDistance)
addCollect(collectAutopeeringMetrics)
}
func collectAutopeeringMetrics() {
neighborDropCount.Set(float64(metrics.NeighborDropCount()))
avgNeighborConnectionLifeTime.Set(metrics.AvgNeighborConnectionLifeTime())
connectionsCount.Set(float64(metrics.ConnectionsCount()))
min, max, avg := metrics.AutopeeringDistanceStats()
minDistance.Set(float64(min))
minDistance.Set(float64(max))
minDistance.Set(avg)
}
......@@ -2,11 +2,13 @@ package prometheus
import (
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
infoApp *prometheus.GaugeVec
sync prometheus.Gauge
)
func init() {
......@@ -18,4 +20,20 @@ func init() {
[]string{"name", "version"},
)
infoApp.WithLabelValues(banner.AppName, banner.AppVersion).Set(1)
sync = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "sync",
Help: "Node sync status.",
})
addCollect(collectInfoMetrics)
}
func collectInfoMetrics() {
sync.Set(func() float64 {
if metrics.Synced() {
return 1.0
}
return 0.
}())
}
package prometheus
import (
"github.com/iotaledger/goshimmer/plugins/autopeering"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
messagesPerSecond prometheus.Gauge
fpcInboundBytes prometheus.Gauge
fpcOutboundBytes prometheus.Gauge
analysisOutboundBytes prometheus.Gauge
autopeeringInboundBytes prometheus.Gauge
autopeeringOutboundBytes prometheus.Gauge
messagesPerSecond prometheus.Gauge
)
func init() {
......@@ -21,43 +15,11 @@ func init() {
Help: "Number of messages per second.",
})
// Network
fpcInboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "FPC_inbound_bytes",
Help: "FPC RX network traffic [bytes].",
})
fpcOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "fpc_outbound_bytes",
Help: "FPC TX network traffic [bytes].",
})
autopeeringInboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "autopeering_inbound_bytes",
Help: "autopeering RX network traffic [bytes].",
})
autopeeringOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "autopeering_outbound_bytes",
Help: "autopeering TX network traffic [bytes].",
})
analysisOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "analysis_outbound_bytes",
Help: "Analysis client TX network traffic [bytes].",
})
registry.MustRegister(messagesPerSecond)
registry.MustRegister(fpcInboundBytes)
registry.MustRegister(fpcOutboundBytes)
registry.MustRegister(analysisOutboundBytes)
registry.MustRegister(autopeeringInboundBytes)
registry.MustRegister(autopeeringOutboundBytes)
addCollect(collectLocalMetrics)
}
func collectLocalMetrics() {
messagesPerSecond.Set(float64(metrics.ReceivedMessagesPerSecond()))
fpcInboundBytes.Set(float64(metrics.FPCInboundBytes()))
fpcOutboundBytes.Set(float64(metrics.FPCOutboundBytes()))
analysisOutboundBytes.Set(float64(metrics.AnalysisOutboundBytes()))
autopeeringInboundBytes.Set(float64(autopeering.Conn.RXBytes()))
autopeeringOutboundBytes.Set(float64(autopeering.Conn.TXBytes()))
}
package prometheus
import (
"github.com/iotaledger/goshimmer/plugins/autopeering"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
fpcInboundBytes prometheus.Gauge
fpcOutboundBytes prometheus.Gauge
analysisOutboundBytes prometheus.Gauge
gossipInboundBytes prometheus.Gauge
gossipOutboundBytes prometheus.Gauge
autopeeringInboundBytes prometheus.Gauge
autopeeringOutboundBytes prometheus.Gauge
)
func init() {
fpcInboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "fpc_inbound_bytes",
Help: "FPC RX network traffic [bytes].",
})
fpcOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "fpc_outbound_bytes",
Help: "FPC TX network traffic [bytes].",
})
autopeeringInboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "autopeering_inbound_bytes",
Help: "autopeering RX network traffic [bytes].",
})
autopeeringOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "autopeering_outbound_bytes",
Help: "autopeering TX network traffic [bytes].",
})
gossipInboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gossip_inbound_bytes",
Help: "gossip RX network traffic [bytes].",
})
gossipOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gossip_outbound_bytes",
Help: "gossip TX network traffic [bytes].",
})
analysisOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "analysis_outbound_bytes",
Help: "Analysis client TX network traffic [bytes].",
})
registry.MustRegister(fpcInboundBytes)
registry.MustRegister(fpcOutboundBytes)
registry.MustRegister(analysisOutboundBytes)
registry.MustRegister(autopeeringInboundBytes)
registry.MustRegister(autopeeringOutboundBytes)
registry.MustRegister(gossipInboundBytes)
registry.MustRegister(gossipOutboundBytes)
addCollect(collectNetworkMetrics)
}
func collectNetworkMetrics() {
fpcInboundBytes.Set(float64(metrics.FPCInboundBytes()))
fpcOutboundBytes.Set(float64(metrics.FPCOutboundBytes()))
analysisOutboundBytes.Set(float64(metrics.AnalysisOutboundBytes()))
autopeeringInboundBytes.Set(float64(autopeering.Conn.RXBytes()))
autopeeringOutboundBytes.Set(float64(autopeering.Conn.TXBytes()))
gossipInboundBytes.Set(float64(metrics.GossipInboundBytes()))
gossipOutboundBytes.Set(float64(metrics.GossipOutboundBytes()))
}
package prometheus
import (
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
cpuUsage prometheus.Gauge
memUsageBytes prometheus.Gauge
)
func init() {
cpuUsage = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "cpu_usage",
Help: "CPU (System) usage.",
})
memUsageBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "mem_usage_bytes",
Help: "memory usage [bytes].",
})
registry.MustRegister(cpuUsage)
registry.MustRegister(memUsageBytes)
addCollect(collectProcesskMetrics)
}
func collectProcesskMetrics() {
cpuUsage.Set(float64(metrics.CpuUsage()))
memUsageBytes.Set(float64(metrics.MemUsage()))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment