NPS(feature): add nps collector

Signed-off-by: rebortg <github@ghlr.de>
This commit is contained in:
rebortg 2023-04-17 16:17:42 +02:00 committed by Ben Reedy
parent d5e8a0ed7e
commit 217b670272
No known key found for this signature in database
GPG Key ID: 235C15B6086C9D7E
4 changed files with 481 additions and 0 deletions

422
collector/nps.go Normal file
View File

@ -0,0 +1,422 @@
package collector
import (
"github.com/prometheus-community/windows_exporter/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/yusufpapurcu/wmi"
)
func init() {
registerCollector("nps", newnpsCollector) // TODO: Add any perflib dependencies here
}
// A npsCollector is a Prometheus collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics
type npsCollector struct {
AccessAccepts *prometheus.Desc
AccessChallenges *prometheus.Desc
AccessRejects *prometheus.Desc
AccessRequests *prometheus.Desc
AccessBadAuthenticators *prometheus.Desc
AccessDroppedPackets *prometheus.Desc
AccessInvalidRequests *prometheus.Desc
AccessMalformedPackets *prometheus.Desc
AccessPacketsReceived *prometheus.Desc
AccessPacketsSent *prometheus.Desc
AccessServerResetTime *prometheus.Desc
AccessServerUpTime *prometheus.Desc
AccessUnknownType *prometheus.Desc
AccountingRequests *prometheus.Desc
AccountingResponses *prometheus.Desc
AccountingBadAuthenticators *prometheus.Desc
AccountingDroppedPackets *prometheus.Desc
AccountingInvalidRequests *prometheus.Desc
AccountingMalformedPackets *prometheus.Desc
AccountingNoRecord *prometheus.Desc
AccountingPacketsReceived *prometheus.Desc
AccountingPacketsSent *prometheus.Desc
AccountingServerResetTime *prometheus.Desc
AccountingServerUpTime *prometheus.Desc
AccountingUnknownType *prometheus.Desc
}
func newnpsCollector() (Collector, error) {
const subsystem = "nps"
return &npsCollector{
AccessAccepts: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_accepts"),
"(AccessAccepts)",
nil,
nil,
),
AccessChallenges: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_challenges"),
"(AccessChallenges)",
nil,
nil,
),
AccessRejects: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_rejects"),
"(AccessRejects)",
nil,
nil,
),
AccessRequests: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_requests"),
"(AccessRequests)",
nil,
nil,
),
AccessBadAuthenticators: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_bad_authenticators"),
"(BadAuthenticators)",
nil,
nil,
),
AccessDroppedPackets: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_dropped_packets"),
"(DroppedPackets)",
nil,
nil,
),
AccessInvalidRequests: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_invalid_requests"),
"(InvalidRequests)",
nil,
nil,
),
AccessMalformedPackets: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_malformed_packets"),
"(MalformedPackets)",
nil,
nil,
),
AccessPacketsReceived: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_packets_received"),
"(PacketsReceived)",
nil,
nil,
),
AccessPacketsSent: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_packets_sent"),
"(PacketsSent)",
nil,
nil,
),
AccessServerResetTime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_server_reset_time"),
"(ServerResetTime)",
nil,
nil,
),
AccessServerUpTime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_server_up_time"),
"(ServerUpTime)",
nil,
nil,
),
AccessUnknownType: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "access_unknown_type"),
"(UnknownType)",
nil,
nil,
),
AccountingRequests: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_requests"),
"(AccountingRequests)",
nil,
nil,
),
AccountingResponses: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_responses"),
"(AccountingResponses)",
nil,
nil,
),
AccountingBadAuthenticators: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_bad_authenticators"),
"(BadAuthenticators)",
nil,
nil,
),
AccountingDroppedPackets: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_dropped_packets"),
"(DroppedPackets)",
nil,
nil,
),
AccountingInvalidRequests: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_invalid_requests"),
"(InvalidRequests)",
nil,
nil,
),
AccountingMalformedPackets: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_malformed_packets"),
"(MalformedPackets)",
nil,
nil,
),
AccountingNoRecord: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_no_record"),
"(NoRecord)",
nil,
nil,
),
AccountingPacketsReceived: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_packets_received"),
"(PacketsReceived)",
nil,
nil,
),
AccountingPacketsSent: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_packets_sent"),
"(PacketsSent)",
nil,
nil,
),
AccountingServerResetTime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_server_reset_time"),
"(ServerResetTime)",
nil,
nil,
),
AccountingServerUpTime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_server_up_time"),
"(ServerUpTime)",
nil,
nil,
),
AccountingUnknownType: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accounting_unknown_type"),
"(UnknownType)",
nil,
nil,
),
}, nil
}
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *npsCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.CollectAccept(ch); err != nil {
log.Error("failed collecting NPS accept data:", desc, err)
return err
}
if desc, err := c.CollectAccounting(ch); err != nil {
log.Error("failed collecting NPS accounting data:", desc, err)
return err
}
return nil
}
// Win32_PerfRawData_IAS_NPSAuthenticationServer docs:
// - <add link to documentation here>
type Win32_PerfRawData_IAS_NPSAuthenticationServer struct {
Name string
AccessAccepts uint32
AccessChallenges uint32
AccessRejects uint32
AccessRequests uint32
AccessBadAuthenticators uint32
AccessDroppedPackets uint32
AccessInvalidRequests uint32
AccessMalformedPackets uint32
AccessPacketsReceived uint32
AccessPacketsSent uint32
AccessServerResetTime uint32
AccessServerUpTime uint32
AccessUnknownType uint32
}
type Win32_PerfRawData_IAS_NPSAccountingServer struct {
Name string
AccountingRequests uint32
AccountingResponses uint32
AccountingBadAuthenticators uint32
AccountingDroppedPackets uint32
AccountingInvalidRequests uint32
AccountingMalformedPackets uint32
AccountingNoRecord uint32
AccountingPacketsReceived uint32
AccountingPacketsSent uint32
AccountingServerResetTime uint32
AccountingServerUpTime uint32
AccountingUnknownType uint32
}
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *npsCollector) CollectAccept(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_IAS_NPSAuthenticationServer
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
ch <- prometheus.MustNewConstMetric(
c.AccessAccepts,
prometheus.CounterValue,
float64(dst[0].AccessAccepts),
)
ch <- prometheus.MustNewConstMetric(
c.AccessChallenges,
prometheus.CounterValue,
float64(dst[0].AccessChallenges),
)
ch <- prometheus.MustNewConstMetric(
c.AccessRejects,
prometheus.CounterValue,
float64(dst[0].AccessRejects),
)
ch <- prometheus.MustNewConstMetric(
c.AccessRequests,
prometheus.CounterValue,
float64(dst[0].AccessRequests),
)
ch <- prometheus.MustNewConstMetric(
c.AccessBadAuthenticators,
prometheus.CounterValue,
float64(dst[0].AccessBadAuthenticators),
)
ch <- prometheus.MustNewConstMetric(
c.AccessDroppedPackets,
prometheus.CounterValue,
float64(dst[0].AccessDroppedPackets),
)
ch <- prometheus.MustNewConstMetric(
c.AccessInvalidRequests,
prometheus.CounterValue,
float64(dst[0].AccessInvalidRequests),
)
ch <- prometheus.MustNewConstMetric(
c.AccessMalformedPackets,
prometheus.CounterValue,
float64(dst[0].AccessMalformedPackets),
)
ch <- prometheus.MustNewConstMetric(
c.AccessPacketsReceived,
prometheus.CounterValue,
float64(dst[0].AccessPacketsReceived),
)
ch <- prometheus.MustNewConstMetric(
c.AccessPacketsSent,
prometheus.CounterValue,
float64(dst[0].AccessPacketsSent),
)
ch <- prometheus.MustNewConstMetric(
c.AccessServerResetTime,
prometheus.CounterValue,
float64(dst[0].AccessServerResetTime),
)
ch <- prometheus.MustNewConstMetric(
c.AccessServerUpTime,
prometheus.CounterValue,
float64(dst[0].AccessServerUpTime),
)
ch <- prometheus.MustNewConstMetric(
c.AccessUnknownType,
prometheus.CounterValue,
float64(dst[0].AccessUnknownType),
)
return nil, nil
}
func (c *npsCollector) CollectAccounting(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_IAS_NPSAccountingServer
q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
ch <- prometheus.MustNewConstMetric(
c.AccountingRequests,
prometheus.CounterValue,
float64(dst[0].AccountingRequests),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingResponses,
prometheus.CounterValue,
float64(dst[0].AccountingResponses),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingBadAuthenticators,
prometheus.CounterValue,
float64(dst[0].AccountingBadAuthenticators),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingDroppedPackets,
prometheus.CounterValue,
float64(dst[0].AccountingDroppedPackets),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingInvalidRequests,
prometheus.CounterValue,
float64(dst[0].AccountingInvalidRequests),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingMalformedPackets,
prometheus.CounterValue,
float64(dst[0].AccountingMalformedPackets),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingNoRecord,
prometheus.CounterValue,
float64(dst[0].AccountingNoRecord),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingPacketsReceived,
prometheus.CounterValue,
float64(dst[0].AccountingPacketsReceived),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingPacketsSent,
prometheus.CounterValue,
float64(dst[0].AccountingPacketsSent),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingServerResetTime,
prometheus.CounterValue,
float64(dst[0].AccountingServerResetTime),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingServerUpTime,
prometheus.CounterValue,
float64(dst[0].AccountingServerUpTime),
)
ch <- prometheus.MustNewConstMetric(
c.AccountingUnknownType,
prometheus.CounterValue,
float64(dst[0].AccountingUnknownType),
)
return nil, nil
}

9
collector/nps_test.go Normal file
View File

@ -0,0 +1,9 @@
package collector
import (
"testing"
)
func BenchmarkNPSCollector(b *testing.B) {
benchmarkCollector(b, "nps", newNPSCollector)
}

View File

@ -26,6 +26,7 @@ This directory contains documentation of the collectors in the windows_exporter,
- [`netframework_clrremoting`](collector.netframework_clrremoting.md)
- [`netframework_clrsecurity`](collector.netframework_clrsecurity.md)
- [`net`](collector.net.md)
- [`nps`](collector.nps.md)
- [`os`](collector.os.md)
- [`process`](collector.process.md)
- [`remote_fx`](collector.remote_fx.md)

49
docs/collector.nps.md Normal file
View File

@ -0,0 +1,49 @@
# nps collector
The nps collector exposes metrics about the NPS server
|||
-|-
Metric name prefix | `nps`
Classes | Win32_PerfRawData_IAS_NPSAuthenticationServer<br/>Win32_PerfRawData_IAS_NPSAccountingServer
Enabled by default? | No
## Flags
None
## Metrics
Name | Description | Type | Labels
-----|-------------|------|-------
`windows_nps_access_accepts` | | counter | None
`windows_nps_access_bad_authenticators` | | counter | None
`windows_nps_access_challenges` | | counter | None
`windows_nps_access_dropped_packets` | | counter | None
`windows_nps_access_invalid_requests` | | counter | None
`windows_nps_access_malformed_packets` | | counter | None
`windows_nps_access_packets_received` | | counter | None
`windows_nps_access_packets_sent` | | counter | None
`windows_nps_access_rejects` | | counter | None
`windows_nps_access_requests` | | counter | None
`windows_nps_access_server_reset_time` | | counter | None
`windows_nps_access_server_up_time` | | counter | None
`windows_nps_access_unknown_type` | | counter | None
`windows_nps_accounting_bad_authenticators` | | counter | None
`windows_nps_accounting_dropped_packets` | | counter | None
`windows_nps_accounting_invalid_requests` | | counter | None
`windows_nps_accounting_malformed_packets` | | counter | None
`windows_nps_accounting_no_record` | | counter | None
`windows_nps_accounting_packets_received` | | counter | None
`windows_nps_accounting_packets_sent` | | counter | None
`windows_nps_accounting_requests` | | counter | None
`windows_nps_accounting_responses` | | counter | None
`windows_nps_accounting_server_reset_time` | | counter | None
`windows_nps_accounting_server_up_time` | | counter | None
`windows_nps_accounting_unknown_type` | | counter | None
### Example metric
Show current number of processes
```
windows_nps_access_accepts{instance="localhost"}
```