mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-14 15:01:14 +00:00
Updated metrics, added dashboard for Grafana (#311)
* Updated metrics, added dashboard for Grafana * Remove unused interfce metric * Set default scrape interval
This commit is contained in:
@@ -75,7 +75,8 @@ func (c *StatisticsCollector) collectInterfaceData(ctx context.Context) {
|
||||
i.BytesTransmitted = physicalInterface.BytesUpload
|
||||
|
||||
// Update prometheus metrics
|
||||
go c.ms.UpdateInterfaceMetrics(*i)
|
||||
go c.updateInterfaceMetrics(*i)
|
||||
|
||||
return i, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -134,7 +135,7 @@ func (c *StatisticsCollector) collectPeerData(ctx context.Context) {
|
||||
p.LastHandshake = lastHandshake
|
||||
|
||||
// Update prometheus metrics
|
||||
go c.ms.UpdatePeerMetrics(ctx, *p)
|
||||
go c.updatePeerMetrics(ctx, *p)
|
||||
|
||||
return p, nil
|
||||
})
|
||||
@@ -272,3 +273,17 @@ func (c *StatisticsCollector) isPeerPingable(ctx context.Context, peer domain.Pe
|
||||
stats := pinger.Statistics()
|
||||
return stats.PacketsRecv == checkCount
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) updateInterfaceMetrics(status domain.InterfaceStatus) {
|
||||
c.ms.UpdateInterfaceMetrics(status)
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) updatePeerMetrics(ctx context.Context, status domain.PeerStatus) {
|
||||
// Fetch peer data from the database
|
||||
peer, err := c.db.GetPeer(ctx, status.PeerId)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch peer data for metrics %s: %v", status.PeerId, err)
|
||||
return
|
||||
}
|
||||
c.ms.UpdatePeerMetrics(peer, status)
|
||||
}
|
||||
|
Reference in New Issue
Block a user