mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-13 00:16:37 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47dc455dc2 | ||
|
|
9ea0c95ca5 | ||
|
|
91374a75f2 | ||
|
|
b4ca3412dd | ||
|
|
7fdbdad140 | ||
|
|
e65b785995 | ||
|
|
8482814343 | ||
|
|
8df4ea3f51 | ||
|
|
f60211aba3 |
@@ -16,6 +16,7 @@ iis | [Win32_PerfRawData_W3SVC_WebService](https://msdn.microsoft.com/en-us/libr
|
|||||||
logical_disk | [Win32_PerfRawData_PerfDisk_LogicalDisk](https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71)) metrics (disk I/O) | ✓
|
logical_disk | [Win32_PerfRawData_PerfDisk_LogicalDisk](https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71)) metrics (disk I/O) | ✓
|
||||||
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
|
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
|
||||||
os | [Win32_OperatingSystem](https://msdn.microsoft.com/en-us/library/aa394239) metrics (memory, processes, users) | ✓
|
os | [Win32_OperatingSystem](https://msdn.microsoft.com/en-us/library/aa394239) metrics (memory, processes, users) | ✓
|
||||||
|
service | [Win32_Service](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx) metrics (service states) | ✓
|
||||||
system | Win32_PerfRawData_PerfOS_System metrics (system calls) | ✓
|
system | Win32_PerfRawData_PerfOS_System metrics (system calls) | ✓
|
||||||
|
|
||||||
The HELP texts shows the WMI data source, please see MSDN documentation for details.
|
The HELP texts shows the WMI data source, please see MSDN documentation for details.
|
||||||
|
|||||||
17
appveyor.yml
17
appveyor.yml
@@ -4,12 +4,17 @@ os: Windows Server 2012 R2
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
GOPATH: c:\gopath
|
GOPATH: c:\gopath
|
||||||
|
matrix:
|
||||||
|
- MSI_ARCH: amd64
|
||||||
|
GOARCH: amd64
|
||||||
|
- MSI_ARCH: 386
|
||||||
|
GOARCH: 386
|
||||||
|
|
||||||
clone_folder: c:\gopath\src\github.com\martinlindhe\wmi_exporter
|
clone_folder: c:\gopath\src\github.com\martinlindhe\wmi_exporter
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- go version
|
- go version
|
||||||
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
|
- set PATH=%GOPATH%\bin;c:\go\bin;%GOPATH%\bin\windows_%GOARCH%;%PATH%
|
||||||
- go get -u github.com/kardianos/govendor
|
- go get -u github.com/kardianos/govendor
|
||||||
- go get -u github.com/prometheus/promu
|
- go get -u github.com/prometheus/promu
|
||||||
- choco install gitversion.portable -y
|
- choco install gitversion.portable -y
|
||||||
@@ -19,17 +24,21 @@ build_script:
|
|||||||
- govendor test -v +local
|
- govendor test -v +local
|
||||||
- promu build -v .
|
- promu build -v .
|
||||||
- ps: |
|
- ps: |
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
if($env:APPVEYOR_REPO_TAG -eq "True") {
|
if($env:APPVEYOR_REPO_TAG -eq "True") {
|
||||||
# The MSI version is not semver compliant, so just take the numerical parts
|
# The MSI version is not semver compliant, so just take the numerical parts
|
||||||
$Version = $env:APPVEYOR_REPO_TAG_NAME -replace '^v?([0-9\.]+).*$','$1'
|
$Version = $env:APPVEYOR_REPO_TAG_NAME -replace '^v?([0-9\.]+).*$','$1'
|
||||||
Write-Verbose "Setting msi version to $Version"
|
Write-Verbose "Setting msi version to $Version"
|
||||||
.\installer\build.ps1 -PathToExecutable .\wmi_exporter.exe -Version $Version -Arch "amd64"
|
.\installer\build.ps1 -PathToExecutable .\wmi_exporter.exe -Version $Version -Arch "$env:MSI_ARCH"
|
||||||
Push-AppveyorArtifact installer\Output\wmi_exporter-$Version-amd64.msi -DeploymentName Installer
|
Push-AppveyorArtifact installer\Output\wmi_exporter-$Version-$env:MSI_ARCH.msi -DeploymentName Installer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
after_build:
|
||||||
|
- 7z a wmi_exporter-%MSI_ARCH%.zip wmi_exporter.exe
|
||||||
|
|
||||||
artifacts:
|
artifacts:
|
||||||
- name: Executable
|
- name: Executable
|
||||||
path: wmi_exporter.exe
|
path: 'wmi_exporter-*.zip'
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
- provider: GitHub
|
- provider: GitHub
|
||||||
|
|||||||
83
collector/service.go
Normal file
83
collector/service.go
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
// returns data points from Win32_Service
|
||||||
|
// https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx - Win32_Service class
|
||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/StackExchange/wmi"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Factories["service"] = NewserviceCollector
|
||||||
|
}
|
||||||
|
|
||||||
|
// A serviceCollector is a Prometheus collector for WMI Win32_Service metrics
|
||||||
|
type serviceCollector struct {
|
||||||
|
State *prometheus.Desc
|
||||||
|
StartMode *prometheus.Desc
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewserviceCollector ...
|
||||||
|
func NewserviceCollector() (Collector, error) {
|
||||||
|
const subsystem = "service"
|
||||||
|
return &serviceCollector{
|
||||||
|
State: prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(Namespace, subsystem, "state"),
|
||||||
|
"The state of the service (State)",
|
||||||
|
[]string{"name", "state"},
|
||||||
|
nil,
|
||||||
|
),
|
||||||
|
StartMode: prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(Namespace, subsystem, "start_mode"),
|
||||||
|
"The start mode of the service (StartMode)",
|
||||||
|
[]string{"name", "start_mode"},
|
||||||
|
nil,
|
||||||
|
),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect sends the metric values for each metric
|
||||||
|
// to the provided prometheus Metric channel.
|
||||||
|
func (c *serviceCollector) Collect(ch chan<- prometheus.Metric) error {
|
||||||
|
if desc, err := c.collect(ch); err != nil {
|
||||||
|
log.Println("[ERROR] failed collecting service metrics:", desc, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Win32_Service struct {
|
||||||
|
Name string
|
||||||
|
State string
|
||||||
|
StartMode string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
|
var dst []Win32_Service
|
||||||
|
q := wmi.CreateQuery(&dst, "")
|
||||||
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, service := range dst {
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.State,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
1.0,
|
||||||
|
strings.ToLower(service.Name),
|
||||||
|
strings.ToLower(service.State),
|
||||||
|
)
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.StartMode,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
1.0,
|
||||||
|
strings.ToLower(service.Name),
|
||||||
|
strings.ToLower(service.StartMode),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ type WmiCollector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultCollectors = "cpu,cs,logical_disk,net,os,system"
|
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system"
|
||||||
serviceName = "wmi_exporter"
|
serviceName = "wmi_exporter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,22 @@ Param(
|
|||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
$Class,
|
$Class,
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
$CollectorName = ($Class -replace 'Win32_PerfRawData_Perf','')
|
$CollectorName = ($Class -replace 'Win32_PerfRawData_Perf',''),
|
||||||
|
[Parameter(Mandatory=$false)]
|
||||||
|
$ComputerName = "localhost",
|
||||||
|
[Parameter(Mandatory=$false)]
|
||||||
|
$Credential
|
||||||
)
|
)
|
||||||
$members = Get-WMIObject $Class `
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
if($Credential -ne $null) {
|
||||||
|
$wmiObject = Get-WMIObject -ComputerName $ComputerName -Credential $Credential -Class $Class
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$wmiObject = Get-WMIObject -ComputerName $ComputerName -Class $Class
|
||||||
|
}
|
||||||
|
|
||||||
|
$members = $wmiObject `
|
||||||
| Get-Member -MemberType Properties `
|
| Get-Member -MemberType Properties `
|
||||||
| Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } `
|
| Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } `
|
||||||
| Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}}
|
| Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}}
|
||||||
|
|||||||
Reference in New Issue
Block a user