2022-01-02 06:24:11 +00:00
|
|
|
//go:build windows
|
|
|
|
|
2023-11-04 19:51:35 +00:00
|
|
|
package adcs
|
2022-01-02 06:24:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-09-28 11:23:08 +00:00
|
|
|
"fmt"
|
2024-09-10 22:34:10 +00:00
|
|
|
"log/slog"
|
2023-04-22 10:17:51 +00:00
|
|
|
|
2023-11-04 19:51:35 +00:00
|
|
|
"github.com/alecthomas/kingpin/v2"
|
2024-11-03 16:23:26 +00:00
|
|
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
2024-10-03 18:23:56 +00:00
|
|
|
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
2024-10-03 18:34:45 +00:00
|
|
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
2024-10-03 18:23:56 +00:00
|
|
|
"github.com/prometheus-community/windows_exporter/internal/utils"
|
2023-04-22 10:17:51 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2022-01-02 06:24:11 +00:00
|
|
|
)
|
|
|
|
|
2023-11-04 19:51:35 +00:00
|
|
|
const Name = "adcs"
|
|
|
|
|
|
|
|
type Config struct{}
|
|
|
|
|
|
|
|
var ConfigDefaults = Config{}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
type Collector struct {
|
2024-08-11 11:28:39 +00:00
|
|
|
config Config
|
2023-04-22 10:17:51 +00:00
|
|
|
|
2024-11-17 20:51:12 +00:00
|
|
|
perfDataCollector *perfdata.Collector
|
2024-09-28 11:23:08 +00:00
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
challengeResponseProcessingTime *prometheus.Desc
|
|
|
|
challengeResponsesPerSecond *prometheus.Desc
|
|
|
|
failedRequestsPerSecond *prometheus.Desc
|
|
|
|
issuedRequestsPerSecond *prometheus.Desc
|
|
|
|
pendingRequestsPerSecond *prometheus.Desc
|
|
|
|
requestCryptographicSigningTime *prometheus.Desc
|
|
|
|
requestPolicyModuleProcessingTime *prometheus.Desc
|
|
|
|
requestProcessingTime *prometheus.Desc
|
|
|
|
requestsPerSecond *prometheus.Desc
|
|
|
|
retrievalProcessingTime *prometheus.Desc
|
|
|
|
retrievalsPerSecond *prometheus.Desc
|
|
|
|
signedCertificateTimestampListProcessingTime *prometheus.Desc
|
|
|
|
signedCertificateTimestampListsPerSecond *prometheus.Desc
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|
|
|
|
|
2024-08-24 17:14:38 +00:00
|
|
|
func New(config *Config) *Collector {
|
2024-08-11 11:28:39 +00:00
|
|
|
if config == nil {
|
|
|
|
config = &ConfigDefaults
|
|
|
|
}
|
|
|
|
|
|
|
|
c := &Collector{
|
|
|
|
config: *config,
|
|
|
|
}
|
|
|
|
|
2023-11-04 19:51:35 +00:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
|
|
|
return &Collector{}
|
2023-11-04 19:51:35 +00:00
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
func (c *Collector) GetName() string {
|
2023-11-04 19:51:35 +00:00
|
|
|
return Name
|
|
|
|
}
|
|
|
|
|
2024-11-17 20:51:12 +00:00
|
|
|
func (c *Collector) Close() error {
|
|
|
|
c.perfDataCollector.Close()
|
2024-11-15 18:34:00 +00:00
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-11-03 16:23:26 +00:00
|
|
|
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
2024-11-17 20:51:12 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
c.perfDataCollector, err = perfdata.NewCollector("Certification Authority", perfdata.InstanceAll, []string{
|
|
|
|
requestsPerSecond,
|
|
|
|
requestProcessingTime,
|
|
|
|
retrievalsPerSecond,
|
|
|
|
retrievalProcessingTime,
|
|
|
|
failedRequestsPerSecond,
|
|
|
|
issuedRequestsPerSecond,
|
|
|
|
pendingRequestsPerSecond,
|
|
|
|
requestCryptographicSigningTime,
|
|
|
|
requestPolicyModuleProcessingTime,
|
|
|
|
challengeResponsesPerSecond,
|
|
|
|
challengeResponseProcessingTime,
|
|
|
|
signedCertificateTimestampListsPerSecond,
|
|
|
|
signedCertificateTimestampListProcessingTime,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create Certification Authority collector: %w", err)
|
2024-09-28 11:23:08 +00:00
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestsPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestProcessingTime = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "request_processing_time_seconds"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Last time elapsed for certificate requests",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.retrievalsPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "retrievals_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total certificate retrieval requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.retrievalProcessingTime = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "retrievals_processing_time_seconds"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Last time elapsed for certificate retrieval request",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.failedRequestsPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "failed_requests_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total failed certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.issuedRequestsPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "issued_requests_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total issued certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.pendingRequestsPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "pending_requests_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total pending certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestCryptographicSigningTime = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "request_cryptographic_signing_time_seconds"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Last time elapsed for signing operation request",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestPolicyModuleProcessingTime = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "request_policy_module_processing_time_seconds"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Last time elapsed for policy module processing request",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.challengeResponsesPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "challenge_responses_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total certificate challenge responses processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.challengeResponseProcessingTime = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "challenge_response_processing_time_seconds"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Last time elapsed for challenge response",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.signedCertificateTimestampListsPerSecond = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_lists_total"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Total Signed Certificate Timestamp Lists processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.signedCertificateTimestampListProcessingTime = prometheus.NewDesc(
|
2024-10-03 18:34:45 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_list_processing_time_seconds"),
|
2023-11-04 19:51:35 +00:00
|
|
|
"Last time elapsed for Signed Certificate Timestamp List",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
|
|
|
|
return nil
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|
|
|
|
|
2024-11-17 20:51:12 +00:00
|
|
|
func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
2024-10-03 19:24:17 +00:00
|
|
|
perfData, err := c.perfDataCollector.Collect()
|
2024-09-28 11:23:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to collect Certification Authority (ADCS) metrics: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-10-03 19:24:17 +00:00
|
|
|
if len(perfData) == 0 {
|
2024-09-28 11:23:08 +00:00
|
|
|
return errors.New("perflib query for Certification Authority (ADCS) returned empty result set")
|
|
|
|
}
|
|
|
|
|
2024-10-03 19:24:17 +00:00
|
|
|
for name, data := range perfData {
|
2024-09-28 11:23:08 +00:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.requestsPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[requestsPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.requestProcessingTime,
|
|
|
|
prometheus.GaugeValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
utils.MilliSecToSec(data[requestProcessingTime].FirstValue),
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.retrievalsPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[retrievalsPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.retrievalProcessingTime,
|
|
|
|
prometheus.GaugeValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
utils.MilliSecToSec(data[retrievalProcessingTime].FirstValue),
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.failedRequestsPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[failedRequestsPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.issuedRequestsPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[issuedRequestsPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.pendingRequestsPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[pendingRequestsPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.requestCryptographicSigningTime,
|
|
|
|
prometheus.GaugeValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
utils.MilliSecToSec(data[requestCryptographicSigningTime].FirstValue),
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.requestPolicyModuleProcessingTime,
|
|
|
|
prometheus.GaugeValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
utils.MilliSecToSec(data[requestPolicyModuleProcessingTime].FirstValue),
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.challengeResponsesPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[challengeResponsesPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.challengeResponseProcessingTime,
|
|
|
|
prometheus.GaugeValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
utils.MilliSecToSec(data[challengeResponseProcessingTime].FirstValue),
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.signedCertificateTimestampListsPerSecond,
|
|
|
|
prometheus.CounterValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
data[signedCertificateTimestampListsPerSecond].FirstValue,
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.signedCertificateTimestampListProcessingTime,
|
|
|
|
prometheus.GaugeValue,
|
2024-10-03 19:24:17 +00:00
|
|
|
utils.MilliSecToSec(data[signedCertificateTimestampListProcessingTime].FirstValue),
|
2024-09-28 11:23:08 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|