Compare commits

...

13 Commits

Author SHA1 Message Date
Calle Pettersson
fe7e5cb4d8 Merge pull request #241 from szook/protect-against-empty-result-set
protect against empty wmi query result sets
2018-08-08 09:14:27 +02:00
Steve Zook
c156f2bcbe protect against emtpy wmi query result sets
If an WMI query were to return an empty result set, trying to access the
first element in the result set would result in a `panic: runtime error:
index out of range` error.

add logic to explicitly check if the result set size is 0 and return an
error rather.

Fixes https://github.com/martinlindhe/wmi_exporter/issues/240
2018-08-07 15:47:39 -04:00
Calle Pettersson
832771b4a2 Merge pull request #238 from bbigras/patch-1
fix typo in exporter.go
2018-08-06 11:41:43 +02:00
Bruno Bigras
16fecfbc67 fix typo in exporter.go 2018-08-05 21:39:43 -04:00
Calle Pettersson
bad1e7f7b0 Merge pull request #237 from szook/fix-mssql-for-non-default-instances
fix mssql for non-default sql instances
2018-08-04 08:33:23 +02:00
Steve Zook
c868c00e89 fix mssql for non-default sql instances
the only sql servers I have access to are using the default
`MSSQLSERVER` instance names.  I was contacted by someone using a
different instance name and it was failing.

Found 2 bugs in the code:

1) I was returning the default `MSSQLSERVER` as an instance even if it wasn't found in the registry

2) learned that the WMI class naming scheme for non-default instances
was not what I had coded. Changed to incorproate new knowledge.
2018-08-03 16:31:19 -04:00
Calle Pettersson
5035e97369 Merge pull request #236 from szook/add-mssql-accessmethod-class
add mssql accessmethod class
2018-08-03 22:16:08 +02:00
Steve Zook
144715e3d2 remove persec from variable names
removed persec from variable names

but when I did that, there was some variable name collisions, so I went
through and name-spaced the class variables.
1
2018-08-03 15:39:26 -04:00
Steve Zook
a20cf1274a add mssql accessmethod class
in the process of trying to build a grafana dashboard with "useful"
mssql metrics, I was looking around for what metrics might be useful and
came across an article of [15 SQL Server Performace Counters to Monitor](https://blogs.sentryone.com/allenwhite/sql-server-performance-counters-to-monitor/)

two of the suggested metrics are provided by the AccessMethod
class, which I was not yet capturing.

So I added metrics for the
Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods class.
2018-08-03 13:45:51 -04:00
Calle Pettersson
626a25cd00 Merge pull request #235 from szook/reorder-functions
reorder functions
2018-08-03 16:42:32 +02:00
Calle Pettersson
96dd456bb1 Merge pull request #234 from szook/fix-mssql-metric-name-typo
fix mssql metric name type
2018-08-03 16:27:40 +02:00
Steve Zook
af1b8bf4d0 fix mssql metric name type
found that I had one metric with an extra `s` in `_genstatss_`, making it
inconsistent with it's siblings.
2018-08-03 09:52:15 -04:00
Steve Zook
d83615a818 reorder functions
so that the two functions that list available child collectors are next
to each other - should make less likely to not miss editing one of those
when adding additional wmi classes

also removed the 'filter' from the `mssqlFilterAvailableClassCollectors`
function as it's not filtering anyting.
2018-08-03 09:48:32 -04:00
10 changed files with 1934 additions and 1205 deletions

View File

@@ -3,6 +3,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -616,6 +618,9 @@ func (c *ADCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.AddressBookOperationsTotal,

View File

@@ -4,6 +4,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -60,6 +62,9 @@ func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.LogicalProcessors,

View File

@@ -4,6 +4,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -237,6 +239,9 @@ func (c *DNSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.ZoneTransferRequestsReceived,

View File

@@ -7,6 +7,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
@@ -1738,216 +1739,218 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
return nil, err
}
if len(dst_cache) > 0 {
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_ActiveFlushedEntries,
prometheus.GaugeValue,
float64(dst_cache[0].ActiveFlushedEntries),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheMemoryUsage,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentFileCacheMemoryUsage),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MaximumFileCacheMemoryUsage,
prometheus.CounterValue,
float64(dst_cache[0].MaximumFileCacheMemoryUsage),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedFiles),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].FileCacheHits+dst_cache[0].FileCacheMisses),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].FileCacheHits),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FilesCached,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentFilesCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FilesCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFilesCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FilesFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedFiles),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedURIs),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelTotalFlushedURIs),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].URICacheHits+dst_cache[0].URICacheMisses),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelURICacheHits+dst_cache[0].KernelURICacheMisses),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].URICacheHits),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelURICacheHits),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCached,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentURIsCached),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCached,
prometheus.GaugeValue,
float64(dst_cache[0].KernelCurrentURIsCached),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalURIsCached),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelTotalURIsCached),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedURIs),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelTotalFlushedURIs),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCached,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentMetadataCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCacheFlushes,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedMetadata),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].MetadataCacheHits+dst_cache[0].MetadataCacheMisses),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].MetadataCacheHits),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalMetadataCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedMetadata),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheActiveFlushedItems,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheCurrentFlushedItems),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheItems,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheCurrentItems),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheMemoryUsage,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheCurrentMemoryUsage),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalHits+dst_cache[0].OutputCacheTotalMisses),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalHits),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheFlushedItemsTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalFlushedItems),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalFlushes),
)
if len(dst_cache) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_ActiveFlushedEntries,
prometheus.GaugeValue,
float64(dst_cache[0].ActiveFlushedEntries),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheMemoryUsage,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentFileCacheMemoryUsage),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MaximumFileCacheMemoryUsage,
prometheus.CounterValue,
float64(dst_cache[0].MaximumFileCacheMemoryUsage),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedFiles),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].FileCacheHits+dst_cache[0].FileCacheMisses),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FileCacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].FileCacheHits),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FilesCached,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentFilesCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FilesCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFilesCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_FilesFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedFiles),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedURIs),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelTotalFlushedURIs),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].URICacheHits+dst_cache[0].URICacheMisses),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelURICacheHits+dst_cache[0].KernelURICacheMisses),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].URICacheHits),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URICacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelURICacheHits),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCached,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentURIsCached),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCached,
prometheus.GaugeValue,
float64(dst_cache[0].KernelCurrentURIsCached),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalURIsCached),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelTotalURIsCached),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedURIs),
"user",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_URIsFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].KernelTotalFlushedURIs),
"kernel",
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCached,
prometheus.GaugeValue,
float64(dst_cache[0].CurrentMetadataCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCacheFlushes,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedMetadata),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].MetadataCacheHits+dst_cache[0].MetadataCacheMisses),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].MetadataCacheHits),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataCachedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalMetadataCached),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_MetadataFlushedTotal,
prometheus.CounterValue,
float64(dst_cache[0].TotalFlushedMetadata),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheActiveFlushedItems,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheCurrentFlushedItems),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheItems,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheCurrentItems),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheMemoryUsage,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheCurrentMemoryUsage),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheQueriesTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalHits+dst_cache[0].OutputCacheTotalMisses),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheHitsTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalHits),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheFlushedItemsTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalFlushedItems),
)
ch <- prometheus.MustNewConstMetric(
c.ServiceCache_OutputCacheFlushesTotal,
prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalFlushes),
)
return nil, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"time"
"github.com/StackExchange/wmi"
@@ -142,6 +143,10 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.PhysicalMemoryFreeBytes,
prometheus.GaugeValue,

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -94,6 +95,9 @@ func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.ContextSwitchesTotal,

View File

@@ -5,6 +5,7 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -118,6 +119,9 @@ func (c *TCPCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
// Counters
ch <- prometheus.MustNewConstMetric(

View File

@@ -2,6 +2,8 @@
package collector
import (
"errors"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@@ -201,6 +203,9 @@ func (c *VmwareCollector) collectMem(ch chan<- prometheus.Metric) (*prometheus.D
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.MemActive,
@@ -287,6 +292,9 @@ func (c *VmwareCollector) collectCpu(ch chan<- prometheus.Metric) (*prometheus.D
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}
ch <- prometheus.MustNewConstMetric(
c.CpuLimitMHz,

View File

@@ -185,7 +185,7 @@ func main() {
).Default("/metrics").String()
enabledCollectors = kingpin.Flag(
"collectors.enabled",
"Comma-separated list of collectors to use. Use '[default]' as a placeholder for all the collectors enabled by default.").
"Comma-separated list of collectors to use. Use '[defaults]' as a placeholder for all the collectors enabled by default.").
Default(filterAvailableCollectors(defaultCollectors)).String()
printCollectors = kingpin.Flag(
"collectors.print",