Compare commits

...

4 Commits

Author SHA1 Message Date
Calle Pettersson
cb9da1ae22 Merge pull request #256 from martinlindhe/mssql-clean-instance-names
Strip special chars from instance names
2018-08-31 18:16:43 +02:00
Calle Pettersson
7de316af9f Strip special chars from instance names 2018-08-31 17:21:32 +02:00
Calle Pettersson
263ab8c444 Merge pull request #253 from kafecho/wildcard_query_escape
Clarified that the % character has to be escaped
2018-08-28 12:19:36 +02:00
Guillaume Belrose
57449c4768 Clarified that the % character has to be escaped when using the wmi_exporter from the command prompt or batch files. 2018-08-28 08:58:08 +02:00
2 changed files with 14 additions and 3 deletions

View File

@@ -76,7 +76,10 @@ The prometheus metrics will be exposed on [localhost:9182](http://localhost:9182
.\wmi_exporter.exe --collectors.enabled "process" --collector.process.processes-where "Name LIKE 'firefox%'"
When there are multiple processes with the same name, WMI represents those after the first instance as `process-name#index`. So to get them all, rather than just the first one, the query needs to be a wildcard search.
When there are multiple processes with the same name, WMI represents those after the first instance as `process-name#index`. So to get them all, rather than just the first one, the query needs to be a wildcard search using a `%` character.
Please note that in Windows batch scripts (and when using the `cmd` command prompt), the `%` character is reserved, so it has to be escaped with another `%`. For example, the wildcard syntax for searching for all firefox processes is `firefox%%`.
## License

View File

@@ -66,7 +66,7 @@ func getMSSQLInstances() mssqlInstancesType {
instanceNames, err := k.ReadValueNames(0)
if err != nil {
log.Warn("Can't ReadSubKeyNames %#v", err)
log.Warnf("Can't ReadSubKeyNames %#v", err)
return sqlDefaultInstance
}
@@ -87,7 +87,15 @@ func getMSSQLInstances() mssqlInstancesType {
func mssqlBuildWMIInstanceClass(suffix string, instance string) string {
instancePart := "MSSQLSERVER_SQLServer"
if instance != "MSSQLSERVER" {
instancePart = fmt.Sprintf("MSSQL%s_MSSQL%s", instance, instance)
// Instance names can contain some special characters, which are not supported in the WMI class name.
// We strip those out.
cleanedName := strings.Map(func(r rune) rune {
if r == '_' || r == '$' || r == '#' {
return -1
}
return r
}, instance)
instancePart = fmt.Sprintf("MSSQL%s_MSSQL%s", cleanedName, cleanedName)
}
return fmt.Sprintf("Win32_PerfRawData_%s%s", instancePart, suffix)