mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-20 11:46:36 +00:00
Expose TCPv6 performance counters in the tcp collector
Signed-off-by: Michael Allen <MAllen@laserfiche.com>
This commit is contained in:
@@ -3,17 +3,15 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("tcp", NewTCPCollector, "TCPv4")
|
registerCollector("tcp", NewTCPCollector, "TCPv4", "TCPv6")
|
||||||
}
|
}
|
||||||
|
|
||||||
// A TCPCollector is a Prometheus collector for WMI Win32_PerfRawData_Tcpip_TCPv4 metrics
|
// A TCPCollector is a Prometheus collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics
|
||||||
type TCPCollector struct {
|
type TCPCollector struct {
|
||||||
ConnectionFailures *prometheus.Desc
|
ConnectionFailures *prometheus.Desc
|
||||||
ConnectionsActive *prometheus.Desc
|
ConnectionsActive *prometheus.Desc
|
||||||
@@ -34,55 +32,55 @@ func NewTCPCollector() (Collector, error) {
|
|||||||
ConnectionFailures: prometheus.NewDesc(
|
ConnectionFailures: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "connection_failures"),
|
prometheus.BuildFQName(Namespace, subsystem, "connection_failures"),
|
||||||
"(TCP.ConnectionFailures)",
|
"(TCP.ConnectionFailures)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
ConnectionsActive: prometheus.NewDesc(
|
ConnectionsActive: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "connections_active"),
|
prometheus.BuildFQName(Namespace, subsystem, "connections_active"),
|
||||||
"(TCP.ConnectionsActive)",
|
"(TCP.ConnectionsActive)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
ConnectionsEstablished: prometheus.NewDesc(
|
ConnectionsEstablished: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "connections_established"),
|
prometheus.BuildFQName(Namespace, subsystem, "connections_established"),
|
||||||
"(TCP.ConnectionsEstablished)",
|
"(TCP.ConnectionsEstablished)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
ConnectionsPassive: prometheus.NewDesc(
|
ConnectionsPassive: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "connections_passive"),
|
prometheus.BuildFQName(Namespace, subsystem, "connections_passive"),
|
||||||
"(TCP.ConnectionsPassive)",
|
"(TCP.ConnectionsPassive)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
ConnectionsReset: prometheus.NewDesc(
|
ConnectionsReset: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "connections_reset"),
|
prometheus.BuildFQName(Namespace, subsystem, "connections_reset"),
|
||||||
"(TCP.ConnectionsReset)",
|
"(TCP.ConnectionsReset)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
SegmentsTotal: prometheus.NewDesc(
|
SegmentsTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "segments_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "segments_total"),
|
||||||
"(TCP.SegmentsTotal)",
|
"(TCP.SegmentsTotal)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
SegmentsReceivedTotal: prometheus.NewDesc(
|
SegmentsReceivedTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "segments_received_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "segments_received_total"),
|
||||||
"(TCP.SegmentsReceivedTotal)",
|
"(TCP.SegmentsReceivedTotal)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
SegmentsRetransmittedTotal: prometheus.NewDesc(
|
SegmentsRetransmittedTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "segments_retransmitted_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "segments_retransmitted_total"),
|
||||||
"(TCP.SegmentsRetransmittedTotal)",
|
"(TCP.SegmentsRetransmittedTotal)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
SegmentsSentTotal: prometheus.NewDesc(
|
SegmentsSentTotal: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "segments_sent_total"),
|
prometheus.BuildFQName(Namespace, subsystem, "segments_sent_total"),
|
||||||
"(TCP.SegmentsSentTotal)",
|
"(TCP.SegmentsSentTotal)",
|
||||||
nil,
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
}, nil
|
}, nil
|
||||||
@@ -100,6 +98,7 @@ func (c *TCPCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
|
|
||||||
// Win32_PerfRawData_Tcpip_TCPv4 docs
|
// Win32_PerfRawData_Tcpip_TCPv4 docs
|
||||||
// - https://msdn.microsoft.com/en-us/library/aa394341(v=vs.85).aspx
|
// - https://msdn.microsoft.com/en-us/library/aa394341(v=vs.85).aspx
|
||||||
|
// The TCPv6 performance object uses the same fields.
|
||||||
type tcp struct {
|
type tcp struct {
|
||||||
ConnectionFailures float64 `perflib:"Connection Failures"`
|
ConnectionFailures float64 `perflib:"Connection Failures"`
|
||||||
ConnectionsActive float64 `perflib:"Connections Active"`
|
ConnectionsActive float64 `perflib:"Connections Active"`
|
||||||
@@ -112,62 +111,81 @@ type tcp struct {
|
|||||||
SegmentsSentPersec float64 `perflib:"Segments Sent/sec"`
|
SegmentsSentPersec float64 `perflib:"Segments Sent/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TCPCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func writeTCPCounters(metrics tcp, labels []string, c *TCPCollector, ch chan<- prometheus.Metric) {
|
||||||
var dst []tcp
|
|
||||||
|
|
||||||
if err := unmarshalObject(ctx.perfObjects["TCPv4"], &dst); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(dst) == 0 {
|
|
||||||
return nil, errors.New("TCPv4 performance object not available")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Counters
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionFailures,
|
c.ConnectionFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ConnectionFailures,
|
metrics.ConnectionFailures,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsActive,
|
c.ConnectionsActive,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ConnectionsActive,
|
metrics.ConnectionsActive,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsEstablished,
|
c.ConnectionsEstablished,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].ConnectionsEstablished,
|
metrics.ConnectionsEstablished,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsPassive,
|
c.ConnectionsPassive,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ConnectionsPassive,
|
metrics.ConnectionsPassive,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsReset,
|
c.ConnectionsReset,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ConnectionsReset,
|
metrics.ConnectionsReset,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsTotal,
|
c.SegmentsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].SegmentsPersec,
|
metrics.SegmentsPersec,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsReceivedTotal,
|
c.SegmentsReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].SegmentsReceivedPersec,
|
metrics.SegmentsReceivedPersec,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsRetransmittedTotal,
|
c.SegmentsRetransmittedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].SegmentsRetransmittedPersec,
|
metrics.SegmentsRetransmittedPersec,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsSentTotal,
|
c.SegmentsSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].SegmentsSentPersec,
|
metrics.SegmentsSentPersec,
|
||||||
|
labels...,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TCPCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
|
var dst []tcp
|
||||||
|
|
||||||
|
// TCPv4 counters
|
||||||
|
if err := unmarshalObject(ctx.perfObjects["TCPv4"], &dst); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(dst) != 0 {
|
||||||
|
writeTCPCounters(dst[0], []string{"ipv4"}, c, ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TCPv6 counters
|
||||||
|
if err := unmarshalObject(ctx.perfObjects["TCPv6"], &dst); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(dst) != 0 {
|
||||||
|
writeTCPCounters(dst[0], []string{"ipv6"}, c, ch)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user