2024-11-17 20:51:12 +00:00
|
|
|
//go:build windows
|
|
|
|
|
2024-10-12 16:09:05 +00:00
|
|
|
package exchange
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
2024-11-20 01:05:31 +00:00
|
|
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
2024-10-12 16:09:05 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Collector) buildAutoDiscover() error {
|
|
|
|
counters := []string{
|
|
|
|
requestsPerSec,
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2024-11-24 12:18:14 +00:00
|
|
|
c.perfDataCollectorAutoDiscover, err = perfdata.NewCollector("MSExchange Autodiscover", perfdata.InstancesAll, counters)
|
2024-10-12 16:09:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create MSExchange Autodiscover collector: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-11-20 01:05:31 +00:00
|
|
|
c.autoDiscoverRequestsPerSec = prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(types.Namespace, Name, "autodiscover_requests_total"),
|
|
|
|
"Number of autodiscover service requests processed each second",
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
|
2024-10-12 16:09:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-11-17 20:51:12 +00:00
|
|
|
func (c *Collector) collectAutoDiscover(ch chan<- prometheus.Metric) error {
|
2024-10-12 16:09:05 +00:00
|
|
|
perfData, err := c.perfDataCollectorAutoDiscover.Collect()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to collect MSExchange Autodiscover metrics: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(perfData) == 0 {
|
|
|
|
return errors.New("perflib query for MSExchange Autodiscover returned empty result set")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, data := range perfData {
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.autoDiscoverRequestsPerSec,
|
|
|
|
prometheus.CounterValue,
|
|
|
|
data[requestsPerSec].FirstValue,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|