diff --git a/collector/ad.go b/collector/ad.go index bf2dc7b64..42122c1f4 100644 --- a/collector/ad.go +++ b/collector/ad.go @@ -11,10 +11,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("ad", NewADCollector) -} - // A ADCollector is a Prometheus collector for WMI Win32_PerfRawData_DirectoryServices_DirectoryServices metrics type ADCollector struct { AddressBookOperationsTotal *prometheus.Desc diff --git a/collector/adcs.go b/collector/adcs.go index 6d87ce55d..443a5d894 100644 --- a/collector/adcs.go +++ b/collector/adcs.go @@ -10,10 +10,6 @@ import ( "strings" ) -func init() { - registerCollector("adcs", adcsCollectorMethod, "Certification Authority") -} - type adcsCollector struct { RequestsPerSecond *prometheus.Desc RequestProcessingTime *prometheus.Desc diff --git a/collector/adfs.go b/collector/adfs.go index 9b243fbfb..6d69c22a0 100644 --- a/collector/adfs.go +++ b/collector/adfs.go @@ -8,10 +8,6 @@ import ( "math" ) -func init() { - registerCollector("adfs", newADFSCollector, "AD FS") -} - type adfsCollector struct { adLoginConnectionFailures *prometheus.Desc certificateAuthentications *prometheus.Desc diff --git a/collector/cache.go b/collector/cache.go index bba70f824..9999cac54 100644 --- a/collector/cache.go +++ b/collector/cache.go @@ -8,10 +8,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("cache", newCacheCollector, "Cache") -} - // A CacheCollector is a Prometheus collector for Perflib Cache metrics type CacheCollector struct { AsyncCopyReadsTotal *prometheus.Desc diff --git a/collector/container.go b/collector/container.go index 332f6c163..2812cec18 100644 --- a/collector/container.go +++ b/collector/container.go @@ -9,10 +9,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("container", NewContainerMetricsCollector) -} - // A ContainerMetricsCollector is a Prometheus collector for containers metrics type ContainerMetricsCollector struct { // Presence diff --git a/collector/cpu.go b/collector/cpu.go index e3a43a0de..8e80195df 100644 --- a/collector/cpu.go +++ b/collector/cpu.go @@ -9,17 +9,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - var deps string - // See below for 6.05 magic value - if getWindowsVersion() > 6.05 { - deps = "Processor Information" - } else { - deps = "Processor" - } - registerCollector("cpu", newCPUCollector, deps) -} - type cpuCollectorBasic struct { CStateSecondsTotal *prometheus.Desc TimeTotal *prometheus.Desc diff --git a/collector/cpu_info.go b/collector/cpu_info.go index 37f16bf1d..8dff803e8 100644 --- a/collector/cpu_info.go +++ b/collector/cpu_info.go @@ -13,10 +13,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("cpu_info", newCpuInfoCollector) -} - // If you are adding additional labels to the metric, make sure that they get added in here as well. See below for explanation. const ( win32ProcessorQuery = "SELECT Architecture, DeviceId, Description, Family, L2CacheSize, L3CacheSize, Name FROM Win32_Processor" diff --git a/collector/cs.go b/collector/cs.go index ba70e754f..df768faad 100644 --- a/collector/cs.go +++ b/collector/cs.go @@ -10,10 +10,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("cs", NewCSCollector) -} - // A CSCollector is a Prometheus collector for WMI metrics type CSCollector struct { PhysicalMemoryBytes *prometheus.Desc diff --git a/collector/dfsr.go b/collector/dfsr.go index a5e176e4e..e9198ef8a 100644 --- a/collector/dfsr.go +++ b/collector/dfsr.go @@ -11,16 +11,6 @@ import ( var dfsrEnabledCollectors = kingpin.Flag("collectors.dfsr.sources-enabled", "Comma-seperated list of DFSR Perflib sources to use.").Default("connection,folder,volume").String() -func init() { - // Perflib sources are dynamic, depending on the enabled child collectors - var perflibDependencies []string - for _, source := range expandEnabledChildCollectors(*dfsrEnabledCollectors) { - perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source)) - } - - registerCollector("dfsr", NewDFSRCollector, perflibDependencies...) -} - // DFSRCollector contains the metric and state data of the DFSR collectors. type DFSRCollector struct { // Connection source diff --git a/collector/dhcp.go b/collector/dhcp.go index 0544b1b8a..09c8ba0e2 100644 --- a/collector/dhcp.go +++ b/collector/dhcp.go @@ -7,10 +7,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("dhcp", NewDhcpCollector, "DHCP Server") -} - // A DhcpCollector is a Prometheus collector perflib DHCP metrics type DhcpCollector struct { PacketsReceivedTotal *prometheus.Desc diff --git a/collector/diskdrive.go b/collector/diskdrive.go index 3cce8759e..63f48d671 100644 --- a/collector/diskdrive.go +++ b/collector/diskdrive.go @@ -12,10 +12,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("disk_drive", newDiskDriveInfoCollector) -} - const ( win32DiskQuery = "SELECT DeviceID, Model, Caption, Name, Partitions, Size, Status, Availability FROM WIN32_DiskDrive" ) diff --git a/collector/dns.go b/collector/dns.go index 0375e68be..472cd842a 100644 --- a/collector/dns.go +++ b/collector/dns.go @@ -11,10 +11,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("dns", NewDNSCollector) -} - // A DNSCollector is a Prometheus collector for WMI Win32_PerfRawData_DNS_DNS metrics type DNSCollector struct { ZoneTransferRequestsReceived *prometheus.Desc diff --git a/collector/exchange.go b/collector/exchange.go index 5d443e7f2..1a6b13206 100644 --- a/collector/exchange.go +++ b/collector/exchange.go @@ -13,20 +13,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("exchange", newExchangeCollector, - "MSExchange ADAccess Processes", - "MSExchangeTransport Queues", - "MSExchange HttpProxy", - "MSExchange ActiveSync", - "MSExchange Availability Service", - "MSExchange OWA", - "MSExchangeAutodiscover", - "MSExchange WorkloadManagement Workloads", - "MSExchange RpcClientAccess", - ) -} - type exchangeCollector struct { LDAPReadTime *prometheus.Desc LDAPSearchTime *prometheus.Desc diff --git a/collector/fsrmquota.go b/collector/fsrmquota.go index 563d0ee1c..98ea18798 100644 --- a/collector/fsrmquota.go +++ b/collector/fsrmquota.go @@ -6,10 +6,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("fsrmquota", newFSRMQuotaCollector) -} - type FSRMQuotaCollector struct { QuotasCount *prometheus.Desc Path *prometheus.Desc diff --git a/collector/hyperv.go b/collector/hyperv.go index 8438bd6df..74d24936c 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -11,10 +11,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("hyperv", NewHyperVCollector) -} - // HyperVCollector is a Prometheus collector for hyper-v type HyperVCollector struct { // Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary diff --git a/collector/iis.go b/collector/iis.go index 95f383c4e..ed95bffff 100644 --- a/collector/iis.go +++ b/collector/iis.go @@ -13,10 +13,6 @@ import ( "golang.org/x/sys/windows/registry" ) -func init() { - registerCollector("iis", NewIISCollector, "Web Service", "APP_POOL_WAS", "Web Service Cache", "W3SVC_W3WP") -} - var ( siteWhitelist = kingpin.Flag("collector.iis.site-whitelist", "Regexp of sites to whitelist. Site name must both match whitelist and not match blacklist to be included.").Default(".+").String() siteBlacklist = kingpin.Flag("collector.iis.site-blacklist", "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.").String() diff --git a/collector/init.go b/collector/init.go new file mode 100644 index 000000000..ecb10ad71 --- /dev/null +++ b/collector/init.go @@ -0,0 +1,309 @@ +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...) + } +} diff --git a/collector/logical_disk.go b/collector/logical_disk.go index a9c4c013a..89990df2a 100644 --- a/collector/logical_disk.go +++ b/collector/logical_disk.go @@ -12,10 +12,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("logical_disk", NewLogicalDiskCollector, "LogicalDisk") -} - var ( volumeWhitelist = kingpin.Flag( "collector.logical_disk.volume-whitelist", diff --git a/collector/logon.go b/collector/logon.go index bc9625b06..fe94fd342 100644 --- a/collector/logon.go +++ b/collector/logon.go @@ -11,10 +11,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("logon", NewLogonCollector) -} - // A LogonCollector is a Prometheus collector for WMI metrics type LogonCollector struct { LogonType *prometheus.Desc diff --git a/collector/memory.go b/collector/memory.go index 114a92718..e216d21b9 100644 --- a/collector/memory.go +++ b/collector/memory.go @@ -11,10 +11,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("memory", NewMemoryCollector, "Memory") -} - // A MemoryCollector is a Prometheus collector for perflib Memory metrics type MemoryCollector struct { AvailableBytes *prometheus.Desc diff --git a/collector/mscluster_cluster.go b/collector/mscluster_cluster.go index bc37de416..584bf6695 100644 --- a/collector/mscluster_cluster.go +++ b/collector/mscluster_cluster.go @@ -5,10 +5,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("mscluster_cluster", newMSCluster_ClusterCollector) -} - // A MSCluster_ClusterCollector is a Prometheus collector for WMI MSCluster_Cluster metrics type MSCluster_ClusterCollector struct { AddEvictDelay *prometheus.Desc diff --git a/collector/mscluster_network.go b/collector/mscluster_network.go index d9fa81594..cabc5cfc4 100644 --- a/collector/mscluster_network.go +++ b/collector/mscluster_network.go @@ -5,10 +5,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("mscluster_network", newMSCluster_NetworkCollector) -} - // A MSCluster_NetworkCollector is a Prometheus collector for WMI MSCluster_Network metrics type MSCluster_NetworkCollector struct { Characteristics *prometheus.Desc diff --git a/collector/mscluster_node.go b/collector/mscluster_node.go index 7bb9714e4..94b278c5c 100644 --- a/collector/mscluster_node.go +++ b/collector/mscluster_node.go @@ -5,10 +5,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("mscluster_node", newMSCluster_NodeCollector) -} - // A MSCluster_NodeCollector is a Prometheus collector for WMI MSCluster_Node metrics type MSCluster_NodeCollector struct { BuildNumber *prometheus.Desc diff --git a/collector/mscluster_resource.go b/collector/mscluster_resource.go index ff0532c6b..2a4241db8 100644 --- a/collector/mscluster_resource.go +++ b/collector/mscluster_resource.go @@ -5,10 +5,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("mscluster_resource", newMSCluster_ResourceCollector) -} - // A MSCluster_ResourceCollector is a Prometheus collector for WMI MSCluster_Resource metrics type MSCluster_ResourceCollector struct { Characteristics *prometheus.Desc diff --git a/collector/mscluster_resourcegroup.go b/collector/mscluster_resourcegroup.go index 693891af5..42b15c1a0 100644 --- a/collector/mscluster_resourcegroup.go +++ b/collector/mscluster_resourcegroup.go @@ -5,10 +5,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("mscluster_resourcegroup", newMSCluster_ResourceGroupCollector) -} - // A MSCluster_ResourceGroupCollector is a Prometheus collector for WMI MSCluster_ResourceGroup metrics type MSCluster_ResourceGroupCollector struct { AutoFailbackType *prometheus.Desc diff --git a/collector/msmq.go b/collector/msmq.go index ab419faf4..66d0137fa 100644 --- a/collector/msmq.go +++ b/collector/msmq.go @@ -12,10 +12,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("msmq", NewMSMQCollector) -} - var ( msmqWhereClause = kingpin.Flag("collector.msmq.msmq-where", "WQL 'where' clause to use in WMI metrics query. Limits the response to the msmqs you specify and reduces the size of the response.").String() ) diff --git a/collector/mssql.go b/collector/mssql.go index 0947daa00..50d1d8b2c 100644 --- a/collector/mssql.go +++ b/collector/mssql.go @@ -129,10 +129,6 @@ func mssqlGetPerfObjectName(sqlInstance string, collector string) string { return (prefix + suffix) } -func init() { - registerCollector("mssql", NewMSSQLCollector) -} - // A MSSQLCollector is a Prometheus collector for various WMI Win32_PerfRawData_MSSQLSERVER_* metrics type MSSQLCollector struct { // meta diff --git a/collector/net.go b/collector/net.go index 9f5ae06fa..41d54dc4f 100644 --- a/collector/net.go +++ b/collector/net.go @@ -12,10 +12,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("net", NewNetworkCollector, "Network Interface") -} - var ( nicWhitelist = kingpin.Flag( "collector.net.nic-whitelist", diff --git a/collector/netframework_clrexceptions.go b/collector/netframework_clrexceptions.go index 8f25387a1..a8acbaf5f 100644 --- a/collector/netframework_clrexceptions.go +++ b/collector/netframework_clrexceptions.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrexceptions", NewNETFramework_NETCLRExceptionsCollector) -} - // A NETFramework_NETCLRExceptionsCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics type NETFramework_NETCLRExceptionsCollector struct { NumberofExcepsThrown *prometheus.Desc diff --git a/collector/netframework_clrinterop.go b/collector/netframework_clrinterop.go index f6a490f46..9906bef83 100644 --- a/collector/netframework_clrinterop.go +++ b/collector/netframework_clrinterop.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrinterop", NewNETFramework_NETCLRInteropCollector) -} - // A NETFramework_NETCLRInteropCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics type NETFramework_NETCLRInteropCollector struct { NumberofCCWs *prometheus.Desc diff --git a/collector/netframework_clrjit.go b/collector/netframework_clrjit.go index b5605f402..f857614b2 100644 --- a/collector/netframework_clrjit.go +++ b/collector/netframework_clrjit.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrjit", NewNETFramework_NETCLRJitCollector) -} - // A NETFramework_NETCLRJitCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics type NETFramework_NETCLRJitCollector struct { NumberofMethodsJitted *prometheus.Desc diff --git a/collector/netframework_clrloading.go b/collector/netframework_clrloading.go index 713294b83..5a86f933d 100644 --- a/collector/netframework_clrloading.go +++ b/collector/netframework_clrloading.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrloading", NewNETFramework_NETCLRLoadingCollector) -} - // A NETFramework_NETCLRLoadingCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics type NETFramework_NETCLRLoadingCollector struct { BytesinLoaderHeap *prometheus.Desc diff --git a/collector/netframework_clrlocksandthreads.go b/collector/netframework_clrlocksandthreads.go index 5cc9b8ea3..6e0a46b0e 100644 --- a/collector/netframework_clrlocksandthreads.go +++ b/collector/netframework_clrlocksandthreads.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrlocksandthreads", NewNETFramework_NETCLRLocksAndThreadsCollector) -} - // A NETFramework_NETCLRLocksAndThreadsCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics type NETFramework_NETCLRLocksAndThreadsCollector struct { CurrentQueueLength *prometheus.Desc diff --git a/collector/netframework_clrmemory.go b/collector/netframework_clrmemory.go index 0909d5a79..3d02ef215 100644 --- a/collector/netframework_clrmemory.go +++ b/collector/netframework_clrmemory.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrmemory", NewNETFramework_NETCLRMemoryCollector) -} - // A NETFramework_NETCLRMemoryCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics type NETFramework_NETCLRMemoryCollector struct { AllocatedBytes *prometheus.Desc diff --git a/collector/netframework_clrremoting.go b/collector/netframework_clrremoting.go index 49c7b3a93..17a15bed3 100644 --- a/collector/netframework_clrremoting.go +++ b/collector/netframework_clrremoting.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrremoting", NewNETFramework_NETCLRRemotingCollector) -} - // A NETFramework_NETCLRRemotingCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics type NETFramework_NETCLRRemotingCollector struct { Channels *prometheus.Desc diff --git a/collector/netframework_clrsecurity.go b/collector/netframework_clrsecurity.go index 25269f85e..e9c6b4fa1 100644 --- a/collector/netframework_clrsecurity.go +++ b/collector/netframework_clrsecurity.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("netframework_clrsecurity", NewNETFramework_NETCLRSecurityCollector) -} - // A NETFramework_NETCLRSecurityCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics type NETFramework_NETCLRSecurityCollector struct { NumberLinkTimeChecks *prometheus.Desc diff --git a/collector/os.go b/collector/os.go index 34bab42c1..bc4635e69 100644 --- a/collector/os.go +++ b/collector/os.go @@ -17,10 +17,6 @@ import ( "golang.org/x/sys/windows/registry" ) -func init() { - registerCollector("os", NewOSCollector, "Paging File") -} - // A OSCollector is a Prometheus collector for WMI metrics type OSCollector struct { OSInformation *prometheus.Desc diff --git a/collector/process.go b/collector/process.go index 5927dba00..5854accf9 100644 --- a/collector/process.go +++ b/collector/process.go @@ -15,10 +15,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("process", newProcessCollector, "Process") -} - var ( processWhitelist = kingpin.Flag( "collector.process.whitelist", diff --git a/collector/remote_fx.go b/collector/remote_fx.go index 40ed09059..6b547fec5 100644 --- a/collector/remote_fx.go +++ b/collector/remote_fx.go @@ -10,10 +10,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("remote_fx", NewRemoteFx, "RemoteFX Network", "RemoteFX Graphics") -} - // A RemoteFxNetworkCollector is a Prometheus collector for // WMI Win32_PerfRawData_Counters_RemoteFXNetwork & Win32_PerfRawData_Counters_RemoteFXGraphics metrics // https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_remotefxnetwork/ diff --git a/collector/scheduled_task.go b/collector/scheduled_task.go index 76e528a19..8f320f8c6 100644 --- a/collector/scheduled_task.go +++ b/collector/scheduled_task.go @@ -63,10 +63,6 @@ type ScheduledTask struct { type ScheduledTasks []ScheduledTask -func init() { - registerCollector("scheduled_task", NewScheduledTask) -} - // NewScheduledTask ... func NewScheduledTask() (Collector, error) { const subsystem = "scheduled_task" diff --git a/collector/service.go b/collector/service.go index 178ed9ce0..73edd9cb1 100644 --- a/collector/service.go +++ b/collector/service.go @@ -16,10 +16,6 @@ import ( "golang.org/x/sys/windows/svc/mgr" ) -func init() { - registerCollector("service", NewserviceCollector) -} - var ( serviceWhereClause = kingpin.Flag( "collector.service.services-where", diff --git a/collector/smtp.go b/collector/smtp.go index b3cd406aa..0ff61e306 100644 --- a/collector/smtp.go +++ b/collector/smtp.go @@ -11,10 +11,6 @@ import ( "regexp" ) -func init() { - registerCollector("smtp", NewSMTPCollector, "SMTP Server") -} - var ( serverWhitelist = kingpin.Flag("collector.smtp.server-whitelist", "Regexp of virtual servers to whitelist. Server name must both match whitelist and not match blacklist to be included.").Default(".+").String() serverBlacklist = kingpin.Flag("collector.smtp.server-blacklist", "Regexp of virtual servers to blacklist. Server name must both match whitelist and not match blacklist to be included.").String() diff --git a/collector/system.go b/collector/system.go index 2e3f76312..937913be0 100644 --- a/collector/system.go +++ b/collector/system.go @@ -8,10 +8,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("system", NewSystemCollector, "System") -} - // A SystemCollector is a Prometheus collector for WMI metrics type SystemCollector struct { ContextSwitchesTotal *prometheus.Desc diff --git a/collector/tcp.go b/collector/tcp.go index 2cc754698..ae9e9d12a 100644 --- a/collector/tcp.go +++ b/collector/tcp.go @@ -8,10 +8,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("tcp", NewTCPCollector, "TCPv4", "TCPv6") -} - // A TCPCollector is a Prometheus collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics type TCPCollector struct { ConnectionFailures *prometheus.Desc diff --git a/collector/teradici_pcoip.go b/collector/teradici_pcoip.go index ada796cc3..b55427a56 100644 --- a/collector/teradici_pcoip.go +++ b/collector/teradici_pcoip.go @@ -11,10 +11,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("teradici_pcoip", newTeradiciPcoipCollector) -} - // A teradiciPcoipCollector is a Prometheus collector for WMI metrics: // win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics // win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics diff --git a/collector/terminal_services.go b/collector/terminal_services.go index 0e6e2186f..f25b6ea34 100644 --- a/collector/terminal_services.go +++ b/collector/terminal_services.go @@ -14,10 +14,6 @@ import ( const ConnectionBrokerFeatureID uint32 = 133 -func init() { - registerCollector("terminal_services", NewTerminalServicesCollector, "Terminal Services", "Terminal Services Session", "Remote Desktop Connection Broker Counterset") -} - var ( connectionBrokerEnabled = isConnectionBrokerServer() ) diff --git a/collector/textfile.go b/collector/textfile.go index a51b45939..0f0982203 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -55,10 +55,6 @@ type textFileCollector struct { mtime *float64 } -func init() { - registerCollector("textfile", NewTextFileCollector) -} - // NewTextFileCollector returns a new Collector exposing metrics read from files // in the given textfile directory. func NewTextFileCollector() (Collector, error) { diff --git a/collector/thermalzone.go b/collector/thermalzone.go index cc18bd82a..78d3cb28a 100644 --- a/collector/thermalzone.go +++ b/collector/thermalzone.go @@ -8,10 +8,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("thermalzone", NewThermalZoneCollector) -} - // A thermalZoneCollector is a Prometheus collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics type thermalZoneCollector struct { PercentPassiveLimit *prometheus.Desc diff --git a/collector/time.go b/collector/time.go index 82da5fa13..a52241db3 100644 --- a/collector/time.go +++ b/collector/time.go @@ -10,10 +10,6 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func init() { - registerCollector("time", newTimeCollector, "Windows Time Service") -} - // TimeCollector is a Prometheus collector for Perflib counter metrics type TimeCollector struct { ClockFrequencyAdjustmentPPBTotal *prometheus.Desc diff --git a/collector/vmware.go b/collector/vmware.go index cf77bd643..bb7c6e1b5 100644 --- a/collector/vmware.go +++ b/collector/vmware.go @@ -11,10 +11,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("vmware", NewVmwareCollector) -} - // A VmwareCollector is a Prometheus collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics type VmwareCollector struct { MemActive *prometheus.Desc diff --git a/collector/vmware_blast.go b/collector/vmware_blast.go index f6bb4c655..12ca0f2c3 100644 --- a/collector/vmware_blast.go +++ b/collector/vmware_blast.go @@ -9,10 +9,6 @@ import ( "github.com/yusufpapurcu/wmi" ) -func init() { - registerCollector("vmware_blast", newVmwareBlastCollector) -} - // A vmwareBlastCollector is a Prometheus collector for WMI metrics: // win32_PerfRawData_Counters_VMwareBlastAudioCounters // win32_PerfRawData_Counters_VMwareBlastCDRCounters diff --git a/exporter.go b/exporter.go index 7178bb528..bd029074f 100644 --- a/exporter.go +++ b/exporter.go @@ -333,6 +333,9 @@ func main() { initWbem() + // Initialize collectors before loading + collector.RegisterCollectors() + collectors, err := loadCollectors(*enabledCollectors) if err != nil { log.Fatalf("Couldn't load collectors: %s", err)