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"
|
|
|
|
"strings"
|
2023-04-22 10:17:51 +00:00
|
|
|
|
2023-11-04 19:51:35 +00:00
|
|
|
"github.com/alecthomas/kingpin/v2"
|
2023-04-22 10:17:51 +00:00
|
|
|
"github.com/go-kit/log"
|
|
|
|
"github.com/go-kit/log/level"
|
2023-11-04 19:51:35 +00:00
|
|
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
|
|
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
|
|
"github.com/prometheus-community/windows_exporter/pkg/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 {
|
2023-04-22 10:17:51 +00:00
|
|
|
logger log.Logger
|
|
|
|
|
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-05 13:50:41 +00:00
|
|
|
func New(logger log.Logger, _ *Config) *Collector {
|
|
|
|
c := &Collector{}
|
2023-11-04 19:51:35 +00:00
|
|
|
c.SetLogger(logger)
|
2024-08-05 13:50:41 +00:00
|
|
|
|
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-08-05 13:50:41 +00:00
|
|
|
func (c *Collector) SetLogger(logger log.Logger) {
|
2023-11-04 19:51:35 +00:00
|
|
|
c.logger = log.With(logger, "collector", Name)
|
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
2023-11-04 19:51:35 +00:00
|
|
|
return []string{"Certification Authority"}, nil
|
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
func (c *Collector) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Collector) Build() error {
|
|
|
|
c.requestsPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
|
|
|
"Total certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestProcessingTime = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "request_processing_time_seconds"),
|
|
|
|
"Last time elapsed for certificate requests",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.retrievalsPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "retrievals_total"),
|
|
|
|
"Total certificate retrieval requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.retrievalProcessingTime = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "retrievals_processing_time_seconds"),
|
|
|
|
"Last time elapsed for certificate retrieval request",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.failedRequestsPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "failed_requests_total"),
|
|
|
|
"Total failed certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.issuedRequestsPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "issued_requests_total"),
|
|
|
|
"Total issued certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.pendingRequestsPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "pending_requests_total"),
|
|
|
|
"Total pending certificate requests processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestCryptographicSigningTime = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "request_cryptographic_signing_time_seconds"),
|
|
|
|
"Last time elapsed for signing operation request",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestPolicyModuleProcessingTime = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "request_policy_module_processing_time_seconds"),
|
|
|
|
"Last time elapsed for policy module processing request",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.challengeResponsesPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "challenge_responses_total"),
|
|
|
|
"Total certificate challenge responses processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.challengeResponseProcessingTime = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "challenge_response_processing_time_seconds"),
|
|
|
|
"Last time elapsed for challenge response",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.signedCertificateTimestampListsPerSecond = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_lists_total"),
|
|
|
|
"Total Signed Certificate Timestamp Lists processed",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
2024-08-05 13:50:41 +00:00
|
|
|
c.signedCertificateTimestampListProcessingTime = prometheus.NewDesc(
|
2023-11-04 19:51:35 +00:00
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_list_processing_time_seconds"),
|
|
|
|
"Last time elapsed for Signed Certificate Timestamp List",
|
|
|
|
[]string{"cert_template"},
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
|
|
|
|
return nil
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
2024-05-11 10:05:45 +00:00
|
|
|
if err := c.collectADCSCounters(ctx, ch); err != nil {
|
|
|
|
_ = level.Error(c.logger).Log("msg", "failed collecting ADCS metrics", "err", err)
|
2022-01-02 06:24:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type perflibADCS struct {
|
|
|
|
Name string
|
|
|
|
RequestsPerSecond float64 `perflib:"Requests/sec"`
|
|
|
|
RequestProcessingTime float64 `perflib:"Request processing time (ms)"`
|
|
|
|
RetrievalsPerSecond float64 `perflib:"Retrievals/sec"`
|
|
|
|
RetrievalProcessingTime float64 `perflib:"Retrieval processing time (ms)"`
|
|
|
|
FailedRequestsPerSecond float64 `perflib:"Failed Requests/sec"`
|
|
|
|
IssuedRequestsPerSecond float64 `perflib:"Issued Requests/sec"`
|
|
|
|
PendingRequestsPerSecond float64 `perflib:"Pending Requests/sec"`
|
|
|
|
RequestCryptographicSigningTime float64 `perflib:"Request cryptographic signing time (ms)"`
|
|
|
|
RequestPolicyModuleProcessingTime float64 `perflib:"Request policy module processing time (ms)"`
|
|
|
|
ChallengeResponsesPerSecond float64 `perflib:"Challenge Responses/sec"`
|
|
|
|
ChallengeResponseProcessingTime float64 `perflib:"Challenge Response processing time (ms)"`
|
|
|
|
SignedCertificateTimestampListsPerSecond float64 `perflib:"Signed Certificate Timestamp Lists/sec"`
|
|
|
|
SignedCertificateTimestampListProcessingTime float64 `perflib:"Signed Certificate Timestamp List processing time (ms)"`
|
|
|
|
}
|
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
func (c *Collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
2022-01-02 06:24:11 +00:00
|
|
|
dst := make([]perflibADCS, 0)
|
2023-11-04 19:51:35 +00:00
|
|
|
if _, ok := ctx.PerfObjects["Certification Authority"]; !ok {
|
2024-05-11 10:05:45 +00:00
|
|
|
return errors.New("perflib did not contain an entry for Certification Authority")
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|
2023-11-04 19:51:35 +00:00
|
|
|
err := perflib.UnmarshalObject(ctx.PerfObjects["Certification Authority"], &dst, c.logger)
|
2022-01-02 06:24:11 +00:00
|
|
|
if err != nil {
|
2024-05-11 10:05:45 +00:00
|
|
|
return err
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|
|
|
|
if len(dst) == 0 {
|
2024-05-11 10:05:45 +00:00
|
|
|
return errors.New("perflib query for Certification Authority (ADCS) returned empty result set")
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, d := range dst {
|
|
|
|
n := strings.ToLower(d.Name)
|
|
|
|
if n == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestsPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.RequestsPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestProcessingTime,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.GaugeValue,
|
2023-11-04 19:51:35 +00:00
|
|
|
utils.MilliSecToSec(d.RequestProcessingTime),
|
2022-01-02 06:24:11 +00:00
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.retrievalsPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.RetrievalsPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.retrievalProcessingTime,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.GaugeValue,
|
2023-11-04 19:51:35 +00:00
|
|
|
utils.MilliSecToSec(d.RetrievalProcessingTime),
|
2022-01-02 06:24:11 +00:00
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.failedRequestsPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.FailedRequestsPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.issuedRequestsPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.IssuedRequestsPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.pendingRequestsPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.PendingRequestsPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestCryptographicSigningTime,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.GaugeValue,
|
2023-11-04 19:51:35 +00:00
|
|
|
utils.MilliSecToSec(d.RequestCryptographicSigningTime),
|
2022-01-02 06:24:11 +00:00
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.requestPolicyModuleProcessingTime,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.GaugeValue,
|
2023-11-04 19:51:35 +00:00
|
|
|
utils.MilliSecToSec(d.RequestPolicyModuleProcessingTime),
|
2022-01-02 06:24:11 +00:00
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.challengeResponsesPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.ChallengeResponsesPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.challengeResponseProcessingTime,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.GaugeValue,
|
2023-11-04 19:51:35 +00:00
|
|
|
utils.MilliSecToSec(d.ChallengeResponseProcessingTime),
|
2022-01-02 06:24:11 +00:00
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.signedCertificateTimestampListsPerSecond,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.CounterValue,
|
|
|
|
d.SignedCertificateTimestampListsPerSecond,
|
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2024-08-05 13:50:41 +00:00
|
|
|
c.signedCertificateTimestampListProcessingTime,
|
2022-01-02 06:24:11 +00:00
|
|
|
prometheus.GaugeValue,
|
2023-11-04 19:51:35 +00:00
|
|
|
utils.MilliSecToSec(d.SignedCertificateTimestampListProcessingTime),
|
2022-01-02 06:24:11 +00:00
|
|
|
d.Name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-11 10:05:45 +00:00
|
|
|
return nil
|
2022-01-02 06:24:11 +00:00
|
|
|
}
|