Files
windows_exporter/collector/init.go
Ben Reedy 9214a87d0d feat: Remove init functions from collectors
Behaviour of init functions has been centralised in `collector/init.go`,
and can be called during exporter startup. This allows the exporter to
control the timing of collector initialisation, rather than relying on
the import & `init()` method.

This should reduce unexpected behaviour arising from the use of
`init()`, such as #551.

Signed-off-by: Ben Reedy <breed808@breed808.com>
2023-04-01 17:54:40 +10:00

310 lines
7.3 KiB
Go

package collector
// collectorInit represents the required initialisation config for a collector.
type collectorInit struct {
// Name of collector to be initialised
name string
// Builder function for the collector
builder collectorBuilder
// Perflib counter names for the collector.
// These will be included in the Perflib scrape scope by the exporter.
perfCounterNames []string
}
func getCPUCollectorDeps() string {
// See below for 6.05 magic value
if getWindowsVersion() > 6.05 {
return "Processor Information"
}
return "Processor"
}
func getDFSRCollectorDeps() []string {
// Perflib sources are dynamic, depending on the enabled child collectors
var perflibDependencies []string
for _, source := range expandEnabledChildCollectors(*dfsrEnabledCollectors) {
perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source))
}
return perflibDependencies
}
var collectors = []collectorInit{
{
name: "ad",
builder: NewADCollector,
perfCounterNames: nil,
},
{
name: "adcs",
builder: adcsCollectorMethod,
perfCounterNames: []string{"Certification Authority"},
},
{
name: "adfs",
builder: newADFSCollector,
perfCounterNames: []string{"AD FS"},
},
{
name: "cache",
builder: newCacheCollector,
perfCounterNames: []string{"Cache"},
},
{
name: "container",
builder: NewContainerMetricsCollector,
perfCounterNames: nil,
},
{
name: "cpu",
builder: newCPUCollector,
perfCounterNames: []string{getCPUCollectorDeps()},
},
{
name: "cpu_info",
builder: newCpuInfoCollector,
perfCounterNames: nil,
},
{
name: "cs",
builder: NewCSCollector,
perfCounterNames: nil,
},
{
name: "dfsr",
builder: NewDFSRCollector,
perfCounterNames: getDFSRCollectorDeps(),
},
{
name: "dhcp",
builder: NewDhcpCollector,
perfCounterNames: nil,
},
{
name: "disk_drive",
builder: newDiskDriveInfoCollector,
perfCounterNames: nil,
},
{
name: "dns",
builder: NewDNSCollector,
perfCounterNames: nil,
},
{
name: "exchange",
builder: newExchangeCollector,
perfCounterNames: []string{
"MSExchange ADAccess Processes",
"MSExchangeTransport Queues",
"MSExchange HttpProxy",
"MSExchange ActiveSync",
"MSExchange Availability Service",
"MSExchange OWA",
"MSExchangeAutodiscover",
"MSExchange WorkloadManagement Workloads",
"MSExchange RpcClientAccess",
},
},
{
name: "fsrmquota",
builder: newFSRMQuotaCollector,
perfCounterNames: nil,
},
{
name: "hyperv",
builder: NewHyperVCollector,
perfCounterNames: nil,
},
{
name: "iis",
builder: NewIISCollector,
perfCounterNames: []string{"Web Service",
"APP_POOL_WAS",
"Web Service Cache",
"W3SVC_W3WP",
},
},
{
name: "logical_disk",
builder: NewLogicalDiskCollector,
perfCounterNames: []string{"LogicalDisk"},
},
{
name: "logon",
builder: NewLogonCollector,
perfCounterNames: nil,
},
{
name: "memory",
builder: NewMemoryCollector,
perfCounterNames: []string{"Memory"},
},
{
name: "mscluster_cluster",
builder: newMSCluster_ClusterCollector,
perfCounterNames: nil,
},
{
name: "mscluster_network",
builder: newMSCluster_NetworkCollector,
perfCounterNames: nil,
},
{
name: "mscluster_node",
builder: newMSCluster_NodeCollector,
perfCounterNames: nil,
},
{
name: "mscluster_resource",
builder: newMSCluster_ResourceCollector,
perfCounterNames: nil,
},
{
name: "mscluster_resourcegroup",
builder: newMSCluster_ResourceGroupCollector,
perfCounterNames: nil,
},
{
name: "msmq",
builder: NewMSMQCollector,
perfCounterNames: nil,
},
{
name: "mssql",
builder: NewMSSQLCollector,
perfCounterNames: nil,
},
{
name: "net",
builder: NewNetworkCollector,
perfCounterNames: []string{"Network Interface"},
},
{
name: "netframework_clrexceptions",
builder: NewNETFramework_NETCLRExceptionsCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrinterop",
builder: NewNETFramework_NETCLRInteropCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrjit",
builder: NewNETFramework_NETCLRJitCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrloading",
builder: NewNETFramework_NETCLRLoadingCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrlocksandthreads",
builder: NewNETFramework_NETCLRLocksAndThreadsCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrmemory",
builder: NewNETFramework_NETCLRMemoryCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrremoting",
builder: NewNETFramework_NETCLRRemotingCollector,
perfCounterNames: nil,
},
{
name: "netframework_clrsecurity",
builder: NewNETFramework_NETCLRSecurityCollector,
perfCounterNames: nil,
},
{
name: "os",
builder: NewOSCollector,
perfCounterNames: []string{"Paging File"},
},
{
name: "process",
builder: newProcessCollector,
perfCounterNames: []string{"Process"},
},
{
name: "remote_fx",
builder: NewRemoteFx,
perfCounterNames: []string{"RemoteFX Network"},
},
{
name: "scheduled_task",
builder: NewScheduledTask,
perfCounterNames: nil,
},
{
name: "service",
builder: NewserviceCollector,
perfCounterNames: nil,
},
{
name: "smtp",
builder: NewSMTPCollector,
perfCounterNames: []string{"SMTP Server"},
},
{
name: "system",
builder: NewSystemCollector,
perfCounterNames: []string{"System"},
},
{
name: "teradici_pcoip",
builder: newTeradiciPcoipCollector,
perfCounterNames: nil,
},
{
name: "tcp",
builder: NewTCPCollector,
perfCounterNames: []string{"TCPv4"},
},
{
name: "terminal_services",
builder: NewTerminalServicesCollector,
perfCounterNames: []string{
"Terminal Services",
"Terminal Services Session",
"Remote Desktop Connection Broker Counterset",
},
},
{
name: "textfile",
builder: NewTextFileCollector,
perfCounterNames: nil,
},
{
name: "thermalzone",
builder: NewThermalZoneCollector,
perfCounterNames: nil,
},
{
name: "time",
builder: newTimeCollector,
perfCounterNames: []string{"Windows Time Service"},
},
{
name: "vmware",
builder: NewVmwareCollector,
perfCounterNames: nil,
},
{
name: "vmware_blast",
builder: newVmwareBlastCollector,
perfCounterNames: nil,
},
}
// To be called by the exporter for collector initialisation
func RegisterCollectors() {
for _, v := range collectors {
registerCollector(v.name, v.builder, v.perfCounterNames...)
}
}