chore: enable more linter (#1557)

This commit is contained in:
Jan-Otto Kröpke
2024-08-10 22:05:33 +02:00
committed by GitHub
parent 27a3553dac
commit 9b02e4a0ea
87 changed files with 337 additions and 494 deletions

View File

@@ -19,7 +19,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DirectoryServices_DirectoryServices metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DirectoryServices_DirectoryServices metrics.
type Collector struct {
logger log.Logger

View File

@@ -18,7 +18,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for Perflib Cache metrics
// A Collector is a Prometheus Collector for Perflib Cache metrics.
type Collector struct {
logger log.Logger
@@ -258,7 +258,7 @@ func (c *Collector) Build() error {
return nil
}
// Collect implements the Collector interface
// Collect implements the Collector interface.
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if err := c.collect(ctx, ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cache metrics", "err", err)

View File

@@ -69,7 +69,7 @@ import (
"github.com/prometheus-community/windows_exporter/pkg/types"
)
// NewWithFlags To be called by the exporter for collector initialization before running kingpin.Parse
// NewWithFlags To be called by the exporter for collector initialization before running kingpin.Parse.
func NewWithFlags(app *kingpin.Application) Collectors {
collectors := map[string]Collector{}
@@ -195,7 +195,7 @@ func (c *Collectors) SetPerfCounterQuery() error {
return nil
}
// Enable removes all collectors that not enabledCollectors
// Enable removes all collectors that not enabledCollectors.
func (c *Collectors) Enable(enabledCollectors []string) {
for name := range c.collectors {
if !slices.Contains(enabledCollectors, name) {
@@ -204,7 +204,7 @@ func (c *Collectors) Enable(enabledCollectors []string) {
}
}
// Build To be called by the exporter for collector initialization
// Build To be called by the exporter for collector initialization.
func (c *Collectors) Build() error {
var err error
@@ -217,7 +217,7 @@ func (c *Collectors) Build() error {
return nil
}
// PrepareScrapeContext creates a ScrapeContext to be used during a single scrape
// PrepareScrapeContext creates a ScrapeContext to be used during a single scrape.
func (c *Collectors) PrepareScrapeContext() (*types.ScrapeContext, error) {
objs, err := perflib.GetPerflibSnapshot(c.perfCounterQuery)
if err != nil {
@@ -227,7 +227,7 @@ func (c *Collectors) PrepareScrapeContext() (*types.ScrapeContext, error) {
return &types.ScrapeContext{PerfObjects: objs}, nil
}
// Close To be called by the exporter for collector cleanup
// Close To be called by the exporter for collector cleanup.
func (c *Collectors) Close() error {
errs := make([]error, 0, len(c.collectors))

View File

@@ -70,7 +70,7 @@ type Config struct {
Cs cs.Config `yaml:"cs"`
DFSR dfsr.Config `yaml:"dfsr"`
Dhcp dhcp.Config `yaml:"dhcp"`
DiskDrive diskdrive.Config `yaml:"diskdrive"`
DiskDrive diskdrive.Config `yaml:"diskdrive"` //nolint:tagliatelle
DNS dns.Config `yaml:"dns"`
Exchange exchange.Config `yaml:"exchange"`
Fsrmquota fsrmquota.Config `yaml:"fsrmquota"`
@@ -84,7 +84,7 @@ type Config struct {
MsclusterNetwork mscluster_network.Config `yaml:"mscluster_network"`
MsclusterNode mscluster_node.Config `yaml:"mscluster_node"`
MsclusterResource mscluster_resource.Config `yaml:"mscluster_resource"`
MsclusterResourceGroup mscluster_resourcegroup.Config `yaml:"mscluster_resourcegroup"`
MsclusterResourceGroup mscluster_resourcegroup.Config `yaml:"mscluster_resourcegroup"` //nolint:tagliatelle
Msmq msmq.Config `yaml:"msmq"`
Mssql mssql.Config `yaml:"mssql"`
Net net.Config `yaml:"net"`
@@ -105,7 +105,7 @@ type Config struct {
ScheduledTask scheduled_task.Config `yaml:"scheduled_task"`
Service service.Config `yaml:"service"`
SMB smb.Config `yaml:"smb"`
SMBClient smbclient.Config `yaml:"smbclient"`
SMBClient smbclient.Config `yaml:"smbclient"` //nolint:tagliatelle
SMTP smtp.Config `yaml:"smtp"`
System system.Config `yaml:"system"`
TeradiciPcoip teradici_pcoip.Config `yaml:"teradici_pcoip"`

View File

@@ -20,7 +20,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for containers metrics
// A Collector is a Prometheus Collector for containers metrics.
type Collector struct {
logger log.Logger
@@ -55,7 +55,7 @@ type Collector struct {
writeSizeBytes *prometheus.Desc
}
// New constructs a new Collector
// New constructs a new Collector.
func New(logger log.Logger, _ *Config) *Collector {
c := &Collector{}
c.SetLogger(logger)
@@ -205,7 +205,7 @@ func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
return nil
}
// containerClose closes the container resource
// containerClose closes the container resource.
func (c *Collector) containerClose(container hcsshim.Container) {
err := container.Close()
if err != nil {

View File

@@ -25,7 +25,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_Processor
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_Processor.
type Collector struct {
logger log.Logger
@@ -62,7 +62,7 @@ func (c *Collector) Close() error {
func (c *Collector) Build() error {
c.cpuInfo = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, "", Name),
"Labelled CPU information as provided provided by Win32_Processor",
"Labelled CPU information as provided by Win32_Processor",
[]string{
"architecture",
"device_id",

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI metrics
// A Collector is a Prometheus Collector for WMI metrics.
type Collector struct {
logger log.Logger

View File

@@ -82,7 +82,7 @@ type Collector struct {
type dfsrCollectorFunc func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error
// Map Perflib sources to DFSR Collector names
// e.g, volume -> DFS Replication Service Volumes
// e.g, volume -> DFS Replication Service Volumes.
func dfsrGetPerfObjectName(collector string) string {
prefix := "DFS "
suffix := ""
@@ -113,7 +113,7 @@ func New(logger log.Logger, config *Config) *Collector {
func NewWithFlags(app *kingpin.Application) *Collector {
return &Collector{
dfsrEnabledCollectors: app.
Flag("collectors.dfsr.sources-enabled", "Comma-seperated list of DFSR Perflib sources to use.").
Flag("collectors.dfsr.sources-enabled", "Comma-separated list of DFSR Perflib sources to use.").
Default(ConfigDefaults.EnabledCollectors).
String(),
}
@@ -441,7 +441,7 @@ func (c *Collector) Build() error {
}
// Maps enabled child collectors names to their relevant collection function,
// for use in Collector.Collect()
// for use in Collector.Collect().
func (c *Collector) getDFSRChildCollectors(enabledCollectors []string) []dfsrCollectorFunc {
var dfsrCollectors []dfsrCollectorFunc
for _, collector := range enabledCollectors {
@@ -470,7 +470,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
return nil
}
// PerflibDFSRConnection Perflib: "DFS Replication Service Connections"
// PerflibDFSRConnection Perflib: "DFS Replication Service Connections".
type PerflibDFSRConnection struct {
Name string
@@ -558,7 +558,7 @@ func (c *Collector) collectConnection(ctx *types.ScrapeContext, ch chan<- promet
return nil
}
// perflibDFSRFolder Perflib: "DFS Replicated Folder"
// perflibDFSRFolder Perflib: "DFS Replicated Folder".
type perflibDFSRFolder struct {
Name string
@@ -790,7 +790,7 @@ func (c *Collector) collectFolder(ctx *types.ScrapeContext, ch chan<- prometheus
return nil
}
// perflibDFSRVolume Perflib: "DFS Replication Service Volumes"
// perflibDFSRVolume Perflib: "DFS Replication Service Volumes".
type perflibDFSRVolume struct {
Name string

View File

@@ -16,7 +16,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector perflib DHCP metrics
// A Collector is a Prometheus Collector perflib DHCP metrics.
type Collector struct {
logger log.Logger

View File

@@ -23,7 +23,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_DiskDrive
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_DiskDrive.
type Collector struct {
logger log.Logger
@@ -177,10 +177,10 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
c.diskInfo,
prometheus.GaugeValue,
1.0,
strings.Trim(disk.DeviceID, "\\.\\"),
strings.Trim(disk.DeviceID, "\\.\\"), //nolint:staticcheck
strings.TrimRight(disk.Model, " "),
strings.TrimRight(disk.Caption, " "),
strings.TrimRight(disk.Name, "\\.\\"),
strings.TrimRight(disk.Name, "\\.\\"), //nolint:staticcheck
)
for _, status := range allDiskStatus {
@@ -193,7 +193,7 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
c.status,
prometheus.GaugeValue,
isCurrentState,
strings.Trim(disk.Name, "\\.\\"),
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
status,
)
}
@@ -202,14 +202,14 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
c.size,
prometheus.GaugeValue,
float64(disk.Size),
strings.Trim(disk.Name, "\\.\\"),
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
)
ch <- prometheus.MustNewConstMetric(
c.partitions,
prometheus.GaugeValue,
float64(disk.Partitions),
strings.Trim(disk.Name, "\\.\\"),
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
)
for availNum, val := range availMap {
@@ -221,7 +221,7 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
c.availability,
prometheus.GaugeValue,
isCurrentState,
strings.Trim(disk.Name, "\\.\\"),
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
val,
)
}

View File

@@ -19,7 +19,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics.
type Collector struct {
logger log.Logger

View File

@@ -75,7 +75,7 @@ type Collector struct {
enabledCollectors []string
}
// All available Collector functions
// All available Collector functions.
var exchangeAllCollectorNames = []string{
"ADAccessProcesses",
"TransportQueues",
@@ -189,7 +189,7 @@ func (c *Collector) Build() error {
c.yieldedTasks = desc("workload_yielded_tasks", "The total number of tasks that have been yielded by a workload", "name")
c.isActive = desc("workload_is_active", "Active indicates whether the workload is in an active (1) or paused (0) state", "name")
c.activeSyncRequestsPerSec = desc("activesync_requests_total", "Num HTTP requests received from the client via ASP.NET per sec. Shows Current user load")
c.averageCASProcessingLatency = desc("http_proxy_avg_cas_proccessing_latency_sec", "Average latency (sec) of CAS processing time over the last 200 reqs", "name")
c.averageCASProcessingLatency = desc("http_proxy_avg_cas_processing_latency_sec", "Average latency (sec) of CAS processing time over the last 200 reqs", "name")
c.mailboxServerProxyFailureRate = desc("http_proxy_mailbox_proxy_failure_rate", "% of failures between this CAS and MBX servers over the last 200 samples", "name")
c.pingCommandsPending = desc("activesync_ping_cmds_pending", "Number of ping commands currently pending in the queue")
c.syncCommandsPerSec = desc("activesync_sync_cmds_total", "Number of sync commands processed per second. Clients use this command to synchronize items within a folder")
@@ -220,9 +220,7 @@ func (c *Collector) Build() error {
}
if utils.IsEmpty(c.exchangeCollectorsEnabled) {
for _, collectorName := range exchangeAllCollectorNames {
c.enabledCollectors = append(c.enabledCollectors, collectorName)
}
c.enabledCollectors = append(c.enabledCollectors, exchangeAllCollectorNames...)
} else {
for _, collectorName := range strings.Split(*c.exchangeCollectorsEnabled, ",") {
if slices.Contains(exchangeAllCollectorNames, collectorName) {
@@ -236,7 +234,7 @@ func (c *Collector) Build() error {
return nil
}
// Collect collects exchange metrics and sends them to prometheus
// Collect collects exchange metrics and sends them to prometheus.
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
"ADAccessProcesses": c.collectADAccessProcesses,
@@ -260,7 +258,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
return nil
}
// Perflib: [19108] MSExchange ADAccess Processes
// Perflib: [19108] MSExchange ADAccess Processes.
type perflibADAccessProcesses struct {
Name string
@@ -324,7 +322,7 @@ func (c *Collector) collectADAccessProcesses(ctx *types.ScrapeContext, ch chan<-
return nil
}
// Perflib: [24914] MSExchange Availability Service
// Perflib: [24914] MSExchange Availability Service.
type perflibAvailabilityService struct {
RequestsSec float64 `perflib:"Availability Requests (sec)"`
}
@@ -345,7 +343,7 @@ func (c *Collector) collectAvailabilityService(ctx *types.ScrapeContext, ch chan
return nil
}
// Perflib: [36934] MSExchange HttpProxy
// Perflib: [36934] MSExchange HttpProxy.
type perflibHTTPProxy struct {
Name string
@@ -405,7 +403,7 @@ func (c *Collector) collectHTTPProxy(ctx *types.ScrapeContext, ch chan<- prometh
return nil
}
// Perflib: [24618] MSExchange OWA
// Perflib: [24618] MSExchange OWA.
type perflibOWA struct {
CurrentUniqueUsers float64 `perflib:"Current Unique Users"`
RequestsPerSec float64 `perflib:"Requests/sec"`
@@ -432,7 +430,7 @@ func (c *Collector) collectOWA(ctx *types.ScrapeContext, ch chan<- prometheus.Me
return nil
}
// Perflib: [25138] MSExchange ActiveSync
// Perflib: [25138] MSExchange ActiveSync.
type perflibActiveSync struct {
RequestsPerSec float64 `perflib:"Requests/sec"`
PingCommandsPending float64 `perflib:"Ping Commands Pending"`
@@ -465,7 +463,7 @@ func (c *Collector) collectActiveSync(ctx *types.ScrapeContext, ch chan<- promet
return nil
}
// Perflib: [29366] MSExchange RpcClientAccess
// Perflib: [29366] MSExchange RpcClientAccess.
type perflibRPCClientAccess struct {
RPCAveragedLatency float64 `perflib:"RPC Averaged Latency"`
RPCRequests float64 `perflib:"RPC Requests"`
@@ -517,7 +515,7 @@ func (c *Collector) collectRPC(ctx *types.ScrapeContext, ch chan<- prometheus.Me
return nil
}
// Perflib: [20524] MSExchangeTransport Queues
// Perflib: [20524] MSExchangeTransport Queues.
type perflibTransportQueues struct {
Name string
@@ -594,7 +592,7 @@ func (c *Collector) collectTransportQueues(ctx *types.ScrapeContext, ch chan<- p
return nil
}
// Perflib: [19430] MSExchange WorkloadManagement Workloads
// Perflib: [19430] MSExchange WorkloadManagement Workloads.
type perflibWorkloadManagementWorkloads struct {
Name string
@@ -651,7 +649,7 @@ func (c *Collector) collectWorkloadManagementWorkloads(ctx *types.ScrapeContext,
return nil
}
// [29240] MSExchangeAutodiscover
// [29240] MSExchangeAutodiscover.
type perflibAutodiscover struct {
RequestsPerSec float64 `perflib:"Requests/sec"`
}
@@ -671,7 +669,7 @@ func (c *Collector) collectAutoDiscover(ctx *types.ScrapeContext, ch chan<- prom
return nil
}
// perflib [26463] MSExchange MapiHttp Emsmdb
// perflib [26463] MSExchange MapiHttp Emsmdb.
type perflibMapiHttpEmsmdb struct {
ActiveUserCount float64 `perflib:"Active User Count"`
}
@@ -693,14 +691,14 @@ func (c *Collector) collectMapiHttpEmsmdb(ctx *types.ScrapeContext, ch chan<- pr
return nil
}
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores.
func (c *Collector) toLabelName(name string) string {
s := strings.ReplaceAll(strings.Join(strings.Fields(strings.ToLower(name)), "_"), ".", "_")
s = strings.ReplaceAll(s, "__", "_")
return s
}
// msToSec converts from ms to seconds
// msToSec converts from ms to seconds.
func (c *Collector) msToSec(t float64) float64 {
return t / 1000
}

View File

@@ -55,7 +55,7 @@ func (c *Collectors) BuildServeHTTP(disableExporterMetrics bool, timeoutMargin f
if timeoutSeconds == 0 {
timeoutSeconds = defaultTimeout
}
timeoutSeconds = timeoutSeconds - timeoutMargin
timeoutSeconds -= timeoutMargin
reg := prometheus.NewRegistry()
err, wc := collectorFactory(time.Duration(timeoutSeconds*float64(time.Second)), r.URL.Query()["collect[]"])

View File

@@ -20,7 +20,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// Collector is a Prometheus Collector for hyper-v
// Collector is a Prometheus Collector for hyper-v.
type Collector struct {
logger log.Logger
@@ -810,7 +810,7 @@ func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
return nil
}
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary vm health status
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary vm health status.
type Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary struct {
HealthCritical uint32
HealthOk uint32
@@ -840,7 +840,7 @@ func (c *Collector) collectVmHealth(ch chan<- prometheus.Metric) error {
return nil
}
// Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition ..,
// Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition ..,.
type Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition struct {
Name string
PhysicalPagesAllocated uint64

View File

@@ -987,22 +987,22 @@ type perflibWebService struct {
TotalUnlockRequests float64 `perflib:"Total Unlock Requests"`
}
// Fulfill the hasGetIISName interface
// Fulfill the hasGetIISName interface.
func (p perflibWebService) getIISName() string {
return p.Name
}
// Fulfill the hasGetIISName interface
// Fulfill the hasGetIISName interface.
func (p perflibAPP_POOL_WAS) getIISName() string {
return p.Name
}
// Fulfill the hasGetIISName interface
// Fulfill the hasGetIISName interface.
func (p perflibW3SVC_W3WP) getIISName() string {
return p.Name
}
// Fulfill the hasGetIISName interface
// Fulfill the hasGetIISName interface.
func (p perflibW3SVC_W3WP_IIS8) getIISName() string {
return p.Name
}
@@ -1017,7 +1017,7 @@ type hasGetIISName interface {
// E.G. Given the following list of site names, "Site_B" would be
// discarded, and "Site_B#2" would be kept and presented as "Site_B" in the
// Collector metrics.
// [ "Site_A", "Site_B", "Site_C", "Site_B#2" ]
// [ "Site_A", "Site_B", "Site_C", "Site_B#2" ].
func dedupIISNames[V hasGetIISName](services []V) map[string]V {
// Ensure IIS entry with the highest suffix occurs last
sort.SliceStable(services, func(i, j int) bool {
@@ -1457,13 +1457,13 @@ type perflibW3SVC_W3WP struct {
URICacheFlushesTotal float64 `perflib:"Total Flushed URIs"`
URICacheFlushesTotalKernel float64 `perflib:"Total Flushed URIs"`
URIsFlushedTotalKernel float64 `perflib:"Kernel\: Total Flushed URIs"` //nolint:govet
URIsFlushedTotalKernel float64 `perflib:"Kernel\: Total Flushed URIs"` //nolint:govet,tagalign,staticcheck
URICacheHitsTotal float64 `perflib:"URI Cache Hits"`
URICacheHitsTotalKernel float64 `perflib:"Kernel\: URI Cache Hits"` //nolint:govet
URICacheHitsTotalKernel float64 `perflib:"Kernel\: URI Cache Hits"` //nolint:govet,tagalign,staticcheck
URICacheMissesTotal float64 `perflib:"URI Cache Misses"`
URICacheMissesTotalKernel float64 `perflib:"Kernel\: URI Cache Misses"` //nolint:govet
URICacheMissesTotalKernel float64 `perflib:"Kernel\: URI Cache Misses"` //nolint:govet,tagalign,staticcheck
URIsCached float64 `perflib:"Current URIs Cached"`
URIsCachedKernel float64 `perflib:"Kernel\: Current URIs Cached"` //nolint:govet
URIsCachedKernel float64 `perflib:"Kernel\: Current URIs Cached"` //nolint:govet,tagalign,staticcheck
URIsCachedTotal float64 `perflib:"Total URIs Cached"`
URIsCachedTotalKernel float64 `perflib:"Total URIs Cached"`
URIsFlushedTotal float64 `perflib:"Total Flushed URIs"`

View File

@@ -6,6 +6,8 @@ import (
)
func TestIISDeduplication(t *testing.T) {
t.Parallel()
start := []perflibAPP_POOL_WAS{
{
Name: "foo",

View File

@@ -25,7 +25,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics.
type Collector struct {
logger log.Logger

View File

@@ -31,7 +31,7 @@ var ConfigDefaults = Config{
VolumeExclude: "",
}
// A Collector is a Prometheus Collector for perflib logicalDisk metrics
// A Collector is a Prometheus Collector for perflib logicalDisk metrics.
type Collector struct {
logger log.Logger
@@ -264,7 +264,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
// Win32_PerfRawData_PerfDisk_LogicalDisk docs:
// - https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71) - Win32_PerfRawData_PerfDisk_LogicalDisk class
// - https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference
// - https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference.
type logicalDisk struct {
Name string
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
@@ -478,7 +478,6 @@ func getDiskIDByVolume(rootDrive string) (string, error) {
f, err = windows.CreateFile(
windows.StringToUTF16Ptr(`\\.\`+rootDrive),
0, mode, nil, windows.OPEN_EXISTING, uint32(windows.FILE_ATTRIBUTE_READONLY), 0)
if err != nil {
return "", err
}
@@ -527,7 +526,6 @@ func getVolumeInfo(rootDrive string) (volumeInfo, error) {
err := windows.GetVolumeInformation(volPath, &volBufLabel[0], uint32(len(volBufLabel)),
&volSerialNum, nil, &fsFlags, &volBufType[0], uint32(len(volBufType)))
if err != nil {
if driveType != windows.DRIVE_CDROM && driveType != windows.DRIVE_REMOVABLE {
return volumeInfo{}, err

View File

@@ -19,7 +19,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI metrics
// A Collector is a Prometheus Collector for WMI metrics.
type Collector struct {
logger log.Logger

View File

@@ -20,7 +20,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for perflib Memory metrics
// A Collector is a Prometheus Collector for perflib Memory metrics.
type Collector struct {
logger log.Logger

View File

@@ -14,7 +14,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI MSCluster_Cluster metrics
// A Collector is a Prometheus Collector for WMI MSCluster_Cluster metrics.
type Collector struct {
logger log.Logger

View File

@@ -14,7 +14,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI MSCluster_Network metrics
// A Collector is a Prometheus Collector for WMI MSCluster_Network metrics.
type Collector struct {
logger log.Logger

View File

@@ -14,10 +14,10 @@ type Config struct{}
var ConfigDefaults = Config{}
// Variable used by mscluster_resource and mscluster_resourcegroup
// Variable used by mscluster_resource and mscluster_resourcegroup.
var NodeName []string
// A Collector is a Prometheus Collector for WMI MSCluster_Node metrics
// A Collector is a Prometheus Collector for WMI MSCluster_Node metrics.
type Collector struct {
logger log.Logger

View File

@@ -15,7 +15,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI MSCluster_Resource metrics
// A Collector is a Prometheus Collector for WMI MSCluster_Resource metrics.
type Collector struct {
logger log.Logger

View File

@@ -15,7 +15,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI MSCluster_ResourceGroup metrics
// A Collector is a Prometheus Collector for WMI MSCluster_ResourceGroup metrics.
type Collector struct {
logger log.Logger

View File

@@ -24,7 +24,7 @@ var ConfigDefaults = Config{
QueryWhereClause: "",
}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics.
type Collector struct {
logger log.Logger

View File

@@ -23,7 +23,7 @@ import (
const Name = "mssql"
type Config struct {
EnabledCollectors string `yaml:"collectors_enabled"`
EnabledCollectors string `yaml:"collectors_enabled"` //nolint:tagliatelle
}
var ConfigDefaults = Config{
@@ -126,7 +126,7 @@ func mssqlGetPerfObjectName(sqlInstance string, collector string) string {
return prefix + suffix
}
// A Collector is a Prometheus Collector for various WMI Win32_PerfRawData_MSSQLSERVER_* metrics
// A Collector is a Prometheus Collector for various WMI Win32_PerfRawData_MSSQLSERVER_* metrics.
type Collector struct {
logger log.Logger

View File

@@ -28,7 +28,7 @@ var ConfigDefaults = Config{
var nicNameToUnderscore = regexp.MustCompile("[^a-zA-Z0-9]")
// A Collector is a Prometheus Collector for Perflib Network Interface metrics
// A Collector is a Prometheus Collector for Perflib Network Interface metrics.
type Collector struct {
logger log.Logger

View File

@@ -7,6 +7,8 @@ import (
)
func TestNetworkToInstanceName(t *testing.T) {
t.Parallel()
data := map[string]string{
"Intel[R] Dual Band Wireless-AC 8260": "Intel_R__Dual_Band_Wireless_AC_8260",
}

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// Collector is a Prometheus Collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics
// Collector is a Prometheus Collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics.
type Collector struct {
logger log.Logger
@@ -246,7 +246,7 @@ func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
}
// Win32_PerfRawData_IAS_NPSAuthenticationServer docs:
// at the moment there is no Microsoft documentation
// at the moment there is no Microsoft documentation.
type Win32_PerfRawData_IAS_NPSAuthenticationServer struct {
Name string

View File

@@ -30,7 +30,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI metrics
// A Collector is a Prometheus Collector for WMI metrics.
type Collector struct {
logger log.Logger
@@ -175,7 +175,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
}
// Win32_OperatingSystem docs:
// - https://msdn.microsoft.com/en-us/library/aa394239 - Win32_OperatingSystem class
// - https://msdn.microsoft.com/en-us/library/aa394239 - Win32_OperatingSystem class.
type Win32_OperatingSystem struct {
Caption string
FreePhysicalMemory uint64
@@ -215,11 +215,12 @@ func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
// Get total allocation of paging files across all disks.
memManKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management`, registry.QUERY_VALUE)
defer memManKey.Close()
if err != nil {
return err
}
defer memManKey.Close()
pagingFiles, _, pagingErr := memManKey.GetStringsValue("ExistingPageFiles")
var fsipf float64
@@ -236,12 +237,12 @@ func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
// Get build number and product name from registry
ntKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
defer ntKey.Close()
if err != nil {
return err
}
defer ntKey.Close()
pn, _, err := ntKey.GetStringValue("ProductName")
if err != nil {
return err

View File

@@ -27,7 +27,7 @@ var ConfigDefaults = Config{
DiskExclude: "",
}
// A Collector is a Prometheus Collector for perflib PhysicalDisk metrics
// A Collector is a Prometheus Collector for perflib PhysicalDisk metrics.
type Collector struct {
logger log.Logger
@@ -217,7 +217,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
// PhysicalDisk
// Win32_PerfRawData_PerfDisk_PhysicalDisk docs:
// - https://docs.microsoft.com/en-us/previous-versions/aa394308(v=vs.85) - Win32_PerfRawData_PerfDisk_PhysicalDisk class
// - https://docs.microsoft.com/en-us/previous-versions/aa394308(v=vs.85) - Win32_PerfRawData_PerfDisk_PhysicalDisk class.
type PhysicalDisk struct {
Name string
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`

View File

@@ -26,7 +26,7 @@ const Name = "process"
type Config struct {
ProcessInclude string `yaml:"process_include"`
ProcessExclude string `yaml:"process_exclude"`
EnableWorkerProcess bool `yaml:"enable_iis_worker_process"`
EnableWorkerProcess bool `yaml:"enable_iis_worker_process"` //nolint:tagliatelle
EnableReportOwner bool `yaml:"enable_report_owner"`
}
@@ -488,7 +488,7 @@ func (c *Collector) getProcessOwner(pid int) (string, error) {
}
if err != nil {
return "", fmt.Errorf("OpenProcess: %T %w", err, err)
return "", fmt.Errorf("OpenProcess: %w", err)
}
defer windows.Close(p)

View File

@@ -87,7 +87,7 @@ func (coll *Prometheus) Collect(ch chan<- prometheus.Metric) {
time.Since(t).Seconds(),
)
if err != nil {
ch <- prometheus.NewInvalidMetric(coll.scrapeSuccessDesc, fmt.Errorf("failed to prepare scrape: %v", err))
ch <- prometheus.NewInvalidMetric(coll.scrapeSuccessDesc, fmt.Errorf("failed to prepare scrape: %w", err))
return
}

View File

@@ -423,7 +423,7 @@ func (c *Collector) collectRemoteFXGraphicsCounters(ctx *types.ScrapeContext, ch
return nil
}
// normalizeSessionName ensure that the session is the same between WTS API and performance counters
// normalizeSessionName ensure that the session is the same between WTS API and performance counters.
func normalizeSessionName(sessionName string) string {
return strings.Replace(sessionName, "RDP-tcp", "RDP-Tcp", 1)
}

View File

@@ -225,7 +225,9 @@ const SCHEDULED_TASK_PROGRAM_ID = "Schedule.Service.1"
// S_FALSE is returned by CoInitialize if it was already called on this thread.
const S_FALSE = 0x00000001
func getScheduledTasks() (scheduledTasks ScheduledTasks, err error) {
func getScheduledTasks() (ScheduledTasks, error) {
var scheduledTasks ScheduledTasks
// The only way to run WMI queries in parallel while being thread-safe is to
// ensure the CoInitialize[Ex]() call is bound to its current OS thread.
// Otherwise, attempting to initialize and run parallel queries across
@@ -320,7 +322,9 @@ func fetchTasksRecursively(folder *ole.IDispatch, scheduledTasks *ScheduledTasks
return err
}
func parseTask(task *ole.IDispatch) (scheduledTask ScheduledTask, err error) {
func parseTask(task *ole.IDispatch) (ScheduledTask, error) {
var scheduledTask ScheduledTask
taskNameVar, err := oleutil.GetProperty(task, "Name")
if err != nil {
return scheduledTask, err

View File

@@ -35,7 +35,7 @@ var ConfigDefaults = Config{
V2: false,
}
// A Collector is a Prometheus Collector for WMI Win32_Service metrics
// A Collector is a Prometheus Collector for WMI Win32_Service metrics.
type Collector struct {
logger log.Logger

View File

@@ -38,7 +38,7 @@ type Collector struct {
enabledCollectors []string
}
// All available Collector functions
// All available Collector functions.
var smbAllCollectorNames = []string{
"ServerShares",
}
@@ -121,9 +121,7 @@ func (c *Collector) Build() error {
}
if *c.smbCollectorsEnabled == "" {
for _, collectorName := range smbAllCollectorNames {
c.enabledCollectors = append(c.enabledCollectors, collectorName)
}
c.enabledCollectors = append(c.enabledCollectors, smbAllCollectorNames...)
} else {
for _, collectorName := range strings.Split(*c.smbCollectorsEnabled, ",") {
if slices.Contains(smbAllCollectorNames, collectorName) {
@@ -137,7 +135,7 @@ func (c *Collector) Build() error {
return nil
}
// Collect collects smb metrics and sends them to prometheus
// Collect collects smb metrics and sends them to prometheus.
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
"ServerShares": c.collectServerShares,
@@ -152,7 +150,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
return nil
}
// Perflib: SMB Server Shares
// Perflib: SMB Server Shares.
type perflibServerShares struct {
Name string
@@ -186,7 +184,7 @@ func (c *Collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prom
return nil
}
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores.
func (c *Collector) toLabelName(name string) string {
s := strings.ReplaceAll(strings.Join(strings.Fields(strings.ToLower(name)), "_"), ".", "_")
s = strings.ReplaceAll(s, "__", "_")

View File

@@ -60,7 +60,7 @@ type Collector struct {
requestSecs *prometheus.Desc
}
// All available collector functions
// All available collector functions.
var smbclientAllCollectorNames = []string{
"ClientShares",
}
@@ -224,9 +224,7 @@ func (c *Collector) Build() error {
}
if *c.smbClientCollectorsEnabled == "" {
for _, collectorName := range smbclientAllCollectorNames {
c.enabledCollectors = append(c.enabledCollectors, collectorName)
}
c.enabledCollectors = append(c.enabledCollectors, smbclientAllCollectorNames...)
} else {
for _, collectorName := range strings.Split(*c.smbClientCollectorsEnabled, ",") {
if slices.Contains(smbclientAllCollectorNames, collectorName) {
@@ -240,7 +238,7 @@ func (c *Collector) Build() error {
return nil
}
// Collect collects smb client metrics and sends them to prometheus
// Collect collects smb client metrics and sends them to prometheus.
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
"ClientShares": c.collectClientShares,
@@ -255,7 +253,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
return nil
}
// Perflib: SMB Client Shares
// Perflib: SMB Client Shares.
type perflibClientShares struct {
Name string

View File

@@ -405,7 +405,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
return nil
}
// PerflibSMTPServer Perflib: "SMTP Server"
// PerflibSMTPServer Perflib: "SMTP Server".
type PerflibSMTPServer struct {
Name string

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI metrics
// A Collector is a Prometheus Collector for WMI metrics.
type Collector struct {
logger log.Logger

View File

@@ -17,7 +17,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics.
type Collector struct {
logger log.Logger

View File

@@ -24,7 +24,7 @@ var ConfigDefaults = Config{}
// win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
// win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
// win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
// win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics
// win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics.
type Collector struct {
logger log.Logger

View File

@@ -102,7 +102,6 @@ func (c *Collector) GetPerfCounter() ([]string, error) {
func (c *Collector) Close() error {
err := wtsapi32.WTSCloseServer(c.hServer)
if err != nil {
return fmt.Errorf("failed to close WTS server: %w", err)
}
@@ -434,7 +433,7 @@ func (c *Collector) collectWTSSessions(ch chan<- prometheus.Metric) error {
c.sessionInfo,
prometheus.GaugeValue,
isState,
strings.Replace(session.SessionName, "#", " ", -1),
strings.ReplaceAll(session.SessionName, "#", " "),
userName,
session.HostName,
stateName,

View File

@@ -120,21 +120,21 @@ func (c *Collector) Build() error {
func duplicateMetricEntry(metricFamilies []*dto.MetricFamily) bool {
uniqueMetrics := make(map[string]map[string]string)
for _, metricFamily := range metricFamilies {
metric_name := *metricFamily.Name
for _, metric := range metricFamily.Metric {
metric_labels := metric.GetLabel()
metricName := metricFamily.GetName()
for _, metric := range metricFamily.GetMetric() {
metricLabels := metric.GetLabel()
labels := make(map[string]string)
for _, label := range metric_labels {
for _, label := range metricLabels {
labels[label.GetName()] = label.GetValue()
}
// Check if key is present before appending
_, mapContainsKey := uniqueMetrics[metric_name]
_, mapContainsKey := uniqueMetrics[metricName]
// Duplicate metric found with identical labels & label values
if mapContainsKey == true && reflect.DeepEqual(uniqueMetrics[metric_name], labels) {
if mapContainsKey && reflect.DeepEqual(uniqueMetrics[metricName], labels) {
return true
}
uniqueMetrics[metric_name] = labels
uniqueMetrics[metricName] = labels
}
}
return false
@@ -145,7 +145,7 @@ func (c *Collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
var val float64
allLabelNames := map[string]struct{}{}
for _, metric := range metricFamily.Metric {
for _, metric := range metricFamily.GetMetric() {
labels := metric.GetLabel()
for _, label := range labels {
if _, ok := allLabelNames[label.GetName()]; !ok {
@@ -154,7 +154,7 @@ func (c *Collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
}
}
for _, metric := range metricFamily.Metric {
for _, metric := range metricFamily.GetMetric() {
if metric.TimestampMs != nil {
_ = level.Warn(c.logger).Log("msg", fmt.Sprintf("Ignoring unsupported custom timestamp on textfile Collector metric %v", metric))
}
@@ -175,7 +175,7 @@ func (c *Collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
break
}
}
if present == false {
if !present {
names = append(names, k)
values = append(values, "")
}
@@ -185,44 +185,44 @@ func (c *Collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
switch metricType {
case dto.MetricType_COUNTER:
valType = prometheus.CounterValue
val = metric.Counter.GetValue()
val = metric.GetCounter().GetValue()
case dto.MetricType_GAUGE:
valType = prometheus.GaugeValue
val = metric.Gauge.GetValue()
val = metric.GetGauge().GetValue()
case dto.MetricType_UNTYPED:
valType = prometheus.UntypedValue
val = metric.Untyped.GetValue()
val = metric.GetUntyped().GetValue()
case dto.MetricType_SUMMARY:
quantiles := map[float64]float64{}
for _, q := range metric.Summary.Quantile {
for _, q := range metric.GetSummary().GetQuantile() {
quantiles[q.GetQuantile()] = q.GetValue()
}
ch <- prometheus.MustNewConstSummary(
prometheus.NewDesc(
*metricFamily.Name,
metricFamily.GetName(),
metricFamily.GetHelp(),
names, nil,
),
metric.Summary.GetSampleCount(),
metric.Summary.GetSampleSum(),
metric.GetSummary().GetSampleCount(),
metric.GetSummary().GetSampleSum(),
quantiles, values...,
)
case dto.MetricType_HISTOGRAM:
buckets := map[float64]uint64{}
for _, b := range metric.Histogram.Bucket {
for _, b := range metric.GetHistogram().GetBucket() {
buckets[b.GetUpperBound()] = b.GetCumulativeCount()
}
ch <- prometheus.MustNewConstHistogram(
prometheus.NewDesc(
*metricFamily.Name,
metricFamily.GetName(),
metricFamily.GetHelp(),
names, nil,
),
metric.Histogram.GetSampleCount(),
metric.Histogram.GetSampleSum(),
metric.GetHistogram().GetSampleCount(),
metric.GetHistogram().GetSampleSum(),
buckets, values...,
)
default:
@@ -232,7 +232,7 @@ func (c *Collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
if metricType == dto.MetricType_GAUGE || metricType == dto.MetricType_COUNTER || metricType == dto.MetricType_UNTYPED {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
*metricFamily.Name,
metricFamily.GetName(),
metricFamily.GetHelp(),
names, nil,
),
@@ -266,7 +266,7 @@ type carriageReturnFilteringReader struct {
r io.Reader
}
// Read returns data from the underlying io.Reader, but with \r filtered out
// Read returns data from the underlying io.Reader, but with \r filtered out.
func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
buf := make([]byte, len(p))
n, err := cr.r.Read(buf)
@@ -276,7 +276,7 @@ func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
}
pi := 0
for i := 0; i < n; i++ {
for i := range n {
if buf[i] != '\r' {
p[pi] = buf[i]
pi++
@@ -380,7 +380,7 @@ func scrapeFile(path string, log log.Logger) ([]*dto.MetricFamily, error) {
for _, mf := range parsedFamilies {
families_array = append(families_array, mf)
for _, m := range mf.Metric {
for _, m := range mf.GetMetric() {
if m.TimestampMs != nil {
return nil, errors.New("textfile contains unsupported client-side timestamps")
}

View File

@@ -10,6 +10,8 @@ import (
)
func TestCRFilter(t *testing.T) {
t.Parallel()
sr := strings.NewReader("line 1\r\nline 2")
cr := carriageReturnFilteringReader{r: sr}
b, err := io.ReadAll(cr)
@@ -23,6 +25,8 @@ func TestCRFilter(t *testing.T) {
}
func TestCheckBOM(t *testing.T) {
t.Parallel()
testdata := []struct {
encoding utfbom.Encoding
err string
@@ -49,6 +53,8 @@ func TestCheckBOM(t *testing.T) {
}
func TestDuplicateMetricEntry(t *testing.T) {
t.Parallel()
metric_name := "windows_sometest"
metric_help := "This is a Test."
metric_type := dto.MetricType_GAUGE

View File

@@ -17,6 +17,8 @@ import (
var baseDir = "../../../tools/textfile-test"
func TestMultipleDirectories(t *testing.T) {
t.Parallel()
testDir := baseDir + "/multiple-dirs"
testDirs := fmt.Sprintf("%[1]s/dir1,%[1]s/dir2,%[1]s/dir3", testDir)
@@ -58,6 +60,8 @@ func TestMultipleDirectories(t *testing.T) {
}
func TestDuplicateFileName(t *testing.T) {
t.Parallel()
testDir := baseDir + "/duplicate-filename"
textfileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
TextFileDirectories: testDir,

View File

@@ -19,7 +19,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics.
type Collector struct {
logger log.Logger

View File

@@ -20,7 +20,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// Collector is a Prometheus Collector for Perflib counter metrics
// Collector is a Prometheus Collector for Perflib counter metrics.
type Collector struct {
logger log.Logger
@@ -113,7 +113,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
return nil
}
// Perflib "Windows Time Service"
// Perflib "Windows Time Service".
type windowsTime struct {
ClockFrequencyAdjustmentPPBTotal float64 `perflib:"Clock Frequency Adjustment (ppb)"`
ComputedTimeOffset float64 `perflib:"Computed Time Offset"`

View File

@@ -16,8 +16,10 @@ type Collectors struct {
type Map map[string]Collector
type Builder func(logger log.Logger) Collector
type BuilderWithFlags[C Collector] func(*kingpin.Application) C
type (
Builder func(logger log.Logger) Collector
BuilderWithFlags[C Collector] func(*kingpin.Application) C
)
// Collector interface that a collector has to implement.
type Collector interface {

View File

@@ -20,7 +20,7 @@ type Config struct{}
var ConfigDefaults = Config{}
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics.
type Collector struct {
logger log.Logger