mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-09 12:06:35 +00:00
process: Use registry collector for V1 data (#1814)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
// Copyright 2024 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package nps
|
||||
|
||||
const (
|
||||
// NPS Authentication Server
|
||||
accessAccepts = "Access-Accepts"
|
||||
accessChallenges = "Access-Challenges"
|
||||
accessRejects = "Access-Rejects"
|
||||
accessRequests = "Access-Requests"
|
||||
accessBadAuthenticators = "Bad Authenticators"
|
||||
accessDroppedPackets = "Dropped Packets"
|
||||
accessInvalidRequests = "Invalid Requests"
|
||||
accessMalformedPackets = "Malformed Packets"
|
||||
accessPacketsReceived = "Packets Received"
|
||||
accessPacketsSent = "Packets Sent"
|
||||
accessServerResetTime = "Server Reset Time"
|
||||
accessServerUpTime = "Server Up Time"
|
||||
accessUnknownType = "Unknown Type"
|
||||
|
||||
// NPS Accounting Server
|
||||
accountingRequests = "Accounting-Requests"
|
||||
accountingResponses = "Accounting-Responses"
|
||||
accountingBadAuthenticators = "Bad Authenticators"
|
||||
accountingDroppedPackets = "Dropped Packets"
|
||||
accountingInvalidRequests = "Invalid Requests"
|
||||
accountingMalformedPackets = "Malformed Packets"
|
||||
accountingNoRecord = "No Record"
|
||||
accountingPacketsReceived = "Packets Received"
|
||||
accountingPacketsSent = "Packets Sent"
|
||||
accountingServerResetTime = "Server Reset Time"
|
||||
accountingServerUpTime = "Server Up Time"
|
||||
accountingUnknownType = "Unknown Type"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
"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/pdh"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@@ -37,7 +37,8 @@ var ConfigDefaults = Config{}
|
||||
type Collector struct {
|
||||
config Config
|
||||
|
||||
accessPerfDataCollector *perfdata.Collector
|
||||
accessPerfDataCollector *pdh.Collector
|
||||
accessPerfDataObject []perfDataCounterValuesAccess
|
||||
accessAccepts *prometheus.Desc
|
||||
accessChallenges *prometheus.Desc
|
||||
accessRejects *prometheus.Desc
|
||||
@@ -52,7 +53,8 @@ type Collector struct {
|
||||
accessServerUpTime *prometheus.Desc
|
||||
accessUnknownType *prometheus.Desc
|
||||
|
||||
accountingPerfDataCollector *perfdata.Collector
|
||||
accountingPerfDataCollector *pdh.Collector
|
||||
accountingPerfDataObject []perfDataCounterValuesAccounting
|
||||
accountingRequests *prometheus.Desc
|
||||
accountingResponses *prometheus.Desc
|
||||
accountingBadAuthenticators *prometheus.Desc
|
||||
@@ -96,39 +98,12 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
|
||||
errs := make([]error, 0, 2)
|
||||
|
||||
c.accessPerfDataCollector, err = perfdata.NewCollector("NPS Authentication Server", nil, []string{
|
||||
accessAccepts,
|
||||
accessChallenges,
|
||||
accessRejects,
|
||||
accessRequests,
|
||||
accessBadAuthenticators,
|
||||
accessDroppedPackets,
|
||||
accessInvalidRequests,
|
||||
accessMalformedPackets,
|
||||
accessPacketsReceived,
|
||||
accessPacketsSent,
|
||||
accessServerResetTime,
|
||||
accessServerUpTime,
|
||||
accessUnknownType,
|
||||
})
|
||||
c.accessPerfDataCollector, err = pdh.NewCollector[perfDataCounterValuesAccess]("NPS Authentication Server", nil)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("failed to create NPS Authentication Server collector: %w", err))
|
||||
}
|
||||
|
||||
c.accountingPerfDataCollector, err = perfdata.NewCollector("NPS Accounting Server", nil, []string{
|
||||
accountingRequests,
|
||||
accountingResponses,
|
||||
accountingBadAuthenticators,
|
||||
accountingDroppedPackets,
|
||||
accountingInvalidRequests,
|
||||
accountingMalformedPackets,
|
||||
accountingNoRecord,
|
||||
accountingPacketsReceived,
|
||||
accountingPacketsSent,
|
||||
accountingServerResetTime,
|
||||
accountingServerUpTime,
|
||||
accountingUnknownType,
|
||||
})
|
||||
c.accountingPerfDataCollector, err = pdh.NewCollector[perfDataCounterValuesAccounting]("NPS Accounting Server", nil)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("failed to create NPS Accounting Server collector: %w", err))
|
||||
}
|
||||
@@ -307,178 +282,168 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
||||
// collectAccept sends the metric values for each metric
|
||||
// to the provided prometheus Metric channel.
|
||||
func (c *Collector) collectAccept(ch chan<- prometheus.Metric) error {
|
||||
perfData, err := c.accessPerfDataCollector.Collect()
|
||||
err := c.accessPerfDataCollector.Collect(&c.accessPerfDataObject)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to collect NPS Authentication Server metrics: %w", err)
|
||||
}
|
||||
|
||||
data, ok := perfData[perfdata.InstanceEmpty]
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to collect NPS Authentication Server metrics: %w", types.ErrNoData)
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessAccepts,
|
||||
prometheus.CounterValue,
|
||||
data[accessAccepts].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessAccepts,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessChallenges,
|
||||
prometheus.CounterValue,
|
||||
data[accessChallenges].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessChallenges,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessRejects,
|
||||
prometheus.CounterValue,
|
||||
data[accessRejects].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessRejects,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessRequests,
|
||||
prometheus.CounterValue,
|
||||
data[accessRequests].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessRequests,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessBadAuthenticators,
|
||||
prometheus.CounterValue,
|
||||
data[accessBadAuthenticators].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessBadAuthenticators,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessDroppedPackets,
|
||||
prometheus.CounterValue,
|
||||
data[accessDroppedPackets].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessDroppedPackets,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessInvalidRequests,
|
||||
prometheus.CounterValue,
|
||||
data[accessInvalidRequests].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessInvalidRequests,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessMalformedPackets,
|
||||
prometheus.CounterValue,
|
||||
data[accessMalformedPackets].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessMalformedPackets,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessPacketsReceived,
|
||||
prometheus.CounterValue,
|
||||
data[accessPacketsReceived].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessPacketsReceived,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessPacketsSent,
|
||||
prometheus.CounterValue,
|
||||
data[accessPacketsSent].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessPacketsSent,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessServerResetTime,
|
||||
prometheus.CounterValue,
|
||||
data[accessServerResetTime].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessServerResetTime,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessServerUpTime,
|
||||
prometheus.CounterValue,
|
||||
data[accessServerUpTime].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessServerUpTime,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accessUnknownType,
|
||||
prometheus.CounterValue,
|
||||
data[accessUnknownType].FirstValue,
|
||||
c.accessPerfDataObject[0].AccessUnknownType,
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) collectAccounting(ch chan<- prometheus.Metric) error {
|
||||
perfData, err := c.accountingPerfDataCollector.Collect()
|
||||
err := c.accountingPerfDataCollector.Collect(&c.accountingPerfDataObject)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to collect NPS Accounting Server metrics: %w", err)
|
||||
}
|
||||
|
||||
data, ok := perfData[perfdata.InstanceEmpty]
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to collect NPS Accounting Server metrics: %w", types.ErrNoData)
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingRequests,
|
||||
prometheus.CounterValue,
|
||||
data[accountingRequests].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingRequests,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingResponses,
|
||||
prometheus.CounterValue,
|
||||
data[accountingResponses].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingResponses,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingBadAuthenticators,
|
||||
prometheus.CounterValue,
|
||||
data[accountingBadAuthenticators].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingBadAuthenticators,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingDroppedPackets,
|
||||
prometheus.CounterValue,
|
||||
data[accountingDroppedPackets].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingDroppedPackets,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingInvalidRequests,
|
||||
prometheus.CounterValue,
|
||||
data[accountingInvalidRequests].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingInvalidRequests,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingMalformedPackets,
|
||||
prometheus.CounterValue,
|
||||
data[accountingMalformedPackets].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingMalformedPackets,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingNoRecord,
|
||||
prometheus.CounterValue,
|
||||
data[accountingNoRecord].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingNoRecord,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingPacketsReceived,
|
||||
prometheus.CounterValue,
|
||||
data[accountingPacketsReceived].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingPacketsReceived,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingPacketsSent,
|
||||
prometheus.CounterValue,
|
||||
data[accountingPacketsSent].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingPacketsSent,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingServerResetTime,
|
||||
prometheus.CounterValue,
|
||||
data[accountingServerResetTime].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingServerResetTime,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingServerUpTime,
|
||||
prometheus.CounterValue,
|
||||
data[accountingServerUpTime].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingServerUpTime,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.accountingUnknownType,
|
||||
prometheus.CounterValue,
|
||||
data[accountingUnknownType].FirstValue,
|
||||
c.accountingPerfDataObject[0].AccountingUnknownType,
|
||||
)
|
||||
|
||||
return nil
|
||||
|
||||
49
internal/collector/nps/types.go
Normal file
49
internal/collector/nps/types.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2024 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package nps
|
||||
|
||||
type perfDataCounterValuesAccess struct {
|
||||
// NPS Authentication Server
|
||||
AccessAccepts float64 `perfdata:"Access-Accepts"`
|
||||
AccessChallenges float64 `perfdata:"Access-Challenges"`
|
||||
AccessRejects float64 `perfdata:"Access-Rejects"`
|
||||
AccessRequests float64 `perfdata:"Access-Requests"`
|
||||
AccessBadAuthenticators float64 `perfdata:"Bad Authenticators"`
|
||||
AccessDroppedPackets float64 `perfdata:"Dropped Packets"`
|
||||
AccessInvalidRequests float64 `perfdata:"Invalid Requests"`
|
||||
AccessMalformedPackets float64 `perfdata:"Malformed Packets"`
|
||||
AccessPacketsReceived float64 `perfdata:"Packets Received"`
|
||||
AccessPacketsSent float64 `perfdata:"Packets Sent"`
|
||||
AccessServerResetTime float64 `perfdata:"Server Reset Time"`
|
||||
AccessServerUpTime float64 `perfdata:"Server Up Time"`
|
||||
AccessUnknownType float64 `perfdata:"Unknown Type"`
|
||||
}
|
||||
|
||||
type perfDataCounterValuesAccounting struct {
|
||||
// NPS Accounting Server
|
||||
AccountingRequests float64 `perfdata:"Accounting-Requests"`
|
||||
AccountingResponses float64 `perfdata:"Accounting-Responses"`
|
||||
AccountingBadAuthenticators float64 `perfdata:"Bad Authenticators"`
|
||||
AccountingDroppedPackets float64 `perfdata:"Dropped Packets"`
|
||||
AccountingInvalidRequests float64 `perfdata:"Invalid Requests"`
|
||||
AccountingMalformedPackets float64 `perfdata:"Malformed Packets"`
|
||||
AccountingNoRecord float64 `perfdata:"No Record"`
|
||||
AccountingPacketsReceived float64 `perfdata:"Packets Received"`
|
||||
AccountingPacketsSent float64 `perfdata:"Packets Sent"`
|
||||
AccountingServerResetTime float64 `perfdata:"Server Reset Time"`
|
||||
AccountingServerUpTime float64 `perfdata:"Server Up Time"`
|
||||
AccountingUnknownType float64 `perfdata:"Unknown Type"`
|
||||
}
|
||||
Reference in New Issue
Block a user