Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Dec 15, 2024
1 parent eea5a50 commit b539494
Show file tree
Hide file tree
Showing 145 changed files with 6,635 additions and 6,325 deletions.
384 changes: 116 additions & 268 deletions internal/collector/ad/ad.go

Large diffs are not rendered by default.

222 changes: 0 additions & 222 deletions internal/collector/ad/const.go

This file was deleted.

223 changes: 223 additions & 0 deletions internal/collector/ad/types.go

Large diffs are not rendered by default.

81 changes: 32 additions & 49 deletions internal/collector/adcs/adcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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-community/windows_exporter/internal/utils"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -37,7 +37,8 @@ var ConfigDefaults = Config{}
type Collector struct {
config Config

perfDataCollector *perfdata.Collector
perfDataCollector *pdh.Collector
perfDataObject []perfDataCounterValues

challengeResponseProcessingTime *prometheus.Desc
challengeResponsesPerSecond *prometheus.Desc
Expand Down Expand Up @@ -83,21 +84,7 @@ func (c *Collector) Close() error {
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
var err error

c.perfDataCollector, err = perfdata.NewCollector("Certification Authority", perfdata.InstancesAll, []string{
requestsPerSecond,
requestProcessingTime,
retrievalsPerSecond,
retrievalProcessingTime,
failedRequestsPerSecond,
issuedRequestsPerSecond,
pendingRequestsPerSecond,
requestCryptographicSigningTime,
requestPolicyModuleProcessingTime,
challengeResponsesPerSecond,
challengeResponseProcessingTime,
signedCertificateTimestampListsPerSecond,
signedCertificateTimestampListProcessingTime,
})
c.perfDataCollector, err = pdh.NewCollector[perfDataCounterValues]("Certification Authority", pdh.InstancesAll)
if err != nil {
return fmt.Errorf("failed to create Certification Authority collector: %w", err)
}
Expand Down Expand Up @@ -185,93 +172,89 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
}

func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
perfData, err := c.perfDataCollector.Collect()
err := c.perfDataCollector.Collect(&c.perfDataObject)
if err != nil {
return fmt.Errorf("failed to collect Certification Authority (ADCS) metrics: %w", err)
}

if len(perfData) == 0 {
return fmt.Errorf("failed to collect Certification Authority (ADCS) metrics: %w", types.ErrNoData)
}

for name, data := range perfData {
for _, data := range c.perfDataObject {
ch <- prometheus.MustNewConstMetric(
c.requestsPerSecond,
prometheus.CounterValue,
data[requestsPerSecond].FirstValue,
name,
data.RequestsPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.requestProcessingTime,
prometheus.GaugeValue,
utils.MilliSecToSec(data[requestProcessingTime].FirstValue),
name,
utils.MilliSecToSec(data.RequestProcessingTime),
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.retrievalsPerSecond,
prometheus.CounterValue,
data[retrievalsPerSecond].FirstValue,
name,
data.RetrievalsPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.retrievalProcessingTime,
prometheus.GaugeValue,
utils.MilliSecToSec(data[retrievalProcessingTime].FirstValue),
name,
utils.MilliSecToSec(data.RetrievalProcessingTime),
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.failedRequestsPerSecond,
prometheus.CounterValue,
data[failedRequestsPerSecond].FirstValue,
name,
data.FailedRequestsPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.issuedRequestsPerSecond,
prometheus.CounterValue,
data[issuedRequestsPerSecond].FirstValue,
name,
data.IssuedRequestsPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.pendingRequestsPerSecond,
prometheus.CounterValue,
data[pendingRequestsPerSecond].FirstValue,
name,
data.PendingRequestsPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.requestCryptographicSigningTime,
prometheus.GaugeValue,
utils.MilliSecToSec(data[requestCryptographicSigningTime].FirstValue),
name,
utils.MilliSecToSec(data.RequestCryptographicSigningTime),
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.requestPolicyModuleProcessingTime,
prometheus.GaugeValue,
utils.MilliSecToSec(data[requestPolicyModuleProcessingTime].FirstValue),
name,
utils.MilliSecToSec(data.RequestPolicyModuleProcessingTime),
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.challengeResponsesPerSecond,
prometheus.CounterValue,
data[challengeResponsesPerSecond].FirstValue,
name,
data.ChallengeResponsesPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.challengeResponseProcessingTime,
prometheus.GaugeValue,
utils.MilliSecToSec(data[challengeResponseProcessingTime].FirstValue),
name,
utils.MilliSecToSec(data.ChallengeResponseProcessingTime),
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.signedCertificateTimestampListsPerSecond,
prometheus.CounterValue,
data[signedCertificateTimestampListsPerSecond].FirstValue,
name,
data.SignedCertificateTimestampListsPerSecond,
data.Name,
)
ch <- prometheus.MustNewConstMetric(
c.signedCertificateTimestampListProcessingTime,
prometheus.GaugeValue,
utils.MilliSecToSec(data[signedCertificateTimestampListProcessingTime].FirstValue),
name,
utils.MilliSecToSec(data.SignedCertificateTimestampListProcessingTime),
data.Name,
)
}

Expand Down
32 changes: 0 additions & 32 deletions internal/collector/adcs/const.go

This file was deleted.

34 changes: 34 additions & 0 deletions internal/collector/adcs/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 adcs

type perfDataCounterValues struct {
Name string

ChallengeResponseProcessingTime float64 `perfdata:"Challenge Response processing time (ms)"`
ChallengeResponsesPerSecond float64 `perfdata:"Challenge Responses/sec"`
FailedRequestsPerSecond float64 `perfdata:"Failed Requests/sec"`
IssuedRequestsPerSecond float64 `perfdata:"Issued Requests/sec"`
PendingRequestsPerSecond float64 `perfdata:"Pending Requests/sec"`
RequestCryptographicSigningTime float64 `perfdata:"Request cryptographic signing time (ms)"`
RequestPolicyModuleProcessingTime float64 `perfdata:"Request policy module processing time (ms)"`
RequestProcessingTime float64 `perfdata:"Request processing time (ms)"`
RequestsPerSecond float64 `perfdata:"Requests/sec"`
RetrievalProcessingTime float64 `perfdata:"Retrieval processing time (ms)"`
RetrievalsPerSecond float64 `perfdata:"Retrievals/sec"`
SignedCertificateTimestampListProcessingTime float64 `perfdata:"Signed Certificate Timestamp List processing time (ms)"`
SignedCertificateTimestampListsPerSecond float64 `perfdata:"Signed Certificate Timestamp Lists/sec"`
}
Loading

0 comments on commit b539494

Please sign in to comment.