2020-06-07 15:40:55 +00:00
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
2023-04-22 10:17:51 +00:00
|
|
|
"github.com/go-kit/log"
|
|
|
|
"github.com/go-kit/log/level"
|
2020-06-07 15:40:55 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2023-03-12 00:27:31 +00:00
|
|
|
"github.com/yusufpapurcu/wmi"
|
2020-06-07 15:40:55 +00:00
|
|
|
)
|
|
|
|
|
2020-06-07 15:55:52 +00:00
|
|
|
type FSRMQuotaCollector struct {
|
2023-04-22 10:17:51 +00:00
|
|
|
logger log.Logger
|
|
|
|
|
2020-06-07 15:55:52 +00:00
|
|
|
QuotasCount *prometheus.Desc
|
|
|
|
Path *prometheus.Desc
|
|
|
|
PeakUsage *prometheus.Desc
|
|
|
|
Size *prometheus.Desc
|
|
|
|
Usage *prometheus.Desc
|
|
|
|
|
|
|
|
Description *prometheus.Desc
|
|
|
|
Disabled *prometheus.Desc
|
|
|
|
MatchesTemplate *prometheus.Desc
|
|
|
|
SoftLimit *prometheus.Desc
|
|
|
|
Template *prometheus.Desc
|
2020-06-07 15:40:55 +00:00
|
|
|
}
|
|
|
|
|
2023-04-22 10:17:51 +00:00
|
|
|
func newFSRMQuotaCollector(logger log.Logger) (Collector, error) {
|
2020-06-07 15:40:55 +00:00
|
|
|
const subsystem = "fsrmquota"
|
|
|
|
return &FSRMQuotaCollector{
|
2023-04-22 10:17:51 +00:00
|
|
|
logger: log.With(logger, "collector", subsystem),
|
|
|
|
|
2020-06-07 15:40:55 +00:00
|
|
|
QuotasCount: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "count"),
|
|
|
|
"Number of Quotas",
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
PeakUsage: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "peak_usage_bytes"),
|
|
|
|
"The highest amount of disk space usage charged to this quota. (PeakUsage)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
Size: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "size_bytes"),
|
|
|
|
"The size of the quota. (Size)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
Usage: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "usage_bytes"),
|
|
|
|
"The current amount of disk space usage charged to this quota. (Usage)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
Description: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "description"),
|
|
|
|
"Description of the quota (Description)",
|
|
|
|
[]string{"path", "template", "description"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
Disabled: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "disabled"),
|
|
|
|
"If 1, the quota is disabled. The default value is 0. (Disabled)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
SoftLimit: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "softlimit"),
|
|
|
|
"If 1, the quota is a soft limit. If 0, the quota is a hard limit. The default value is 0. Optional (SoftLimit)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
Template: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "template"),
|
|
|
|
"Quota template name. (Template)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
MatchesTemplate: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "matchestemplate"),
|
|
|
|
"If 1, the property values of this quota match those values of the template from which it was derived. (MatchesTemplate)",
|
|
|
|
[]string{"path", "template"},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect sends the metric values for each metric
|
|
|
|
// to the provided prometheus Metric channel.
|
|
|
|
func (c *FSRMQuotaCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
|
|
|
|
if desc, err := c.collect(ch); err != nil {
|
2023-06-08 00:29:50 +00:00
|
|
|
_ = level.Error(c.logger).Log("msg", "failed collecting fsrmquota metrics", "desc", desc, "err", err)
|
2020-06-07 15:40:55 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MSFT_FSRMQuota docs:
|
|
|
|
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/fsrm/msft-fsrmquota
|
|
|
|
type MSFT_FSRMQuota struct {
|
|
|
|
Name string
|
|
|
|
|
|
|
|
Path string
|
|
|
|
PeakUsage uint64
|
|
|
|
Size uint64
|
|
|
|
Usage uint64
|
|
|
|
Description string
|
|
|
|
Template string
|
|
|
|
//Threshold string
|
|
|
|
Disabled bool
|
|
|
|
MatchesTemplate bool
|
|
|
|
SoftLimit bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FSRMQuotaCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
|
|
|
var dst []MSFT_FSRMQuota
|
2023-04-22 10:17:51 +00:00
|
|
|
q := queryAll(&dst, c.logger)
|
2020-06-07 15:40:55 +00:00
|
|
|
|
|
|
|
var count int
|
|
|
|
|
|
|
|
if err := wmi.QueryNamespace(q, &dst, "root/microsoft/windows/fsrm"); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, quota := range dst {
|
|
|
|
|
|
|
|
count++
|
|
|
|
path := quota.Path
|
|
|
|
template := quota.Template
|
|
|
|
Description := quota.Description
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.PeakUsage,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(quota.PeakUsage),
|
|
|
|
path,
|
|
|
|
template,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.Size,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(quota.Size),
|
|
|
|
path,
|
|
|
|
template,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.Usage,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(quota.Usage),
|
|
|
|
path,
|
|
|
|
template,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.Description,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
1.0,
|
|
|
|
path, template, Description,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.Disabled,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
boolToFloat(quota.Disabled),
|
|
|
|
path,
|
|
|
|
template,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.MatchesTemplate,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
boolToFloat(quota.MatchesTemplate),
|
|
|
|
path,
|
|
|
|
template,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.SoftLimit,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
boolToFloat(quota.SoftLimit),
|
|
|
|
path,
|
|
|
|
template,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.QuotasCount,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(count),
|
|
|
|
)
|
|
|
|
return nil, nil
|
|
|
|
}
|