mirror of
https://github.com/h44z/wg-portal
synced 2025-06-26 18:16:21 +00:00
Remove unused interfce metric
This commit is contained in:
parent
1e1884043e
commit
ea1a0e0bbf
@ -17,7 +17,6 @@ import (
|
||||
type MetricsServer struct {
|
||||
*http.Server
|
||||
|
||||
ifaceIsDisabled *prometheus.GaugeVec
|
||||
ifaceReceivedBytesTotal *prometheus.GaugeVec
|
||||
ifaceSendBytesTotal *prometheus.GaugeVec
|
||||
peerIsConnected *prometheus.GaugeVec
|
||||
@ -45,13 +44,6 @@ func NewMetricsServer(cfg *config.Config) *MetricsServer {
|
||||
Handler: mux,
|
||||
},
|
||||
|
||||
ifaceIsDisabled: promauto.With(reg).NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "wireguard_interface_up",
|
||||
Help: "Iterface state (boolean: 1/0).",
|
||||
}, ifaceLabels,
|
||||
),
|
||||
|
||||
ifaceReceivedBytesTotal: promauto.With(reg).NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "wireguard_interface_received_bytes_total",
|
||||
@ -119,9 +111,8 @@ func (m *MetricsServer) Run(ctx context.Context) {
|
||||
}
|
||||
|
||||
// UpdateInterfaceMetrics updates the metrics for the given interface
|
||||
func (m *MetricsServer) UpdateInterfaceMetrics(iface *domain.Interface, status domain.InterfaceStatus) {
|
||||
func (m *MetricsServer) UpdateInterfaceMetrics(status domain.InterfaceStatus) {
|
||||
labels := []string{string(status.InterfaceId)}
|
||||
m.ifaceIsDisabled.WithLabelValues(labels...).Set(internal.BoolToFloat64(iface.IsDisabled()))
|
||||
m.ifaceReceivedBytesTotal.WithLabelValues(labels...).Set(float64(status.BytesReceived))
|
||||
m.ifaceSendBytesTotal.WithLabelValues(labels...).Set(float64(status.BytesTransmitted))
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ type InterfaceAndPeerDatabaseRepo interface {
|
||||
|
||||
type StatisticsDatabaseRepo interface {
|
||||
GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)
|
||||
GetInterface(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, error)
|
||||
GetInterfacePeers(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.Peer, error)
|
||||
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
|
||||
|
||||
@ -53,6 +52,6 @@ type WgQuickController interface {
|
||||
}
|
||||
|
||||
type MetricsServer interface {
|
||||
UpdateInterfaceMetrics(iface *domain.Interface, status domain.InterfaceStatus)
|
||||
UpdateInterfaceMetrics(status domain.InterfaceStatus)
|
||||
UpdatePeerMetrics(peer *domain.Peer, status domain.PeerStatus)
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func (c *StatisticsCollector) collectInterfaceData(ctx context.Context) {
|
||||
i.BytesTransmitted = physicalInterface.BytesUpload
|
||||
|
||||
// Update prometheus metrics
|
||||
go c.updateInterfaceMetrics(ctx, *i)
|
||||
go c.updateInterfaceMetrics(*i)
|
||||
|
||||
return i, nil
|
||||
})
|
||||
@ -274,13 +274,8 @@ func (c *StatisticsCollector) isPeerPingable(ctx context.Context, peer domain.Pe
|
||||
return stats.PacketsRecv == checkCount
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) updateInterfaceMetrics(ctx context.Context, status domain.InterfaceStatus) {
|
||||
iface, err := c.db.GetInterface(ctx, status.InterfaceId)
|
||||
if err != nil {
|
||||
logrus.Warnf("failed to fetch interface data for metrics %s: %v", status.InterfaceId, err)
|
||||
return
|
||||
}
|
||||
c.ms.UpdateInterfaceMetrics(iface, status)
|
||||
func (c *StatisticsCollector) updateInterfaceMetrics(status domain.InterfaceStatus) {
|
||||
c.ms.UpdateInterfaceMetrics(status)
|
||||
}
|
||||
|
||||
func (c *StatisticsCollector) updatePeerMetrics(ctx context.Context, status domain.PeerStatus) {
|
||||
|
Loading…
Reference in New Issue
Block a user