-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
376 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# udp collector | ||
|
||
The udp collector exposes metrics about the UDP network stack. | ||
|
||
||| | ||
-|- | ||
Metric name prefix | `udp` | ||
Data source | Perflib | ||
Enabled by default? | No | ||
|
||
## Flags | ||
|
||
None | ||
|
||
## Metrics | ||
|
||
| 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_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 | | ||
|
||
### Example metric | ||
_This collector does not yet have explained examples, we would appreciate your help adding them!_ | ||
|
||
## Useful queries | ||
_This collector does not yet have any useful queries added, we would appreciate your help adding them!_ | ||
|
||
## Alerting examples | ||
_This collector does not yet have alerting examples, we would appreciate your help adding them!_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package udp | ||
|
||
// The TCPv6 performance object uses the same fields. | ||
// https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.tcpstate?view=net-8.0. | ||
const ( | ||
datagramsNoPortPerSec = "Datagrams No Port/sec" | ||
datagramsReceivedPerSec = "Datagrams Received/sec" | ||
datagramsReceivedErrors = "Datagrams Received Errors" | ||
datagramsSentPerSec = "Datagrams Sent/sec" | ||
) | ||
|
||
// Datagrams No Port/sec is the rate of received UDP datagrams for which there was no application at the destination port. | ||
// Datagrams Received Errors is the number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port. | ||
// Datagrams Received/sec is the rate at which UDP datagrams are delivered to UDP users. | ||
// Datagrams Sent/sec is the rate at which UDP datagrams are sent from the entity. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
//go:build windows | ||
|
||
package udp | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/alecthomas/kingpin/v2" | ||
"github.com/prometheus-community/windows_exporter/internal/mi" | ||
"github.com/prometheus-community/windows_exporter/internal/perfdata" | ||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes" | ||
"github.com/prometheus-community/windows_exporter/internal/types" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const Name = "udp" | ||
|
||
type Config struct{} | ||
|
||
var ConfigDefaults = Config{} | ||
|
||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics. | ||
type Collector struct { | ||
config Config | ||
|
||
perfDataCollector4 perfdata.Collector | ||
perfDataCollector6 perfdata.Collector | ||
|
||
datagramsNoPortTotal *prometheus.Desc | ||
datagramsReceivedTotal *prometheus.Desc | ||
datagramsReceivedErrorsTotal *prometheus.Desc | ||
datagramsSentTotal *prometheus.Desc | ||
} | ||
|
||
func New(config *Config) *Collector { | ||
if config == nil { | ||
config = &ConfigDefaults | ||
} | ||
|
||
c := &Collector{ | ||
config: *config, | ||
} | ||
|
||
return c | ||
} | ||
|
||
func NewWithFlags(_ *kingpin.Application) *Collector { | ||
c := &Collector{ | ||
config: ConfigDefaults, | ||
} | ||
|
||
return c | ||
} | ||
|
||
func (c *Collector) GetName() string { | ||
return Name | ||
} | ||
|
||
func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) { | ||
return []string{}, nil | ||
} | ||
|
||
func (c *Collector) Close(_ *slog.Logger) error { | ||
c.perfDataCollector4.Close() | ||
c.perfDataCollector6.Close() | ||
|
||
return nil | ||
} | ||
|
||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error { | ||
counters := []string{ | ||
datagramsNoPortPerSec, | ||
datagramsReceivedPerSec, | ||
datagramsReceivedErrors, | ||
datagramsSentPerSec, | ||
} | ||
|
||
var err error | ||
|
||
c.perfDataCollector4, err = perfdata.NewCollector(perfdata.V2, "UDPv4", nil, counters) | ||
if err != nil { | ||
return fmt.Errorf("failed to create UDPv4 collector: %w", err) | ||
} | ||
|
||
c.perfDataCollector6, err = perfdata.NewCollector(perfdata.V2, "UDPv6", nil, counters) | ||
if err != nil { | ||
return fmt.Errorf("failed to create UDPv6 collector: %w", err) | ||
} | ||
|
||
c.datagramsNoPortTotal = prometheus.NewDesc( | ||
prometheus.BuildFQName(types.Namespace, Name, "datagram_no_port_total"), | ||
"Number of received UDP datagrams for which there was no application at the destination port", | ||
[]string{"af"}, | ||
nil, | ||
) | ||
c.datagramsReceivedTotal = prometheus.NewDesc( | ||
prometheus.BuildFQName(types.Namespace, Name, "datagram_received_total"), | ||
"UDP datagrams are delivered to UDP users", | ||
[]string{"af"}, | ||
nil, | ||
) | ||
c.datagramsReceivedErrorsTotal = prometheus.NewDesc( | ||
prometheus.BuildFQName(types.Namespace, Name, "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", | ||
[]string{"af"}, | ||
nil, | ||
) | ||
c.datagramsSentTotal = prometheus.NewDesc( | ||
prometheus.BuildFQName(types.Namespace, Name, "datagram_sent_total"), | ||
"UDP datagrams are sent from the entity", | ||
[]string{"af"}, | ||
nil, | ||
) | ||
|
||
return nil | ||
} | ||
|
||
// Collect sends the metric values for each metric | ||
// to the provided prometheus Metric channel. | ||
func (c *Collector) Collect(_ *types.ScrapeContext, _ *slog.Logger, ch chan<- prometheus.Metric) error { | ||
return c.collect(ch) | ||
} | ||
|
||
func (c *Collector) collect(ch chan<- prometheus.Metric) error { | ||
data, err := c.perfDataCollector4.Collect() | ||
if err != nil { | ||
return fmt.Errorf("failed to collect UDPv4 metrics: %w", err) | ||
} | ||
|
||
c.writeUDPCounters(ch, data[perftypes.EmptyInstance], []string{"ipv4"}) | ||
|
||
data, err = c.perfDataCollector6.Collect() | ||
if err != nil { | ||
return fmt.Errorf("failed to collect UDPv6 metrics: %w", err) | ||
} | ||
|
||
c.writeUDPCounters(ch, data[perftypes.EmptyInstance], []string{"ipv6"}) | ||
|
||
return nil | ||
} | ||
|
||
func (c *Collector) writeUDPCounters(ch chan<- prometheus.Metric, metrics map[string]perftypes.CounterValues, labels []string) { | ||
ch <- prometheus.MustNewConstMetric( | ||
c.datagramsNoPortTotal, | ||
prometheus.CounterValue, | ||
metrics[datagramsNoPortPerSec].FirstValue, | ||
labels..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.datagramsReceivedErrorsTotal, | ||
prometheus.CounterValue, | ||
metrics[datagramsReceivedErrors].FirstValue, | ||
labels..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.datagramsReceivedTotal, | ||
prometheus.GaugeValue, | ||
metrics[datagramsReceivedPerSec].FirstValue, | ||
labels..., | ||
) | ||
ch <- prometheus.MustNewConstMetric( | ||
c.datagramsSentTotal, | ||
prometheus.CounterValue, | ||
metrics[datagramsSentPerSec].FirstValue, | ||
labels..., | ||
) | ||
} |
Oops, something went wrong.