mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-21 03:59:04 +02:00
collector: publish documented counter types for udp and hyperv metrics (#2661)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
co-authored by
Claude Fable 5
parent
ab74f5d39d
commit
c6ad8f4792
@@ -106,7 +106,7 @@ func (c *Collector) collectLegacyNetworkAdapter(ch chan<- prometheus.Metric) err
|
||||
for _, data := range c.perfDataObjectLegacyNetworkAdapter {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.legacyNetworkAdapterBytesDropped,
|
||||
prometheus.GaugeValue,
|
||||
prometheus.CounterValue,
|
||||
data.LegacyNetworkAdapterBytesDropped,
|
||||
data.Name,
|
||||
)
|
||||
|
||||
@@ -75,6 +75,29 @@ func TestCollectorVirtualStorageDeviceLatency(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCollectorLegacyNetworkAdapter checks that the legacy network adapter
|
||||
// metrics are published with the counter type documented in
|
||||
// docs/collector.hyperv.md; bytes_dropped_total used to be published as a
|
||||
// gauge. The CI fixture VM carries a legacy network adapter.
|
||||
func TestCollectorLegacyNetworkAdapter(t *testing.T) {
|
||||
metrics := testutils.TestCollector(t, hyperv.New, &hyperv.Config{CollectorsEnabled: []string{"legacy_network_adapter"}})
|
||||
|
||||
for _, name := range []string{
|
||||
"windows_hyperv_legacy_network_adapter_bytes_dropped_total",
|
||||
"windows_hyperv_legacy_network_adapter_bytes_received_total",
|
||||
"windows_hyperv_legacy_network_adapter_bytes_sent_total",
|
||||
"windows_hyperv_legacy_network_adapter_frames_dropped_total",
|
||||
"windows_hyperv_legacy_network_adapter_frames_received_total",
|
||||
"windows_hyperv_legacy_network_adapter_frames_sent_total",
|
||||
} {
|
||||
testutils.RequireFixtureMetric(t, metrics, hyperv.Name, name, nil)
|
||||
|
||||
if family, ok := metrics[name]; ok {
|
||||
require.Equal(t, dto.MetricType_COUNTER, family.GetType(), name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestCloseReleasesQuery ensures Close releases the PDH queries of the sub-collectors.
|
||||
func TestCloseReleasesQuery(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -171,7 +171,7 @@ func (c *Collector) writeUDPCounters(ch chan<- prometheus.Metric, metrics []perf
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.datagramsReceivedTotal,
|
||||
prometheus.GaugeValue,
|
||||
prometheus.CounterValue,
|
||||
metrics[0].DatagramsReceivedPerSec,
|
||||
af,
|
||||
)
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
|
||||
"github.com/prometheus-community/windows_exporter/internal/collector/udp"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils/testutils"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func BenchmarkCollector(b *testing.B) {
|
||||
@@ -29,5 +31,18 @@ func BenchmarkCollector(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestCollector(t *testing.T) {
|
||||
testutils.TestCollector(t, udp.New, nil)
|
||||
metrics := testutils.TestCollector(t, udp.New, nil)
|
||||
|
||||
// All four datagram totals are cumulative raw PDH values and documented as
|
||||
// counters in docs/collector.udp.md; datagram_received_total used to be
|
||||
// published as a gauge.
|
||||
for _, name := range []string{
|
||||
"windows_udp_datagram_no_port_total",
|
||||
"windows_udp_datagram_received_errors_total",
|
||||
"windows_udp_datagram_received_total",
|
||||
"windows_udp_datagram_sent_total",
|
||||
} {
|
||||
require.Contains(t, metrics, name)
|
||||
require.Equal(t, dto.MetricType_COUNTER, metrics[name].GetType(), name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user