mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-04 17:46:36 +00:00
Fix IIS warning when IIS collector is NOT in use (#212)
changing IIS code to only error if used Only tries to read registry if collector is initialized
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Factories["iis"] = NewIISCollector
|
Factories["iis"] = NewIISCollector
|
||||||
iis_version = getIISVersion()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type simple_version struct {
|
type simple_version struct {
|
||||||
@@ -60,8 +59,6 @@ var (
|
|||||||
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()
|
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()
|
||||||
appWhitelist = kingpin.Flag("collector.iis.app-whitelist", "Regexp of apps to whitelist. App name must both match whitelist and not match blacklist to be included.").Default(".+").String()
|
appWhitelist = kingpin.Flag("collector.iis.app-whitelist", "Regexp of apps to whitelist. App name must both match whitelist and not match blacklist to be included.").Default(".+").String()
|
||||||
appBlacklist = kingpin.Flag("collector.iis.app-blacklist", "Regexp of apps to blacklist. App name must both match whitelist and not match blacklist to be included.").String()
|
appBlacklist = kingpin.Flag("collector.iis.app-blacklist", "Regexp of apps to blacklist. App name must both match whitelist and not match blacklist to be included.").String()
|
||||||
|
|
||||||
iis_version = simple_version{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type IISCollector struct {
|
type IISCollector struct {
|
||||||
@@ -188,13 +185,15 @@ type IISCollector struct {
|
|||||||
|
|
||||||
appWhitelistPattern *regexp.Regexp
|
appWhitelistPattern *regexp.Regexp
|
||||||
appBlacklistPattern *regexp.Regexp
|
appBlacklistPattern *regexp.Regexp
|
||||||
|
|
||||||
|
iis_version simple_version
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIISCollector ...
|
// NewIISCollector ...
|
||||||
func NewIISCollector() (Collector, error) {
|
func NewIISCollector() (Collector, error) {
|
||||||
const subsystem = "iis"
|
const subsystem = "iis"
|
||||||
|
|
||||||
return &IISCollector{
|
buildIIS := &IISCollector{
|
||||||
// Websites
|
// Websites
|
||||||
// Gauges
|
// Gauges
|
||||||
CurrentAnonymousUsers: prometheus.NewDesc(
|
CurrentAnonymousUsers: prometheus.NewDesc(
|
||||||
@@ -808,7 +807,11 @@ func NewIISCollector() (Collector, error) {
|
|||||||
|
|
||||||
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
|
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
|
||||||
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
|
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
buildIIS.iis_version = getIISVersion()
|
||||||
|
|
||||||
|
return buildIIS, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -1645,7 +1648,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if iis_version.major >= 8 {
|
if c.iis_version.major >= 8 {
|
||||||
var dst_worker_iis8 []Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP_IIS8
|
var dst_worker_iis8 []Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP_IIS8
|
||||||
q = queryAllForClass(&dst_worker_iis8, "Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP")
|
q = queryAllForClass(&dst_worker_iis8, "Win32_PerfRawData_W3SVCW3WPCounterProvider_W3SVCW3WP")
|
||||||
if err := wmi.Query(q, &dst_worker_iis8); err != nil {
|
if err := wmi.Query(q, &dst_worker_iis8); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user