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

:chart_with_upwards_trend: Add autopeering network traffic metric

parent db366947
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,8 @@ var ( ...@@ -35,6 +35,8 @@ var (
// NetworkID specifies the autopeering network identifier // NetworkID specifies the autopeering network identifier
NetworkID = hash32([]byte(banner.AppVersion + NetworkVersion)) NetworkID = hash32([]byte(banner.AppVersion + NetworkVersion))
Conn *NetConnMetric
) )
var ( var (
...@@ -142,8 +144,10 @@ func start(shutdownSignal <-chan struct{}) { ...@@ -142,8 +144,10 @@ func start(shutdownSignal <-chan struct{}) {
} }
defer conn.Close() defer conn.Close()
Conn = &NetConnMetric{UDPConn: conn}
// start a server doing peerDisc and peering // start a server doing peerDisc and peering
srv := server.Serve(lPeer, conn, log.Named("srv"), Discovery(), Selection()) srv := server.Serve(lPeer, Conn, log.Named("srv"), Discovery(), Selection())
defer srv.Close() defer srv.Close()
// start the peer discovery on that connection // start the peer discovery on that connection
......
package autopeering
import (
"net"
"go.uber.org/atomic"
)
// NetConnMetric is a wrapper of a UDPConn that keeps track of RX and TX bytes.
type NetConnMetric struct {
*net.UDPConn
rxBytes atomic.Uint64
txBytes atomic.Uint64
}
// RXBytes returns the RX bytes.
func (nc *NetConnMetric) RXBytes() uint64 {
return nc.rxBytes.Load()
}
// RXBytes returns the TX bytes.
func (nc *NetConnMetric) TXBytes() uint64 {
return nc.txBytes.Load()
}
// ReadFromUDP acts like ReadFrom but returns a UDPAddr.
func (nc *NetConnMetric) ReadFromUDP(b []byte) (int, *net.UDPAddr, error) {
n, addr, err := nc.UDPConn.ReadFromUDP(b)
nc.rxBytes.Add(uint64(n))
return n, addr, err
}
// WriteToUDP acts like WriteTo but takes a UDPAddr.
func (nc *NetConnMetric) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error) {
n, err := nc.UDPConn.WriteToUDP(b, addr)
nc.txBytes.Add(uint64(n))
return n, err
}
package metrics package metrics
import ( import (
"sync/atomic"
"github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/hive.go/identity" "github.com/iotaledger/hive.go/identity"
"go.uber.org/atomic"
) )
var ( var (
_FPCInboundBytes *uint64 _FPCInboundBytes atomic.Uint64
_FPCOutboundBytes *uint64 _FPCOutboundBytes atomic.Uint64
previousNeighbors = make(map[identity.ID]gossipTrafficMetric) previousNeighbors = make(map[identity.ID]gossipTrafficMetric)
gossipOldTx uint32 gossipOldTx uint32
gossipOldRx uint32 gossipOldRx uint32
analysisOutboundBytes *uint64 analysisOutboundBytes atomic.Uint64
) )
func FPCInboundBytes() uint64 { func FPCInboundBytes() uint64 {
return atomic.LoadUint64(_FPCInboundBytes) return _FPCInboundBytes.Load()
} }
func FPCOutboundBytes() uint64 { func FPCOutboundBytes() uint64 {
return atomic.LoadUint64(_FPCOutboundBytes) return _FPCOutboundBytes.Load()
} }
func AnalysisOutboundBytes() uint64 { func AnalysisOutboundBytes() uint64 {
return atomic.LoadUint64(analysisOutboundBytes) return analysisOutboundBytes.Load()
} }
type gossipTrafficMetric struct { type gossipTrafficMetric struct {
......
package metrics package metrics
import ( import (
"sync/atomic"
"time" "time"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message" "github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
...@@ -35,13 +34,13 @@ func configure(_ *node.Plugin) { ...@@ -35,13 +34,13 @@ func configure(_ *node.Plugin) {
increaseReceivedMPSCounter() increaseReceivedMPSCounter()
})) }))
metrics.Events().FPCInboundBytes.Attach(events.NewClosure(func(amountBytes uint64) { metrics.Events().FPCInboundBytes.Attach(events.NewClosure(func(amountBytes uint64) {
atomic.AddUint64(_FPCInboundBytes, amountBytes) _FPCInboundBytes.Add(amountBytes)
})) }))
metrics.Events().FPCOutboundBytes.Attach(events.NewClosure(func(amountBytes uint64) { metrics.Events().FPCOutboundBytes.Attach(events.NewClosure(func(amountBytes uint64) {
atomic.AddUint64(_FPCOutboundBytes, amountBytes) _FPCOutboundBytes.Add(amountBytes)
})) }))
metrics.Events().AnalysisOutboundBytes.Attach(events.NewClosure(func(amountBytes uint64) { metrics.Events().AnalysisOutboundBytes.Attach(events.NewClosure(func(amountBytes uint64) {
atomic.AddUint64(analysisOutboundBytes, amountBytes) analysisOutboundBytes.Add(amountBytes)
})) }))
metrics.Events().CPUUsage.Attach(events.NewClosure(func(cpuPercent float64) { metrics.Events().CPUUsage.Attach(events.NewClosure(func(cpuPercent float64) {
cpuLock.Lock() cpuLock.Lock()
......
package prometheus package prometheus
import ( import (
"github.com/iotaledger/goshimmer/plugins/autopeering"
"github.com/iotaledger/goshimmer/plugins/metrics" "github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
var ( var (
messagesPerSecond prometheus.Gauge messagesPerSecond prometheus.Gauge
fpcInboundBytes prometheus.Gauge fpcInboundBytes prometheus.Gauge
fpcOutboundBytes prometheus.Gauge fpcOutboundBytes prometheus.Gauge
analysisOutboundBytes prometheus.Gauge analysisOutboundBytes prometheus.Gauge
autopeeringInboundBytes prometheus.Gauge
autopeeringOutboundBytes prometheus.Gauge
) )
func init() { func init() {
...@@ -27,6 +30,14 @@ func init() { ...@@ -27,6 +30,14 @@ func init() {
Name: "fpc_outbound_bytes", Name: "fpc_outbound_bytes",
Help: "FPC TX network traffic [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{ analysisOutboundBytes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "analysis_outbound_bytes", Name: "analysis_outbound_bytes",
Help: "Analysis client TX network traffic [bytes].", Help: "Analysis client TX network traffic [bytes].",
...@@ -36,6 +47,8 @@ func init() { ...@@ -36,6 +47,8 @@ func init() {
registry.MustRegister(fpcInboundBytes) registry.MustRegister(fpcInboundBytes)
registry.MustRegister(fpcOutboundBytes) registry.MustRegister(fpcOutboundBytes)
registry.MustRegister(analysisOutboundBytes) registry.MustRegister(analysisOutboundBytes)
registry.MustRegister(autopeeringInboundBytes)
registry.MustRegister(autopeeringOutboundBytes)
addCollect(collectLocalMetrics) addCollect(collectLocalMetrics)
} }
...@@ -45,4 +58,6 @@ func collectLocalMetrics() { ...@@ -45,4 +58,6 @@ func collectLocalMetrics() {
fpcInboundBytes.Set(float64(metrics.FPCInboundBytes())) fpcInboundBytes.Set(float64(metrics.FPCInboundBytes()))
fpcOutboundBytes.Set(float64(metrics.FPCOutboundBytes())) fpcOutboundBytes.Set(float64(metrics.FPCOutboundBytes()))
analysisOutboundBytes.Set(float64(metrics.AnalysisOutboundBytes())) analysisOutboundBytes.Set(float64(metrics.AnalysisOutboundBytes()))
autopeeringInboundBytes.Set(float64(autopeering.Conn.RXBytes()))
autopeeringOutboundBytes.Set(float64(autopeering.Conn.TXBytes()))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment