Remove unused interfce metric

This commit is contained in:
Dmytro Bondar 2024-09-30 21:17:52 +02:00
parent 1e1884043e
commit ea1a0e0bbf
No known key found for this signature in database
GPG Key ID: C123CD37BBED8BB7
3 changed files with 5 additions and 20 deletions

View File

@ -17,7 +17,6 @@ import (
type MetricsServer struct { type MetricsServer struct {
*http.Server *http.Server
ifaceIsDisabled *prometheus.GaugeVec
ifaceReceivedBytesTotal *prometheus.GaugeVec ifaceReceivedBytesTotal *prometheus.GaugeVec
ifaceSendBytesTotal *prometheus.GaugeVec ifaceSendBytesTotal *prometheus.GaugeVec
peerIsConnected *prometheus.GaugeVec peerIsConnected *prometheus.GaugeVec
@ -45,13 +44,6 @@ func NewMetricsServer(cfg *config.Config) *MetricsServer {
Handler: mux, 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( ifaceReceivedBytesTotal: promauto.With(reg).NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "wireguard_interface_received_bytes_total", 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 // 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)} labels := []string{string(status.InterfaceId)}
m.ifaceIsDisabled.WithLabelValues(labels...).Set(internal.BoolToFloat64(iface.IsDisabled()))
m.ifaceReceivedBytesTotal.WithLabelValues(labels...).Set(float64(status.BytesReceived)) m.ifaceReceivedBytesTotal.WithLabelValues(labels...).Set(float64(status.BytesReceived))
m.ifaceSendBytesTotal.WithLabelValues(labels...).Set(float64(status.BytesTransmitted)) m.ifaceSendBytesTotal.WithLabelValues(labels...).Set(float64(status.BytesTransmitted))
} }

View File

@ -27,7 +27,6 @@ type InterfaceAndPeerDatabaseRepo interface {
type StatisticsDatabaseRepo interface { type StatisticsDatabaseRepo interface {
GetAllInterfaces(ctx context.Context) ([]domain.Interface, error) 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) GetInterfacePeers(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.Peer, error)
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error) GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
@ -53,6 +52,6 @@ type WgQuickController interface {
} }
type MetricsServer interface { type MetricsServer interface {
UpdateInterfaceMetrics(iface *domain.Interface, status domain.InterfaceStatus) UpdateInterfaceMetrics(status domain.InterfaceStatus)
UpdatePeerMetrics(peer *domain.Peer, status domain.PeerStatus) UpdatePeerMetrics(peer *domain.Peer, status domain.PeerStatus)
} }

View File

@ -75,7 +75,7 @@ func (c *StatisticsCollector) collectInterfaceData(ctx context.Context) {
i.BytesTransmitted = physicalInterface.BytesUpload i.BytesTransmitted = physicalInterface.BytesUpload
// Update prometheus metrics // Update prometheus metrics
go c.updateInterfaceMetrics(ctx, *i) go c.updateInterfaceMetrics(*i)
return i, nil return i, nil
}) })
@ -274,13 +274,8 @@ func (c *StatisticsCollector) isPeerPingable(ctx context.Context, peer domain.Pe
return stats.PacketsRecv == checkCount return stats.PacketsRecv == checkCount
} }
func (c *StatisticsCollector) updateInterfaceMetrics(ctx context.Context, status domain.InterfaceStatus) { func (c *StatisticsCollector) updateInterfaceMetrics(status domain.InterfaceStatus) {
iface, err := c.db.GetInterface(ctx, status.InterfaceId) c.ms.UpdateInterfaceMetrics(status)
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) updatePeerMetrics(ctx context.Context, status domain.PeerStatus) { func (c *StatisticsCollector) updatePeerMetrics(ctx context.Context, status domain.PeerStatus) {