Skip to content

Commit

Permalink
Merge pull request #263 from martinlindhe/linting
Browse files Browse the repository at this point in the history
Add linting
  • Loading branch information
carlpett committed Jan 27, 2019
2 parents 2053dea + 9daa8c8 commit 517cd3b
Show file tree
Hide file tree
Showing 30 changed files with 126 additions and 120 deletions.
9 changes: 6 additions & 3 deletions Makefile
@@ -1,14 +1,17 @@
export GOOS=windows

fmt:
gofmt -l -w -s .

build:
promu build -v

test:
go test -v ./...

lint:
gometalinter --vendor --config gometalinter.config ./...

fmt:
gofmt -l -w -s .

crossbuild:
# The prometheus/golang-builder image for promu crossbuild doesn't exist
# on Windows, so for now, we'll just build twice
Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Expand Up @@ -12,11 +12,15 @@ clone_folder: c:\gopath\src\github.com\martinlindhe\wmi_exporter
install:
- set PATH=%GOPATH%\bin;%PATH%
- go get -u github.com/prometheus/promu
- go get -u github.com/alecthomas/gometalinter && gometalinter --install
- choco install gitversion.portable make -y

test_script:
- make test

after_test:
- make lint

build_script:
- ps: |
$ErrorActionPreference = "Stop"
Expand Down
9 changes: 4 additions & 5 deletions collector/ad.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_DirectoryServices_DirectoryServices
// Partial docs: https://msdn.microsoft.com/en-us/library/ms803980.aspx

// +build windows

package collector
Expand Down Expand Up @@ -465,6 +462,8 @@ func (c *ADCollector) Collect(ch chan<- prometheus.Metric) error {
return nil
}

// Win32_PerfRawData_DirectoryServices_DirectoryServices docs:
// - https://msdn.microsoft.com/en-us/library/ms803980.aspx
type Win32_PerfRawData_DirectoryServices_DirectoryServices struct {
Name string

Expand All @@ -488,8 +487,8 @@ type Win32_PerfRawData_DirectoryServices_DirectoryServices struct {
DatabasemodifysPersec uint32
DatabaserecyclesPersec uint32
DigestBindsPersec uint32
DRAHighestUSNCommittedHighpart uint32
DRAHighestUSNCommittedLowpart uint32
DRAHighestUSNCommittedHighpart uint64
DRAHighestUSNCommittedLowpart uint64
DRAHighestUSNIssuedHighpart uint64
DRAHighestUSNIssuedLowpart uint64
DRAInboundBytesCompressedBetweenSitesAfterCompressionPersec uint32
Expand Down
6 changes: 3 additions & 3 deletions collector/cpu.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_PerfOS_Processor
// https://msdn.microsoft.com/en-us/library/aa394317(v=vs.90).aspx - Win32_PerfRawData_PerfOS_Processor class

// +build windows

package collector
Expand All @@ -25,6 +22,7 @@ type CPUCollector struct {
DPCsTotal *prometheus.Desc
}

// NewCPUCollector constructs a new CPUCollector
func NewCPUCollector() (Collector, error) {
const subsystem = "cpu"
return &CPUCollector{
Expand Down Expand Up @@ -66,6 +64,8 @@ func (c *CPUCollector) Collect(ch chan<- prometheus.Metric) error {
return nil
}

// Win32_PerfRawData_PerfOS_Processor docs:
// - https://msdn.microsoft.com/en-us/library/aa394317(v=vs.90).aspx
type Win32_PerfRawData_PerfOS_Processor struct {
Name string
C1TransitionsPersec uint64
Expand Down
5 changes: 2 additions & 3 deletions collector/cs.go
@@ -1,6 +1,3 @@
// returns data points from Win32_ComputerSystem
// https://msdn.microsoft.com/en-us/library/aa394102 - Win32_ComputerSystem class

// +build windows

package collector
Expand Down Expand Up @@ -53,6 +50,8 @@ func (c *CSCollector) Collect(ch chan<- prometheus.Metric) error {
return nil
}

// Win32_ComputerSystem docs:
// - https://msdn.microsoft.com/en-us/library/aa394102
type Win32_ComputerSystem struct {
NumberOfLogicalProcessors uint32
TotalPhysicalMemory uint64
Expand Down
7 changes: 3 additions & 4 deletions collector/dns.go
@@ -1,7 +1,3 @@
// returns data points from Win32_PerfRawData_DNS_DNS
// https://msdn.microsoft.com/en-us/library/ms803992.aspx?f=255&MSPPError=-2147217396
// https://technet.microsoft.com/en-us/library/cc977686.aspx

// +build windows

package collector
Expand Down Expand Up @@ -193,6 +189,9 @@ func (c *DNSCollector) Collect(ch chan<- prometheus.Metric) error {
return nil
}

// Win32_PerfRawData_DNS_DNS docs:
// - https://msdn.microsoft.com/en-us/library/ms803992.aspx?f=255&MSPPError=-2147217396
// - https://technet.microsoft.com/en-us/library/cc977686.aspx
type Win32_PerfRawData_DNS_DNS struct {
AXFRRequestReceived uint32
AXFRRequestSent uint32
Expand Down
21 changes: 10 additions & 11 deletions collector/iis.go
@@ -1,9 +1,3 @@
// returns data points from the following classes:
// - Win32_PerfRawData_W3SVC_WebService
// - Win32_PerfRawData_APPPOOLCountersProvider_APPPOOLWAS
// - Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP
// - Win32_PerfRawData_W3SVC_WebServiceCache

// +build windows

package collector
Expand Down Expand Up @@ -36,7 +30,12 @@ func getIISVersion() simple_version {
log.Warn("Couldn't open registry to determine IIS version:", err)
return simple_version{}
}
defer k.Close()
defer func() {
err = k.Close()
if err != nil {
log.Warnf("Failed to close registry key: %v", err)
}
}()

major, _, err := k.GetIntegerValue("MajorVersion")
if err != nil {
Expand Down Expand Up @@ -808,8 +807,8 @@ func NewIISCollector() (Collector, error) {
nil,
),

appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *appWhitelist)),
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *appBlacklist)),
}

buildIIS.iis_version = getIISVersion()
Expand Down Expand Up @@ -986,7 +985,7 @@ type Win32_PerfRawData_W3SVC_WebServiceCache struct {
URICacheMisses uint32
}

var ApplicationStates = map[uint32]string{
var applicationStates = map[uint32]string{
1: "Uninitialized",
2: "Initialized",
3: "Running",
Expand Down Expand Up @@ -1267,7 +1266,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
}

// Guages
for key, label := range ApplicationStates {
for key, label := range applicationStates {
isCurrentState := 0.0
if key == app.CurrentApplicationPoolState {
isCurrentState = 1.0
Expand Down
7 changes: 3 additions & 4 deletions collector/logical_disk.go
@@ -1,7 +1,3 @@
// returns data points from Win32_PerfRawData_PerfDisk_LogicalDisk
// 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

// +build windows

package collector
Expand Down Expand Up @@ -146,6 +142,9 @@ func (c *LogicalDiskCollector) Collect(ch chan<- prometheus.Metric) error {
return nil
}

// 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
type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
Name string
CurrentDiskQueueLength uint32
Expand Down
3 changes: 0 additions & 3 deletions collector/msmq.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_MSMQ_MSMQQueue
// <add link to documentation here> - Win32_PerfRawData_MSMQ_MSMQQueue class

// +build windows

package collector
Expand Down
54 changes: 29 additions & 25 deletions collector/mssql.go
@@ -1,23 +1,3 @@
// returns data points from the following classes:
// - Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-access-methods-object
// - Win32_PerfRawData_MSSQLSERVER_SQLServerAvailabilityReplica
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-availability-replica
// - Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-buffer-manager-object
// - Win32_PerfRawData_MSSQLSERVER_SQLServerDatabaseReplica
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-database-replica
// - Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-databases-object?view=sql-server-2017
// - Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-general-statistics-object
// - Win32_PerfRawData_MSSQLSERVER_SQLServerLocks
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-locks-object
// - Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-memory-manager-object
// - Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-sql-statistics-object

// +build windows

package collector
Expand Down Expand Up @@ -64,7 +44,12 @@ func getMSSQLInstances() mssqlInstancesType {
log.Warn("Couldn't open registry to determine SQL instances:", err)
return sqlDefaultInstance
}
defer k.Close()
defer func() {
err = k.Close()
if err != nil {
log.Warnf("Failed to close registry key: %v", err)
}
}()

instanceNames, err := k.ReadValueNames(0)
if err != nil {
Expand Down Expand Up @@ -383,7 +368,7 @@ func NewMSSQLCollector() (Collector, error) {

const subsystem = "mssql"

MSSQLCollector := MSSQLCollector{
mssqlCollector := MSSQLCollector{
// meta
mssqlScrapeDurationDesc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "collector_duration_seconds"),
Expand Down Expand Up @@ -1655,17 +1640,17 @@ func NewMSSQLCollector() (Collector, error) {
mssqlInstances: getMSSQLInstances(),
}

MSSQLCollector.mssqlCollectors = MSSQLCollector.getMSSQLCollectors()
mssqlCollector.mssqlCollectors = mssqlCollector.getMSSQLCollectors()

if *mssqlPrintCollectors {
fmt.Printf("Available SQLServer Classes:\n")
for name := range MSSQLCollector.mssqlCollectors {
for name := range mssqlCollector.mssqlCollectors {
fmt.Printf(" - %s\n", name)
}
os.Exit(0)
}

return &MSSQLCollector, nil
return &mssqlCollector, nil
}

type mssqlCollectorFunc func(ch chan<- prometheus.Metric, sqlInstance string) (*prometheus.Desc, error)
Expand Down Expand Up @@ -1723,6 +1708,9 @@ func (c *MSSQLCollector) Collect(ch chan<- prometheus.Metric) error {
return nil
}

// win32PerfRawDataSQLServerAccessMethods docs:
// - Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-access-methods-object
type win32PerfRawDataSQLServerAccessMethods struct {
AUcleanupbatchesPersec uint64
AUcleanupsPersec uint64
Expand Down Expand Up @@ -2087,6 +2075,8 @@ func (c *MSSQLCollector) collectAccessMethods(ch chan<- prometheus.Metric, sqlIn
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerAvailabilityReplica docs:
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-availability-replica
type win32PerfRawDataSQLServerAvailabilityReplica struct {
Name string
BytesReceivedfromReplicaPersec uint64
Expand Down Expand Up @@ -2179,6 +2169,8 @@ func (c *MSSQLCollector) collectAvailabilityReplica(ch chan<- prometheus.Metric,
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager docs:
// https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-buffer-manager-object
type win32PerfRawDataSQLServerBufferManager struct {
BackgroundwriterpagesPersec uint64
Buffercachehitratio uint64
Expand Down Expand Up @@ -2376,6 +2368,8 @@ func (c *MSSQLCollector) collectBufferManager(ch chan<- prometheus.Metric, sqlIn
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerDatabaseReplica docs:
// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-database-replica
type win32PerfRawDataSQLServerDatabaseReplica struct {
Name string
DatabaseFlowControlDelay uint64
Expand Down Expand Up @@ -2588,6 +2582,8 @@ func (c *MSSQLCollector) collectDatabaseReplica(ch chan<- prometheus.Metric, sql
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases docs:
// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-databases-object?view=sql-server-2017
type win32PerfRawDataSQLServerDatabases struct {
Name string
ActiveTransactions uint64
Expand Down Expand Up @@ -2976,6 +2972,8 @@ func (c *MSSQLCollector) collectDatabases(ch chan<- prometheus.Metric, sqlInstan
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics docs:
// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-general-statistics-object
type win32PerfRawDataSQLServerGeneralStatistics struct {
ActiveTempTables uint64
ConnectionResetPersec uint64
Expand Down Expand Up @@ -3188,6 +3186,8 @@ func (c *MSSQLCollector) collectGeneralStatistics(ch chan<- prometheus.Metric, s
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerLocks docs:
// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-locks-object
type win32PerfRawDataSQLServerLocks struct {
Name string
AverageWaitTimems uint64
Expand Down Expand Up @@ -3264,6 +3264,8 @@ func (c *MSSQLCollector) collectLocks(ch chan<- prometheus.Metric, sqlInstance s
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager docs:
// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-memory-manager-object
type win32PerfRawDataSQLServerMemoryManager struct {
ConnectionMemoryKB uint64
DatabaseCacheMemoryKB uint64
Expand Down Expand Up @@ -3445,6 +3447,8 @@ func (c *MSSQLCollector) collectMemoryManager(ch chan<- prometheus.Metric, sqlIn
return nil, nil
}

// Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics docs:
// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-sql-statistics-object
type win32PerfRawDataSQLServerSQLStatistics struct {
AutoParamAttemptsPersec uint64
BatchRequestsPersec uint64
Expand Down
8 changes: 2 additions & 6 deletions collector/net.go
@@ -1,9 +1,3 @@
// returns data points from Win32_PerfRawData_Tcpip_NetworkInterface

// https://technet.microsoft.com/en-us/security/aa394340(v=vs.80) (Win32_PerfRawData_Tcpip_NetworkInterface class)
// https://msdn.microsoft.com/en-us/library/aa394216 (Win32_NetworkAdapter class)
// https://msdn.microsoft.com/en-us/library/aa394353 (Win32_PnPEntity class)

// +build windows

package collector
Expand Down Expand Up @@ -152,6 +146,8 @@ func mangleNetworkName(name string) string {
return nicNameToUnderscore.ReplaceAllString(name, "_")
}

// Win32_PerfRawData_Tcpip_NetworkInterface docs:
// - https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)
type Win32_PerfRawData_Tcpip_NetworkInterface struct {
BytesReceivedPerSec uint64
BytesSentPerSec uint64
Expand Down
3 changes: 0 additions & 3 deletions collector/netframework_clrexceptions.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_NETFramework_NETCLRExceptions
// <add link to documentation here> - Win32_PerfRawData_NETFramework_NETCLRExceptions class

// +build windows

package collector
Expand Down
3 changes: 0 additions & 3 deletions collector/netframework_clrinterop.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_NETFramework_NETCLRInterop
// <add link to documentation here> - Win32_PerfRawData_NETFramework_NETCLRInterop class

// +build windows

package collector
Expand Down
3 changes: 0 additions & 3 deletions collector/netframework_clrjit.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_NETFramework_NETCLRJit
// <add link to documentation here> - Win32_PerfRawData_NETFramework_NETCLRJit class

// +build windows

package collector
Expand Down
3 changes: 0 additions & 3 deletions collector/netframework_clrloading.go
@@ -1,6 +1,3 @@
// returns data points from Win32_PerfRawData_NETFramework_NETCLRLoading
// <add link to documentation here> - Win32_PerfRawData_NETFramework_NETCLRLoading class

// +build windows

package collector
Expand Down

0 comments on commit 517cd3b

Please sign in to comment.