mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-17 10:09:05 +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
@@ -16,7 +16,7 @@ None
|
||||
|
||||
| Name | Description | Type | Labels |
|
||||
|-----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
|
||||
| `windows_udp_datagram_datagram_no_port_total` | Number of received UDP datagrams for which there was no application at the destination port | counter | af |
|
||||
| `windows_udp_datagram_no_port_total` | Number of received UDP datagrams for which there was no application at the destination port | counter | af |
|
||||
| `windows_udp_datagram_received_errors_total` | Number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port | counter | af |
|
||||
| `windows_udp_datagram_received_total` | Number of UDP datagrams segments received | counter | af |
|
||||
| `windows_udp_datagram_sent_total` | Number of UDP datagrams segments sent | counter | af |
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ func logCollectorResult(ctx context.Context, logger *slog.Logger, name string, e
|
||||
if err != nil {
|
||||
if !expectedCollectionError(err) {
|
||||
if errors.Is(err, pdh.ErrPerformanceCounterNotInitialized) {
|
||||
err = fmt.Errorf("%w. Check application logs from initialization pharse for more information", err)
|
||||
err = fmt.Errorf("%w. Check application logs from initialization phase for more information", err)
|
||||
}
|
||||
|
||||
logger.LogAttrs(ctx, slog.LevelWarn,
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
var _ prometheus.Collector = (*Handler)(nil)
|
||||
|
||||
// scrapeSlot admits one scrape at a time, across all collections.
|
||||
// We are expose metrics directly from the memory region of the Win32 API.
|
||||
// We expose metrics directly from the memory region of the Win32 API.
|
||||
// We should not allow more than one request at a time.
|
||||
//
|
||||
//nolint:gochecknoglobals
|
||||
|
||||
@@ -436,6 +436,6 @@ windows_service_state{name="Themes",state="stopped"} 0
|
||||
# HELP windows_udp_datagram_received_errors_total Number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port
|
||||
# TYPE windows_udp_datagram_received_errors_total counter
|
||||
# HELP windows_udp_datagram_received_total UDP datagrams are delivered to UDP users
|
||||
# TYPE windows_udp_datagram_received_total gauge
|
||||
# TYPE windows_udp_datagram_received_total counter
|
||||
# HELP windows_udp_datagram_sent_total UDP datagrams are sent from the entity
|
||||
# TYPE windows_udp_datagram_sent_total counter
|
||||
|
||||
Reference in New Issue
Block a user