├── installer ├── .gitignore ├── icon.ico ├── codesign.cer └── build.ps1 ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── question.yaml │ └── enhancement.yaml ├── CODEOWNERS ├── release.yml ├── workflows │ ├── spelling.yml │ ├── stale.yml │ ├── stale-close.yml │ └── pr-check.yaml └── PULL_REQUEST_TEMPLATE.md ├── .gitattributes ├── tools ├── e2e-textfile.prom └── textfile-test │ ├── duplicate-filename │ ├── file.prom │ └── sub │ │ └── file.prom │ └── multiple-dirs │ ├── dir1 │ └── dir1.prom │ ├── dir2 │ └── dir2.prom │ └── dir3 │ ├── dir3.prom │ └── dir3sub │ └── dir3sub.prom ├── cmd └── windows_exporter │ ├── winres │ ├── icon.png │ └── winres.json │ └── doc.go ├── CODE_OF_CONDUCT.md ├── .idea ├── vcs.xml ├── inspectionProfiles │ └── Project_Default.xml ├── go.imports.xml ├── copyright │ ├── profiles_settings.xml │ └── windows_exporter.xml └── dictionaries │ └── project.xml ├── SECURITY.md ├── .editorconfig ├── kubernetes ├── windows-exporter-podmonitor.yaml └── windows-exporter-daemonset.yaml ├── MAINTAINERS.md ├── docs ├── example_config.yml ├── collector-template.md ├── collector.msmq.md ├── collector.license.md ├── collector.smb.md ├── collector.file.md ├── collector.pagefile.md ├── collector.udp.md ├── README.md ├── collector.nps.md ├── collector.printer.md └── collector.os.md ├── .gitignore ├── Dockerfile ├── internal ├── types │ ├── const.go │ ├── regexp.go │ └── errors.go ├── pdh │ ├── types │ │ └── types.go │ ├── registry │ │ ├── utils.go │ │ ├── perflib_test.go │ │ ├── LICENSE │ │ └── utf16.go │ ├── error.go │ └── collector_test.go ├── headers │ ├── iphlpapi │ │ ├── const.go │ │ └── iphlpapi_test.go │ ├── gdi32 │ │ └── gdi32_test.go │ ├── secur32 │ │ └── secur32_test.go │ ├── ntdll │ │ └── ntdll.go │ ├── dhcpsapi │ │ └── dhcpsapi_test.go │ ├── propsys │ │ └── propsys.go │ ├── hcn │ │ └── types.go │ ├── hcs │ │ └── hcs_test.go │ ├── shell32 │ │ └── types.go │ ├── slc │ │ └── slc.go │ ├── kernel32 │ │ └── job.go │ ├── win32 │ │ ├── utils.go │ │ └── types.go │ ├── psapi │ │ └── psapi.go │ └── cfgmgr32 │ │ └── types.go ├── collector │ ├── pagefile │ │ ├── types.go │ │ └── pagefile_test.go │ ├── thermalzone │ │ ├── types.go │ │ └── thermalzone_test.go │ ├── net │ │ ├── net_test.go │ │ ├── net_bench_test.go │ │ └── types.go │ ├── msmq │ │ ├── types.go │ │ └── msmq_test.go │ ├── ad │ │ └── ad_test.go │ ├── cpu │ │ └── cpu_test.go │ ├── dns │ │ └── dns_test.go │ ├── gpu │ │ ├── gpu_test.go │ │ ├── types.go │ │ └── utils.go │ ├── nps │ │ └── nps_test.go │ ├── smb │ │ ├── smb_test.go │ │ └── types.go │ ├── tcp │ │ ├── tcp_test.go │ │ └── types.go │ ├── udp │ │ ├── udp_test.go │ │ └── types.go │ ├── adcs │ │ ├── adcs_test.go │ │ └── types.go │ ├── adfs │ │ └── adfs_test.go │ ├── dfsr │ │ └── dfsr_test.go │ ├── dhcp │ │ └── dhcp_test.go │ ├── iis │ │ └── iis_bench_test.go │ ├── smtp │ │ └── smtp_test.go │ ├── time │ │ ├── time_test.go │ │ └── types.go │ ├── cache │ │ └── cache_test.go │ ├── mssql │ │ ├── mssql_test.go │ │ └── mssql_instance.go │ ├── os │ │ └── os_test.go │ ├── hyperv │ │ └── hyperv_test.go │ ├── memory │ │ └── memory_test.go │ ├── system │ │ ├── system_test.go │ │ └── types.go │ ├── update │ │ └── update_test.go │ ├── vmware │ │ └── vmware_test.go │ ├── license │ │ └── license_test.go │ ├── service │ │ └── service_test.go │ ├── cpu_info │ │ └── cpu_info_test.go │ ├── exchange │ │ ├── exchange_test.go │ │ └── exchange_autodiscover.go │ ├── container │ │ └── container_test.go │ ├── diskdrive │ │ └── diskdrive_test.go │ ├── fsrmquota │ │ └── fsrmquota_test.go │ ├── mscluster │ │ └── mscluster_test.go │ ├── remote_fx │ │ └── remote_fx_test.go │ ├── smbclient │ │ └── smbclient_test.go │ ├── file │ │ └── file_test.go │ ├── scheduled_task │ │ └── scheduled_task_test.go │ ├── terminal_services │ │ ├── terminal_services_test.go │ │ └── types.go │ ├── netframework │ │ └── netframework_test.go │ ├── physical_disk │ │ ├── physical_disk_test.go │ │ └── types.go │ ├── printer │ │ └── printer_test.go │ ├── process │ │ └── process_test.go │ ├── logical_disk │ │ ├── logical_disk_test.go │ │ └── types.go │ └── performancecounter │ │ ├── performancecounter_test.go │ │ └── types.go ├── mi │ ├── errors.go │ ├── doc.go │ └── mi_bench_test.go ├── osversion │ ├── osversion_windows_test.go │ └── osversion_windows.go ├── httphandler │ ├── health.go │ └── version.go ├── utils │ ├── testutils │ │ └── handle.go │ ├── counter.go │ ├── utils.go │ └── counter_test.go ├── config │ ├── flatten_test.go │ └── flatten.go └── log │ ├── flag │ └── flag.go │ ├── eventlog │ └── eventlog.go │ └── logger.go ├── config.yaml ├── .promu.yml ├── LICENSE ├── go.mod ├── pkg └── collector │ ├── types.go │ └── handler.go └── .run └── all.run.xml /installer/.gitignore: -------------------------------------------------------------------------------- 1 | Work/* 2 | Output/* 3 | WiX/* 4 | Source/* -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @prometheus-community/windows_exporter-reviewers 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.go text eol=lf 2 | *.sh text eol=lf 3 | Makefile text eol=lf -------------------------------------------------------------------------------- /installer/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prometheus-community/windows_exporter/HEAD/installer/icon.ico -------------------------------------------------------------------------------- /installer/codesign.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prometheus-community/windows_exporter/HEAD/installer/codesign.cer -------------------------------------------------------------------------------- /tools/e2e-textfile.prom: -------------------------------------------------------------------------------- 1 | # HELP test_alpha_total Some random metric. 2 | # TYPE test_alpha_total counter 3 | test_alpha_total 42 4 | 5 | -------------------------------------------------------------------------------- /cmd/windows_exporter/winres/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prometheus-community/windows_exporter/HEAD/cmd/windows_exporter/winres/icon.png -------------------------------------------------------------------------------- /tools/textfile-test/duplicate-filename/file.prom: -------------------------------------------------------------------------------- 1 | # HELP windows_test Some Test 2 | # TYPE windows_test gauge 3 | windows_test{flag="file"} 1 4 | -------------------------------------------------------------------------------- /tools/textfile-test/multiple-dirs/dir1/dir1.prom: -------------------------------------------------------------------------------- 1 | # HELP windows_test Some Test 2 | # TYPE windows_test gauge 3 | windows_test{flag="dir1"} 1 4 | -------------------------------------------------------------------------------- /tools/textfile-test/multiple-dirs/dir2/dir2.prom: -------------------------------------------------------------------------------- 1 | # HELP windows_test Some Test 2 | # TYPE windows_test gauge 3 | windows_test{flag="dir2"} 2 4 | -------------------------------------------------------------------------------- /tools/textfile-test/multiple-dirs/dir3/dir3.prom: -------------------------------------------------------------------------------- 1 | # HELP windows_test Some Test 2 | # TYPE windows_test gauge 3 | windows_test{flag="dir3"} 3 4 | -------------------------------------------------------------------------------- /tools/textfile-test/duplicate-filename/sub/file.prom: -------------------------------------------------------------------------------- 1 | # HELP windows_test Some Test 2 | # TYPE windows_test gauge 3 | windows_test{flag="sub_file"} 2 4 | -------------------------------------------------------------------------------- /tools/textfile-test/multiple-dirs/dir3/dir3sub/dir3sub.prom: -------------------------------------------------------------------------------- 1 | # HELP windows_test Some Test 2 | # TYPE windows_test gauge 3 | windows_test{flag="dir3sub"} 3 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Prometheus Community Code of Conduct 2 | 3 | Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md). 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting a security issue 2 | 3 | The Prometheus security policy, including how to report vulnerabilities, can be 4 | found here: 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/go.imports.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | tab_width = 4 9 | 10 | [*.{json,wxs,xml}] 11 | indent_style = space 12 | indent_size = 4 13 | 14 | [renovate.json] 15 | indent_size = 2 16 | 17 | [*.{yml,yaml}] 18 | indent_style = space 19 | indent_size = 2 20 | -------------------------------------------------------------------------------- /kubernetes/windows-exporter-podmonitor.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: monitoring.coreos.com/v1 2 | kind: PodMonitor 3 | metadata: 4 | labels: 5 | app: windows-exporter 6 | name: windows-exporter 7 | namespace: monitoring 8 | spec: 9 | jobLabel: windows-exporter 10 | selector: 11 | matchLabels: 12 | app: windows-exporter 13 | podMetricsEndpoints: 14 | - port: http 15 | scheme: http 16 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | Maintainers in alphabetical order 2 | 3 | * [Ben Reedy](https://github.com/breed808) - breed808@breed808.com 4 | * [Calle Pettersson](https://github.com/carlpett) - calle@cape.nu 5 | * [Jan-Otto Kröpke](https://github.com/jkroepke) - github@jkroepke.de 6 | 7 | Alumni 8 | 9 | * [Brian Brazil](https://github.com/brian-brazil) 10 | * [Martin Lindhe](https://github.com/martinlindhe) 11 | -------------------------------------------------------------------------------- /docs/example_config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Note this is not an exhaustive list of all configuration values 3 | collectors: 4 | enabled: cpu,logical_disk,net,os,service,system 5 | collector: 6 | service: 7 | include: "windows_exporter" 8 | scheduled_task: 9 | include: /Microsoft/.+ 10 | log: 11 | level: debug 12 | scrape: 13 | timeout-margin: 0.5 14 | telemetry: 15 | path: /metrics 16 | web: 17 | listen-address: ":9182" 18 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/dictionaries/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | containerd 5 | endpointstats 6 | gochecknoglobals 7 | lpwstr 8 | luid 9 | operationoptions 10 | setupapi 11 | spdx 12 | textfile 13 | vmcompute 14 | 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | VERSION 3 | *.swp 4 | *.un~ 5 | output/ 6 | .vscode 7 | *.syso 8 | installer/*.msi 9 | installer/*.log 10 | installer/*.wixpdb 11 | local/ 12 | 13 | /.idea/* 14 | !/.idea/inspectionProfiles/ 15 | /.idea/inspectionProfiles/* 16 | !/.idea/inspectionProfiles/Project_Default.xml 17 | !/.idea/dictionaries/ 18 | /.idea/dictionaries/* 19 | !/.idea/dictionaries/project.xml 20 | /.idea/copyright/* 21 | !/.idea/copyright/profiles_settings.xml 22 | !/.idea/copyright/windows_exporter.xml 23 | !/.idea/vcs.xml 24 | !/.idea/go.imports.xml 25 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - chore 5 | categories: 6 | - title: 💥 Breaking Changes 7 | labels: 8 | - 💥 breaking-change 9 | - title: ✨ Exciting New Features 10 | labels: 11 | - ✨ enhancement 12 | - title: 🐞 Bug Fixes 13 | labels: 14 | - 🐞 bug 15 | - title: 🛠️ Dependencies 16 | labels: 17 | - 🛠️ dependencies 18 | - title: 📖 Documentation 19 | labels: 20 | - 📖 docs 21 | - title: Other Changes 22 | labels: 23 | - "*" -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 2 | # Using this image as a base for HostProcess containers has a few advantages over using other base images for Windows containers including: 3 | # - Smaller image size 4 | # - OS compatibility (works on any Windows version that supports containers) 5 | 6 | # This image MUST be built with docker buildx build (buildx) command on a Linux system. 7 | # Ref: https://github.com/microsoft/windows-host-process-containers-base-image 8 | 9 | ARG BASE="mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0" 10 | FROM $BASE 11 | 12 | COPY windows_exporter*-amd64.exe /windows_exporter.exe 13 | ENTRYPOINT ["windows_exporter.exe"] 14 | -------------------------------------------------------------------------------- /.github/workflows/spelling.yml: -------------------------------------------------------------------------------- 1 | name: Spell checking 2 | 3 | # Trigger on pull requests, and pushes to master branch. 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | branches: 10 | - master 11 | 12 | env: 13 | VERSION_PROMU: 'v0.14.0' 14 | 15 | jobs: 16 | codespell: 17 | name: Check for spelling errors 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 21 | - uses: codespell-project/actions-codespell@master 22 | with: 23 | check_filenames: true 24 | # When using this Action in other repos, the --skip option below can be removed 25 | skip: ./.git,go.mod,go.sum 26 | ignore_words_list: calle,Entires 27 | -------------------------------------------------------------------------------- /internal/types/const.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package types 19 | 20 | const ( 21 | Namespace = "windows" 22 | ) 23 | -------------------------------------------------------------------------------- /internal/pdh/types/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package types 19 | 20 | type Collector interface { 21 | Collect(dst any) error 22 | Close() 23 | } 24 | -------------------------------------------------------------------------------- /internal/headers/iphlpapi/const.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package iphlpapi 19 | 20 | const ( 21 | TCPTableOwnerPIDAll uint32 = 5 22 | TCPTableOwnerPIDListener uint32 = 3 23 | ) 24 | -------------------------------------------------------------------------------- /internal/collector/pagefile/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package pagefile 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | Usage float64 `perfdata:"% Usage"` 24 | } 25 | -------------------------------------------------------------------------------- /cmd/windows_exporter/doc.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | /* 17 | The main package for the windows_exporter executable. 18 | 19 | usage: windows_exporter [] 20 | 21 | A metrics collector for Windows. 22 | */ 23 | package main 24 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | # example configuration file for windows_exporter 2 | 3 | collectors: 4 | enabled: cpu,cpu_info,exchange,iis,logical_disk,memory,net,os,performancecounter,process,remote_fx,service,system,tcp,time,terminal_services,textfile 5 | collector: 6 | textfile: 7 | directories: 8 | - 'C:\MyDir1' 9 | - 'C:\MyDir2' 10 | service: 11 | include: "windows_exporter" 12 | performancecounter: 13 | objects: |- 14 | - name: photon_udp 15 | object: "Photon Socket Server: UDP" 16 | instances: ["*"] 17 | counters: 18 | - name: "UDP: Datagrams in" 19 | metric: "photon_udp_datagrams" 20 | labels: 21 | direction: "in" 22 | - name: "UDP: Datagrams out" 23 | metric: "photon_udp_datagrams" 24 | labels: 25 | direction: "out" 26 | log: 27 | level: warn 28 | -------------------------------------------------------------------------------- /internal/types/regexp.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package types 19 | 20 | import "regexp" 21 | 22 | var ( 23 | RegExpAny = regexp.MustCompile("^.+$") 24 | RegExpEmpty = regexp.MustCompile("^$") 25 | ) 26 | -------------------------------------------------------------------------------- /.promu.yml: -------------------------------------------------------------------------------- 1 | go: 2 | # Whenever the Go version is updated here, 3 | # .github/workflows should also be updated. 4 | version: 1.23 5 | cgo: false 6 | repository: 7 | path: github.com/prometheus-community/windows_exporter 8 | build: 9 | binaries: 10 | - name: windows_exporter 11 | path: ./cmd/windows_exporter 12 | tags: 13 | all: 14 | - trimpath 15 | ldflags: | 16 | -X github.com/prometheus/common/version.Version={{.Version}} 17 | -X github.com/prometheus/common/version.Revision={{.Revision}} 18 | -X github.com/prometheus/common/version.Branch={{.Branch}} 19 | -X github.com/prometheus/common/version.BuildUser={{user}}@{{host}} 20 | -X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} 21 | tarball: 22 | files: 23 | - LICENSE 24 | crossbuild: 25 | platforms: 26 | - windows/amd64 27 | - windows/arm64 28 | -------------------------------------------------------------------------------- /docs/collector-template.md: -------------------------------------------------------------------------------- 1 | # %name% collector 2 | 3 | The %name% collector exposes metrics about ... 4 | 5 | ||| 6 | -|- 7 | Metric name prefix | `%name%` 8 | Classes | [`...`](https://msdn.microsoft.com/en-us/library/...) 9 | Enabled by default? | Yes/No 10 | 11 | ## Flags 12 | 13 | ### `--collector....` 14 | 15 | Add description... 16 | 17 | Example: `--collector....` 18 | 19 | ## Metrics 20 | 21 | Name | Description | Type | Labels 22 | -----|-------------|------|------- 23 | `windows_...` | ... | counter/gauge/histogram/summary | ... 24 | 25 | ### Example metric 26 | 27 | ...: 28 | 29 | `windows_...{...} 1` 30 | 31 | ## Useful queries 32 | ### Add queries... 33 | 34 | `...` 35 | 36 | ## Alerting examples 37 | ### Add alerts... 38 | 39 | ```yaml 40 | - alert: "" 41 | expr: "" 42 | for: "" 43 | labels: 44 | urgency: "" 45 | annotations: 46 | summary: "" 47 | ``` 48 | -------------------------------------------------------------------------------- /internal/mi/errors.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package mi 19 | 20 | import "errors" 21 | 22 | var ( 23 | ErrNotInitialized = errors.New("not initialized") 24 | ErrInvalidEntityType = errors.New("invalid entity type") 25 | ) 26 | -------------------------------------------------------------------------------- /.idea/copyright/windows_exporter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /internal/pdh/registry/utils.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package registry 19 | 20 | import ( 21 | "strconv" 22 | ) 23 | 24 | func MapCounterToIndex(name string) string { 25 | return strconv.Itoa(int(CounterNameTable.LookupIndex(name))) 26 | } 27 | -------------------------------------------------------------------------------- /internal/pdh/registry/perflib_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package registry 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | func BenchmarkQueryPerformanceData(b *testing.B) { 25 | for b.Loop() { 26 | _, _ = QueryPerformanceData("Global", "") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /internal/types/errors.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package types 19 | 20 | import "errors" 21 | 22 | var ( 23 | ErrCollectorNotInitialized = errors.New("collector not initialized") 24 | ErrNoData = errors.New("no data") 25 | ErrNoDataUnexpected = errors.New("no data") 26 | ) 27 | -------------------------------------------------------------------------------- /internal/mi/doc.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | // mi is a package that provides a Go API for Windows Management Infrastructure (MI) functions. 19 | // It requires Windows Management Framework 3.0 or later. 20 | // 21 | // https://learn.microsoft.com/de-de/previous-versions/windows/desktop/wmi_v2/why-use-mi- 22 | package mi 23 | -------------------------------------------------------------------------------- /internal/collector/thermalzone/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package thermalzone 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | HighPrecisionTemperature float64 `perfdata:"High Precision Temperature"` 24 | PercentPassiveLimit float64 `perfdata:"% Passive Limit"` 25 | ThrottleReasons float64 `perfdata:"Throttle Reasons"` 26 | } 27 | -------------------------------------------------------------------------------- /internal/collector/net/net_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package net_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/net" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func TestCollector(t *testing.T) { 28 | testutils.TestCollector(t, net.New, nil) 29 | } 30 | -------------------------------------------------------------------------------- /internal/headers/gdi32/gdi32_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gdi32_test 17 | 18 | import ( 19 | "testing" 20 | 21 | "github.com/prometheus-community/windows_exporter/internal/headers/gdi32" 22 | "github.com/stretchr/testify/require" 23 | ) 24 | 25 | func TestGetGPUDevices(t *testing.T) { 26 | devices, err := gdi32.GetGPUDevices() 27 | require.NoError(t, err, "Failed to get GPU devices") 28 | 29 | require.NotNil(t, devices) 30 | } 31 | -------------------------------------------------------------------------------- /internal/collector/msmq/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package msmq 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | BytesInJournalQueue float64 `perfdata:"Bytes in Journal Queue"` 24 | BytesInQueue float64 `perfdata:"Bytes in Queue"` 25 | MessagesInJournalQueue float64 `perfdata:"Messages in Journal Queue"` 26 | MessagesInQueue float64 `perfdata:"Messages in Queue"` 27 | } 28 | -------------------------------------------------------------------------------- /internal/headers/secur32/secur32_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package secur32_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/headers/secur32" 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestGetLogonSessions(t *testing.T) { 28 | t.Parallel() 29 | 30 | sessionData, err := secur32.GetLogonSessions() 31 | require.NoError(t, err) 32 | require.NotEmpty(t, sessionData) 33 | } 34 | -------------------------------------------------------------------------------- /internal/osversion/osversion_windows_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package osversion 19 | 20 | import ( 21 | "fmt" 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestOSVersionString(t *testing.T) { 28 | v := OSVersion{ 29 | Version: 809042555, 30 | MajorVersion: 123, 31 | MinorVersion: 2, 32 | Build: 12345, 33 | } 34 | 35 | require.Equal(t, "the version is: 123.2.12345", fmt.Sprintf("the version is: %s", v)) 36 | } 37 | -------------------------------------------------------------------------------- /internal/collector/ad/ad_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package ad_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/ad" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, ad.Name, ad.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, ad.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/cpu/cpu_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package cpu_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/cpu" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, cpu.Name, cpu.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, cpu.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/dns/dns_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package dns_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/dns" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, dns.Name, dns.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, dns.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/gpu/gpu_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package gpu_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/gpu" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, gpu.Name, gpu.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, gpu.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/nps/nps_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package nps_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/nps" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, nps.Name, nps.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, nps.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/smb/smb_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package smb_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/smb" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, smb.Name, smb.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, smb.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/tcp/tcp_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package tcp_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/tcp" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, tcp.Name, tcp.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, tcp.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/udp/udp_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package udp_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/udp" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, udp.Name, udp.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, udp.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/adcs/adcs_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package adcs_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/adcs" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, adcs.Name, adcs.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, adcs.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/adfs/adfs_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package adfs_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/adfs" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, adfs.Name, adfs.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, adfs.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/dfsr/dfsr_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package dfsr_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/dfsr" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, dfsr.Name, dfsr.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, dfsr.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/dhcp/dhcp_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package dhcp_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/dhcp" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, dhcp.Name, dhcp.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, dhcp.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/iis/iis_bench_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package iis_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/iis" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, iis.Name, iis.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, iis.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/smtp/smtp_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package smtp_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/smtp" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, smtp.Name, smtp.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, smtp.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/time/time_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package time_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/time" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, time.Name, time.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, time.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/httphandler/health.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package httphandler 19 | 20 | import ( 21 | "net/http" 22 | ) 23 | 24 | type HealthHandler struct{} 25 | 26 | // Interface guard. 27 | var _ http.Handler = (*HealthHandler)(nil) 28 | 29 | func NewHealthHandler() HealthHandler { 30 | return HealthHandler{} 31 | } 32 | 33 | func (h HealthHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) { 34 | w.Header().Set("Content-Type", "application/json") 35 | _, _ = w.Write([]byte(`{"status":"ok"}`)) 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Martin Lindhe 4 | Copyright (c) 2021 The Prometheus Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /internal/collector/cache/cache_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package cache_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/cache" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, cache.Name, cache.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, cache.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/mssql/mssql_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package mssql_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/mssql" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, mssql.Name, mssql.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, mssql.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/os/os_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package os_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/os" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, os.Name, os.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | t.Skip() 33 | 34 | testutils.TestCollector(t, os.New, nil) 35 | } 36 | -------------------------------------------------------------------------------- /internal/pdh/registry/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Leopold Schabel / The perflib_exporter authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /internal/collector/hyperv/hyperv_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package hyperv_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/hyperv" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, hyperv.Name, hyperv.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, hyperv.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/memory/memory_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package memory_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/memory" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, memory.Name, memory.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, memory.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/system/system_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package system_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/system" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, system.Name, system.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, system.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/update/update_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package update_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/update" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, update.Name, update.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, update.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/vmware/vmware_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package vmware_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/vmware" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, vmware.Name, vmware.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, vmware.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/license/license_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package license_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/license" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, license.Name, license.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, license.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/service/service_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package service_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/service" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, service.Name, service.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, service.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/headers/ntdll/ntdll.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package ntdll 19 | 20 | import ( 21 | "golang.org/x/sys/windows" 22 | ) 23 | 24 | //nolint:gochecknoglobals 25 | var ( 26 | modNtdll = windows.NewLazySystemDLL("ntdll.dll") 27 | procRtlNtStatusToDosError = modNtdll.NewProc("RtlNtStatusToDosError") 28 | ) 29 | 30 | func RtlNtStatusToDosError(status uintptr) error { 31 | ret, _, _ := procRtlNtStatusToDosError.Call(status) 32 | if ret == 0 { 33 | return nil 34 | } 35 | 36 | return windows.Errno(ret) 37 | } 38 | -------------------------------------------------------------------------------- /internal/collector/cpu_info/cpu_info_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package cpu_info_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/cpu_info" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, cpu_info.Name, cpu_info.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, cpu_info.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/exchange/exchange_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package exchange_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/exchange" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, exchange.Name, exchange.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, exchange.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/pagefile/pagefile_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package pagefile_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/pagefile" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, pagefile.Name, pagefile.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, pagefile.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/system/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package system 19 | 20 | type perfDataCounterValues struct { 21 | ContextSwitchesPerSec float64 `perfdata:"Context Switches/sec"` 22 | ExceptionDispatchesPerSec float64 `perfdata:"Exception Dispatches/sec"` 23 | ProcessorQueueLength float64 `perfdata:"Processor Queue Length"` 24 | SystemCallsPerSec float64 `perfdata:"System Calls/sec"` 25 | Processes float64 `perfdata:"Processes"` 26 | Threads float64 `perfdata:"Threads"` 27 | } 28 | -------------------------------------------------------------------------------- /internal/collector/container/container_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package container_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/container" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, container.Name, container.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, container.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/diskdrive/diskdrive_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package diskdrive_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/diskdrive" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, diskdrive.Name, diskdrive.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, diskdrive.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/fsrmquota/fsrmquota_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package fsrmquota_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/fsrmquota" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, fsrmquota.Name, fsrmquota.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, fsrmquota.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/mscluster/mscluster_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package mscluster_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/mscluster" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, mscluster.Name, mscluster.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, mscluster.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/remote_fx/remote_fx_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package remote_fx_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/remote_fx" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, remote_fx.Name, remote_fx.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, remote_fx.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/smbclient/smbclient_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package smbclient_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/smbclient" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, smbclient.Name, smbclient.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, smbclient.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/thermalzone/thermalzone_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package thermalzone_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/thermalzone" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, thermalzone.Name, thermalzone.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, thermalzone.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/collector/file/file_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package file_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/file" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, file.Name, file.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, file.New, &file.Config{ 33 | FilePatterns: []string{"*.*"}, 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /internal/collector/msmq/msmq_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package msmq_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/msmq" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | // No context name required as Collector source is WMI 29 | testutils.FuncBenchmarkCollector(b, msmq.Name, msmq.NewWithFlags) 30 | } 31 | 32 | func TestCollector(t *testing.T) { 33 | testutils.TestCollector(t, msmq.New, nil) 34 | } 35 | -------------------------------------------------------------------------------- /internal/collector/scheduled_task/scheduled_task_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package scheduled_task_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/scheduled_task" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, scheduled_task.Name, scheduled_task.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, scheduled_task.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/headers/dhcpsapi/dhcpsapi_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package dhcpsapi 19 | 20 | import ( 21 | "errors" 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | "golang.org/x/sys/windows" 26 | ) 27 | 28 | func TestGetDHCPV4ScopeStatistics(t *testing.T) { 29 | t.Parallel() 30 | 31 | if procDhcpGetSuperScopeInfoV4.Find() != nil { 32 | t.Skip("DhcpGetSuperScopeInfoV4 is not available") 33 | } 34 | 35 | _, err := GetDHCPV4ScopeStatistics() 36 | if errors.Is(err, windows.Errno(1753)) { 37 | t.Skip(err.Error()) 38 | } 39 | 40 | require.NoError(t, err) 41 | } 42 | -------------------------------------------------------------------------------- /internal/collector/terminal_services/terminal_services_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package terminal_services_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/terminal_services" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | testutils.FuncBenchmarkCollector(b, terminal_services.Name, terminal_services.NewWithFlags) 29 | } 30 | 31 | func TestCollector(t *testing.T) { 32 | testutils.TestCollector(t, terminal_services.New, nil) 33 | } 34 | -------------------------------------------------------------------------------- /internal/utils/testutils/handle.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package testutils 17 | 18 | import ( 19 | "unsafe" 20 | 21 | "golang.org/x/sys/windows" 22 | ) 23 | 24 | //nolint:gochecknoglobals 25 | var ( 26 | modkernel32 = windows.NewLazySystemDLL("kernel32.dll") 27 | 28 | procGetProcessHandleCount = modkernel32.NewProc("GetProcessHandleCount") 29 | ) 30 | 31 | func GetProcessHandleCount(handle windows.Handle) (uint32, error) { 32 | var count uint32 33 | 34 | r1, _, err := procGetProcessHandleCount.Call( 35 | uintptr(handle), 36 | uintptr(unsafe.Pointer(&count)), 37 | ) 38 | 39 | if r1 != 1 { 40 | return 0, err 41 | } 42 | 43 | return count, nil 44 | } 45 | -------------------------------------------------------------------------------- /installer/build.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | Param ( 3 | [Parameter(Mandatory = $true)] 4 | [String] $PathToExecutable, 5 | [Parameter(Mandatory = $true)] 6 | [String] $Version, 7 | [Parameter(Mandatory = $false)] 8 | [ValidateSet("amd64", "arm64")] 9 | [String] $Arch = "amd64" 10 | ) 11 | $ErrorActionPreference = "Stop" 12 | 13 | # The MSI version is not semver compliant, so just take the numerical parts 14 | $MsiVersion = $Version -replace '^v?([0-9\.]+).*$','$1' 15 | 16 | # Get absolute path to executable before switching directories 17 | $PathToExecutable = Resolve-Path $PathToExecutable 18 | # Set working dir to this directory, reset previous on exit 19 | Push-Location $PSScriptRoot 20 | Trap { 21 | # Reset working dir on error 22 | Pop-Location 23 | } 24 | 25 | mkdir -Force Work | Out-Null 26 | Copy-Item -Force $PathToExecutable Work/windows_exporter.exe 27 | 28 | Write-Verbose "Creating windows_exporter-${Version}-${Arch}.msi" 29 | $wixArch = @{"amd64" = "x64"; "arm64" = "arm64"}[$Arch] 30 | 31 | Invoke-Expression "wix build -sw1149 -arch $wixArch -o .\windows_exporter-$($Version)-$($Arch).msi .\files.wxs .\main.wxs -d ProductName=windows_exporter -d Version=$($MsiVersion) -ext WixToolset.Firewall.wixext -ext WixToolset.UI.wixext -ext WixToolset.Util.wixext" 32 | 33 | Write-Verbose "Done!" 34 | Pop-Location 35 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Stale Check 2 | on: 3 | workflow_dispatch: {} 4 | schedule: 5 | - cron: '16 22 * * *' 6 | permissions: 7 | issues: write 8 | pull-requests: write 9 | jobs: 10 | stale: 11 | if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks. 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/stale@997185467fa4f803885201cee163a9f38240193d # v10.1.1 15 | with: 16 | repo-token: ${{ secrets.GITHUB_TOKEN }} 17 | # opt out of defaults to avoid marking issues as stale and closing them 18 | # https://github.com/actions/stale#days-before-close 19 | # https://github.com/actions/stale#days-before-stale 20 | days-before-stale: -1 21 | days-before-close: -1 22 | # Setting it to empty string to skip comments. 23 | # https://github.com/actions/stale#stale-pr-message 24 | # https://github.com/actions/stale#stale-issue-message 25 | stale-pr-message: '' 26 | stale-issue-message: '' 27 | operations-per-run: 30 28 | # override days-before-stale, for only marking the pull requests as stale 29 | days-before-pr-stale: 60 30 | stale-pr-label: stale 31 | exempt-pr-labels: keepalive 32 | -------------------------------------------------------------------------------- /internal/collector/smb/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package smb 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | CurrentOpenFileCount float64 `perfdata:"Current Open File Count"` 24 | TreeConnectCount float64 `perfdata:"Tree Connect Count"` 25 | ReceivedBytes float64 `perfdata:"Received Bytes/sec"` 26 | WriteRequests float64 `perfdata:"Write Requests/sec"` 27 | ReadRequests float64 `perfdata:"Read Requests/sec"` 28 | MetadataRequests float64 `perfdata:"Metadata Requests/sec"` 29 | SentBytes float64 `perfdata:"Sent Bytes/sec"` 30 | FilesOpened float64 `perfdata:"Files Opened/sec"` 31 | } 32 | -------------------------------------------------------------------------------- /internal/collector/netframework/netframework_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package netframework_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/netframework" 24 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 25 | ) 26 | 27 | func BenchmarkCollector(b *testing.B) { 28 | // No context name required as Collector source is WMI 29 | testutils.FuncBenchmarkCollector(b, netframework.Name, netframework.NewWithFlags) 30 | } 31 | 32 | func TestCollector(t *testing.T) { 33 | t.Skip("Skipping test as it requires WMI data") 34 | 35 | testutils.TestCollector(t, netframework.New, nil) 36 | } 37 | -------------------------------------------------------------------------------- /.github/workflows/stale-close.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | on: 3 | workflow_dispatch: {} 4 | schedule: 5 | - cron: '30 1 * * *' 6 | permissions: 7 | issues: write 8 | pull-requests: write 9 | jobs: 10 | stale: 11 | if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks. 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/stale@997185467fa4f803885201cee163a9f38240193d # v10.1.1 15 | with: 16 | repo-token: ${{ secrets.GITHUB_TOKEN }} 17 | # opt out of defaults to avoid marking issues as stale and closing them 18 | # https://github.com/actions/stale#days-before-close 19 | # https://github.com/actions/stale#days-before-stale 20 | days-before-stale: -1 21 | days-before-close: -1 22 | stale-pr-message: '' 23 | stale-issue-message: 'This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.' 24 | operations-per-run: 30 25 | # override days-before-stale, for only marking the pull requests as stale 26 | days-before-issue-stale: 90 27 | days-before-issue-close: 30 28 | stale-pr-label: stale 29 | exempt-pr-labels: keepalive 30 | -------------------------------------------------------------------------------- /internal/collector/physical_disk/physical_disk_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package physical_disk_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/collector/physical_disk" 24 | "github.com/prometheus-community/windows_exporter/internal/types" 25 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 26 | ) 27 | 28 | func BenchmarkCollector(b *testing.B) { 29 | testutils.FuncBenchmarkCollector(b, physical_disk.Name, physical_disk.NewWithFlags) 30 | } 31 | 32 | func TestCollector(t *testing.T) { 33 | testutils.TestCollector(t, physical_disk.New, &physical_disk.Config{ 34 | DiskInclude: types.RegExpAny, 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /internal/utils/counter.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package utils 19 | 20 | type Counter struct { 21 | lastValue uint32 22 | totalValue float64 23 | } 24 | 25 | // NewCounter creates a new Counter that accepts uint32 values and returns float64 values. 26 | // It resolve the overflow issue of uint32 by using the difference between the last value and the current value. 27 | func NewCounter(lastValue uint32) Counter { 28 | return Counter{ 29 | lastValue: lastValue, 30 | totalValue: 0, 31 | } 32 | } 33 | 34 | func (c *Counter) AddValue(value uint32) { 35 | c.totalValue += float64(value - c.lastValue) 36 | c.lastValue = value 37 | } 38 | 39 | func (c *Counter) Value() float64 { 40 | return c.totalValue 41 | } 42 | -------------------------------------------------------------------------------- /docs/collector.msmq.md: -------------------------------------------------------------------------------- 1 | # msmq collector 2 | 3 | The msmq collector exposes metrics about the queues on a MSMQ server 4 | 5 | | | | 6 | |---------------------|----------------------| 7 | | Metric name prefix | `msmq` | 8 | | Source | Performance Counters | 9 | | Enabled by default? | No | 10 | 11 | ## Flags 12 | 13 | ## Metrics 14 | 15 | | Name | Description | Type | Labels | 16 | |------------------------------------------|---------------------------------|-------|--------| 17 | | `windows_msmq_bytes_in_journal_queue` | Size of queue journal in bytes | gauge | `name` | 18 | | `windows_msmq_bytes_in_queue` | Size of queue in bytes | gauge | `name` | 19 | | `windows_msmq_messages_in_journal_queue` | Count messages in queue journal | gauge | `name` | 20 | | `windows_msmq_messages_in_queue` | Count messages in queue | gauge | `name` | 21 | 22 | ### Example metric 23 | _This collector does not yet have explained examples, we would appreciate your help adding them!_ 24 | 25 | ## Useful queries 26 | _This collector does not yet have any useful queries added, we would appreciate your help adding them!_ 27 | 28 | ## Alerting examples 29 | _This collector does not yet have alerting examples, we would appreciate your help adding them!_ 30 | -------------------------------------------------------------------------------- /internal/collector/net/net_bench_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package net_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/alecthomas/kingpin/v2" 24 | "github.com/prometheus-community/windows_exporter/internal/collector/net" 25 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 26 | ) 27 | 28 | func BenchmarkCollector(b *testing.B) { 29 | // PrinterInclude is not set in testing context (kingpin flags not parsed), causing the collector to skip all interfaces. 30 | localNicInclude := ".+" 31 | 32 | testutils.FuncBenchmarkCollector(b, net.Name, net.NewWithFlags, func(app *kingpin.Application) { 33 | app.GetFlag("collector.net.nic-include").StringVar(&localNicInclude) 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /internal/collector/time/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package time 19 | 20 | type perfDataCounterValues struct { 21 | ClockFrequencyAdjustment float64 `perfdata:"Clock Frequency Adjustment"` 22 | ClockFrequencyAdjustmentPPB float64 `perfdata:"Clock Frequency Adjustment (ppb)" perfdata_min_build:"17763"` 23 | ComputedTimeOffset float64 `perfdata:"Computed Time Offset"` 24 | NTPClientTimeSourceCount float64 `perfdata:"NTP Client Time Source Count"` 25 | NTPRoundTripDelay float64 `perfdata:"NTP Roundtrip Delay"` 26 | NTPServerIncomingRequestsTotal float64 `perfdata:"NTP Server Incoming Requests"` 27 | NTPServerOutgoingResponsesTotal float64 `perfdata:"NTP Server Outgoing Responses"` 28 | } 29 | -------------------------------------------------------------------------------- /docs/collector.license.md: -------------------------------------------------------------------------------- 1 | # license collector 2 | 3 | The license collector exposes metrics about the Windows license status. 4 | 5 | ||| 6 | -|- 7 | Metric name prefix | `license` 8 | Data source | Win32 9 | Enabled by default? | No 10 | 11 | ## Flags 12 | 13 | None 14 | 15 | ## Metrics 16 | 17 | | Name | Description | Type | Labels | 18 | |--------------------------|----------------|-------|---------| 19 | | `windows_license_status` | license status | gauge | `state` | 20 | 21 | ### Example metric 22 | 23 | ``` 24 | # HELP windows_license_status Status of windows license 25 | # TYPE windows_license_status gauge 26 | windows_license_status{state="genuine"} 1 27 | windows_license_status{state="invalid_license"} 0 28 | windows_license_status{state="last"} 0 29 | windows_license_status{state="offline"} 0 30 | windows_license_status{state="tampered"} 0 31 | ``` 32 | 33 | 34 | ## Useful queries 35 | 36 | Show if the license is genuine 37 | 38 | ``` 39 | windows_license_status{state="genuine"} 40 | ``` 41 | 42 | ## Alerting examples 43 | **prometheus.rules** 44 | ```yaml 45 | - alert: "WindowsLicense" 46 | expr: 'windows_license_status{state="genuine"} == 0' 47 | for: "10m" 48 | labels: 49 | severity: "high" 50 | annotations: 51 | summary: "Windows system license is not genuine" 52 | description: "The Windows system license is not genuine. Please check the license status." 53 | ``` 54 | -------------------------------------------------------------------------------- /docs/collector.smb.md: -------------------------------------------------------------------------------- 1 | # smb collector 2 | 3 | The smb collector collects metrics from MS Smb hosts through perflib 4 | ======= 5 | 6 | 7 | ||| 8 | -|- 9 | Metric name prefix | `smb` 10 | Classes | [Win32_PerfRawData_SMB](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb/)
11 | Enabled by default? | No 12 | 13 | ## Flags 14 | 15 | ### `--collectors.smb.list` 16 | Lists the Perflib Objects that are queried for data along with the perlfib object id 17 | 18 | ### `--collectors.smb.enabled` 19 | Comma-separated list of collectors to use, for example: `--collectors.smb.enabled=ServerShares`. Matching is case-sensitive. Depending on the smb installation not all performance counters are available. Use `--collectors.smb.list` to obtain a list of supported collectors. 20 | 21 | ## Metrics 22 | Name | Description 23 | --------------|--------------- 24 | `windows_smb_server_shares_current_open_file_count` | Current total count open files on the SMB Server 25 | `windows_smb_server_shares_tree_connect_count` | Count of user connections to the SMB Server 26 | 27 | ### Example metric 28 | _This collector does not yet have explained examples, we would appreciate your help adding them!_ 29 | 30 | ## Useful queries 31 | _This collector does not yet have any useful queries added, we would appreciate your help adding them!_ 32 | 33 | ## Alerting examples 34 | _This collector does not yet have alerting examples, we would appreciate your help adding them!_ 35 | 36 | -------------------------------------------------------------------------------- /internal/collector/printer/printer_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package printer_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/alecthomas/kingpin/v2" 24 | "github.com/prometheus-community/windows_exporter/internal/collector/printer" 25 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 26 | ) 27 | 28 | func BenchmarkCollector(b *testing.B) { 29 | // Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all printers. 30 | printersInclude := ".+" 31 | 32 | testutils.FuncBenchmarkCollector(b, "printer", printer.NewWithFlags, func(app *kingpin.Application) { 33 | app.GetFlag("collector.printer.include").StringVar(&printersInclude) 34 | }) 35 | } 36 | 37 | func TestCollector(t *testing.T) { 38 | testutils.TestCollector(t, printer.New, nil) 39 | } 40 | -------------------------------------------------------------------------------- /internal/pdh/error.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package pdh 19 | 20 | import "errors" 21 | 22 | var ( 23 | ErrNoData = NewPdhError(NoData) 24 | ErrPerformanceCounterNotInitialized = errors.New("performance counter not initialized") 25 | ) 26 | 27 | // Error represents error returned from Performance Counters API. 28 | type Error struct { 29 | ErrorCode uint32 30 | errorText string 31 | } 32 | 33 | func (m *Error) Is(err error) bool { 34 | if err == nil { 35 | return false 36 | } 37 | 38 | var e *Error 39 | if errors.As(err, &e) { 40 | return m.ErrorCode == e.ErrorCode 41 | } 42 | 43 | return false 44 | } 45 | 46 | func (m *Error) Error() string { 47 | return m.errorText 48 | } 49 | 50 | func NewPdhError(code uint32) error { 51 | return &Error{ 52 | ErrorCode: code, 53 | errorText: FormatError(code), 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /internal/collector/process/process_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package process_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/alecthomas/kingpin/v2" 24 | "github.com/prometheus-community/windows_exporter/internal/collector/process" 25 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 26 | ) 27 | 28 | func BenchmarkProcessCollector(b *testing.B) { 29 | // PrinterInclude is not set in testing context (kingpin flags not parsed), causing the collector to skip all processes. 30 | localProcessInclude := ".+" 31 | // No context name required as collector source is WMI 32 | testutils.FuncBenchmarkCollector(b, process.Name, process.NewWithFlags, func(app *kingpin.Application) { 33 | app.GetFlag("collector.process.include").StringVar(&localProcessInclude) 34 | }) 35 | } 36 | 37 | func TestCollector(t *testing.T) { 38 | testutils.TestCollector(t, process.New, nil) 39 | } 40 | -------------------------------------------------------------------------------- /docs/collector.file.md: -------------------------------------------------------------------------------- 1 | # file collector 2 | 3 | The file collector exposes modified timestamps and file size of files in the filesystem. 4 | 5 | The collector 6 | 7 | ||| 8 | -|- 9 | Metric name prefix | `file` 10 | Enabled by default? | No 11 | 12 | ## Flags 13 | 14 | ### `--collector.file.file-patterns` 15 | Comma-separated list of file patterns. Each pattern is a glob pattern that can contain `*`, `?`, and `**` (recursive). 16 | See https://github.com/bmatcuk/doublestar#patterns for an extended description of the pattern syntax. 17 | 18 | ## Metrics 19 | 20 | | Name | Description | Type | Labels | 21 | |----------------------------------------|------------------------|-------|--------| 22 | | `windows_file_mtime_timestamp_seconds` | File modification time | gauge | `file` | 23 | | `windows_file_size_bytes` | File size | gauge | `file` | 24 | 25 | ### Example metric 26 | 27 | ``` 28 | # HELP windows_file_mtime_timestamp_seconds File modification time 29 | # TYPE windows_file_mtime_timestamp_seconds gauge 30 | windows_file_mtime_timestamp_seconds{file="C:\\Users\\admin\\Desktop\\Dashboard.lnk"} 1.726434517e+09 31 | # HELP windows_file_size_bytes File size 32 | # TYPE windows_file_size_bytes gauge 33 | windows_file_size_bytes{file="C:\\Users\\admin\\Desktop\\Dashboard.lnk"} 123 34 | ``` 35 | 36 | ## Useful queries 37 | _This collector does not yet have any useful queries added, we would appreciate your help adding them!_ 38 | 39 | ## Alerting examples 40 | _This collector does not yet have alerting examples, we would appreciate your help adding them!_ 41 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | #### What this PR does / why we need it 21 | 22 | #### Which issue this PR fixes 23 | 24 | *(optional, in `fixes #(, fixes #, ...)` format, will close that issue when PR gets merged)*: fixes # 25 | 26 | - fixes # 27 | 28 | #### Special notes for your reviewer 29 | 30 | #### Particularly user-facing changes 31 | 32 | #### Checklist 33 | 34 | Complete these before marking the PR as `ready to review`: 35 | 36 | 37 | 38 | - [ ] [DCO](https://github.com/prometheus-community/helm-charts/blob/main/CONTRIBUTING.md#sign-off-your-work) signed 39 | - [ ] The PR title has a summary of the changes and the area they affect 40 | - [ ] The PR body has a summary to reflect any significant (and particularly user-facing) changes introduced by this PR 41 | -------------------------------------------------------------------------------- /internal/collector/physical_disk/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package physical_disk 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | CurrentDiskQueueLength float64 `perfdata:"Current Disk Queue Length"` 24 | DiskReadBytesPerSec float64 `perfdata:"Disk Read Bytes/sec"` 25 | DiskReadsPerSec float64 `perfdata:"Disk Reads/sec"` 26 | DiskWriteBytesPerSec float64 `perfdata:"Disk Write Bytes/sec"` 27 | DiskWritesPerSec float64 `perfdata:"Disk Writes/sec"` 28 | PercentDiskReadTime float64 `perfdata:"% Disk Read Time"` 29 | PercentDiskWriteTime float64 `perfdata:"% Disk Write Time"` 30 | PercentIdleTime float64 `perfdata:"% Idle Time"` 31 | SplitIOPerSec float64 `perfdata:"Split IO/Sec"` 32 | AvgDiskSecPerRead float64 `perfdata:"Avg. Disk sec/Read"` 33 | AvgDiskSecPerWrite float64 `perfdata:"Avg. Disk sec/Write"` 34 | AvgDiskSecPerTransfer float64 `perfdata:"Avg. Disk sec/Transfer"` 35 | } 36 | -------------------------------------------------------------------------------- /internal/utils/utils.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package utils 19 | 20 | func MilliSecToSec(t float64) float64 { 21 | return t / 1000 22 | } 23 | 24 | func MBToBytes(mb float64) float64 { 25 | return mb * 1024 * 1024 26 | } 27 | 28 | func BoolToFloat(b bool) float64 { 29 | if b { 30 | return 1.0 31 | } 32 | 33 | return 0.0 34 | } 35 | 36 | func ToPTR[t any](v t) *t { 37 | return &v 38 | } 39 | 40 | func PercentageToRatio(percentage float64) float64 { 41 | return percentage / 100 42 | } 43 | 44 | // Must panics if the error is not nil. 45 | // 46 | //nolint:ireturn 47 | func Must[T any](v T, err error) T { 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | return v 53 | } 54 | 55 | // SplitError returns a slice of errors from the given error. It reverses the [errors.Join] function. 56 | func SplitError(err error) []error { 57 | if errs, ok := err.(interface{ Unwrap() []error }); ok { 58 | return errs.Unwrap() 59 | } 60 | 61 | return []error{err} 62 | } 63 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yaml: -------------------------------------------------------------------------------- 1 | name: ❓ Question 2 | description: Something is not clear. 3 | labels: [ ❓ question ] 4 | body: 5 | 6 | - type: markdown 7 | attributes: 8 | value: |- 9 | > [!NOTE] 10 | > If you encounter "Counter not found" issues, try to re-build the performance counter first. 11 | 12 | ``` 13 | PS C:\WINDOWS\system32> cd c:\windows\system32 14 | PS C:\windows\system32> lodctr /R 15 | 16 | Error: Unable to rebuild performance counter setting from system backup store, error code is 2 17 | PS C:\windows\system32> cd .. 18 | PS C:\windows> cd syswow64 19 | PS C:\windows\syswow64> lodctr /R 20 | 21 | Info: Successfully rebuilt performance counter setting from system backup store 22 | PS C:\windows\syswow64> winmgmt.exe /RESYNCPERF 23 | ``` 24 | 25 | ---- 26 | 27 | - type: textarea 28 | attributes: 29 | label: Problem Statement 30 | description: Without specifying a solution, describe what the project is missing today. 31 | placeholder: | 32 | The rotating project logo has a fixed size and color. 33 | There is no way to make it larger and more shiny. 34 | validations: 35 | required: false 36 | 37 | - type: textarea 38 | attributes: 39 | label: Environment 40 | description: | 41 | examples: 42 | - **windows_exporter Version**: 0.26 43 | - **Windows Server Version**: 2019 44 | value: | 45 | - windows_exporter Version: 46 | - Windows Server Version: 47 | validations: 48 | required: true 49 | 50 | -------------------------------------------------------------------------------- /internal/config/flatten_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package config 19 | 20 | import ( 21 | "reflect" 22 | "testing" 23 | 24 | "go.yaml.in/yaml/v3" 25 | ) 26 | 27 | // Unmarshal good configuration file and confirm data is flattened correctly. 28 | func TestConfigFlattening(t *testing.T) { 29 | t.Parallel() 30 | 31 | goodYamlConfig := []byte(`--- 32 | 33 | collectors: 34 | enabled: cpu,net,service 35 | 36 | log: 37 | level: debug`) 38 | 39 | var data map[string]any 40 | 41 | err := yaml.Unmarshal(goodYamlConfig, &data) 42 | if err != nil { 43 | t.Error(err) 44 | } 45 | 46 | expectedResult := map[string]string{ 47 | "collectors.enabled": "cpu,net,service", 48 | "log.level": "debug", 49 | } 50 | flattenedValues := flatten(data) 51 | 52 | if !reflect.DeepEqual(expectedResult, flattenedValues) { 53 | t.Errorf("Flattened values do not match!\nExpected result: %s\nActual result: %s", expectedResult, flattenedValues) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /internal/headers/propsys/propsys.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package propsys 19 | 20 | import ( 21 | "fmt" 22 | "unsafe" 23 | 24 | "github.com/go-ole/go-ole" 25 | "golang.org/x/sys/windows" 26 | ) 27 | 28 | //nolint:gochecknoglobals 29 | var ( 30 | modPropsys = windows.NewLazySystemDLL("propsys.dll") 31 | procPSGetPropertyKeyFromName = modPropsys.NewProc("PSGetPropertyKeyFromName") 32 | ) 33 | 34 | type PROPERTYKEY struct { 35 | Fmtid ole.GUID 36 | Pid uint32 37 | } 38 | 39 | func PSGetPropertyKeyFromName(name string, key *PROPERTYKEY) error { 40 | namePtr, err := windows.UTF16PtrFromString(name) 41 | if err != nil { 42 | return fmt.Errorf("failed to convert name to UTF16: %w", err) 43 | } 44 | 45 | hr, _, err := procPSGetPropertyKeyFromName.Call( 46 | uintptr(unsafe.Pointer(namePtr)), 47 | uintptr(unsafe.Pointer(key)), 48 | ) 49 | 50 | if hr != 0 { 51 | return fmt.Errorf("PSGetPropertyKeyFromName failed: %w", err) 52 | } 53 | 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /internal/collector/logical_disk/logical_disk_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package logical_disk_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/alecthomas/kingpin/v2" 24 | "github.com/prometheus-community/windows_exporter/internal/collector/logical_disk" 25 | "github.com/prometheus-community/windows_exporter/internal/types" 26 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 27 | ) 28 | 29 | func BenchmarkCollector(b *testing.B) { 30 | // Whitelist is not set in testing context (kingpin flags not parsed), causing the Collector to skip all disks. 31 | localVolumeInclude := ".+" 32 | 33 | testutils.FuncBenchmarkCollector(b, "logical_disk", logical_disk.NewWithFlags, func(app *kingpin.Application) { 34 | app.GetFlag("collector.logical_disk.volume-include").StringVar(&localVolumeInclude) 35 | }) 36 | } 37 | 38 | func TestCollector(t *testing.T) { 39 | testutils.TestCollector(t, logical_disk.New, &logical_disk.Config{ 40 | VolumeInclude: types.RegExpAny, 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /internal/headers/hcn/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package hcn 19 | 20 | import ( 21 | "golang.org/x/sys/windows" 22 | ) 23 | 24 | type Endpoint = windows.Handle 25 | 26 | // EndpointProperties contains the properties of an HCN endpoint. 27 | // 28 | // https://learn.microsoft.com/en-us/virtualization/api/hcn/hns_schema#HostComputeEndpoint 29 | type EndpointProperties struct { 30 | ID string `json:"ID"` 31 | State int `json:"State"` 32 | SharedContainers []string `json:"SharedContainers"` 33 | } 34 | 35 | type EndpointStats struct { 36 | BytesReceived uint64 `json:"BytesReceived"` 37 | BytesSent uint64 `json:"BytesSent"` 38 | DroppedPacketsIncoming uint64 `json:"DroppedPacketsIncoming"` 39 | DroppedPacketsOutgoing uint64 `json:"DroppedPacketsOutgoing"` 40 | EndpointID string `json:"EndpointId"` 41 | InstanceID string `json:"InstanceId"` 42 | PacketsReceived uint64 `json:"PacketsReceived"` 43 | PacketsSent uint64 `json:"PacketsSent"` 44 | } 45 | -------------------------------------------------------------------------------- /internal/headers/hcs/hcs_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package hcs_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/headers/hcs" 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestGetContainers(t *testing.T) { 28 | t.Parallel() 29 | 30 | containers, err := hcs.GetContainers() 31 | require.NoError(t, err) 32 | require.NotNil(t, containers) 33 | } 34 | 35 | func TestOpenContainer(t *testing.T) { 36 | t.Parallel() 37 | 38 | containers, err := hcs.GetContainers() 39 | require.NoError(t, err) 40 | 41 | if len(containers) == 0 { 42 | t.Skip("No containers found") 43 | } 44 | 45 | statistics, err := hcs.GetContainerStatistics(containers[0].ID) 46 | require.NoError(t, err) 47 | require.NotNil(t, statistics) 48 | } 49 | 50 | func TestOpenContainerNotFound(t *testing.T) { 51 | t.Parallel() 52 | 53 | _, err := hcs.GetContainerStatistics("f3056b79b36ddfe203376473e2aeb4922a8ca7c5d8100764e5829eb5552fe09b") 54 | require.ErrorIs(t, err, hcs.ErrIDNotFound) 55 | } 56 | -------------------------------------------------------------------------------- /internal/collector/udp/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package udp 19 | 20 | // The TCPv6 performance object uses the same fields. 21 | // https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.tcpstate?view=net-8.0. 22 | type perfDataCounterValues struct { 23 | DatagramsNoPortPerSec float64 `perfdata:"Datagrams No Port/sec"` 24 | DatagramsReceivedPerSec float64 `perfdata:"Datagrams Received/sec"` 25 | DatagramsReceivedErrors float64 `perfdata:"Datagrams Received Errors"` 26 | DatagramsSentPerSec float64 `perfdata:"Datagrams Sent/sec"` 27 | } 28 | 29 | // Datagrams No Port/sec is the rate of received UDP datagrams for which there was no application at the destination port. 30 | // Datagrams Received Errors is the number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port. 31 | // Datagrams Received/sec is the rate at which UDP datagrams are delivered to UDP users. 32 | // Datagrams Sent/sec is the rate at which UDP datagrams are sent from the entity. 33 | -------------------------------------------------------------------------------- /internal/collector/tcp/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package tcp 19 | 20 | // Win32_PerfRawData_Tcpip_TCPv4 docs 21 | // - https://msdn.microsoft.com/en-us/library/aa394341(v=vs.85).aspx 22 | // The TCPv6 performance object uses the same fields. 23 | // https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.tcpstate?view=net-8.0. 24 | type perfDataCounterValues struct { 25 | ConnectionFailures float64 `perfdata:"Connection Failures"` 26 | ConnectionsActive float64 `perfdata:"Connections Active"` 27 | ConnectionsEstablished float64 `perfdata:"Connections Established"` 28 | ConnectionsPassive float64 `perfdata:"Connections Passive"` 29 | ConnectionsReset float64 `perfdata:"Connections Reset"` 30 | SegmentsPerSec float64 `perfdata:"Segments/sec"` 31 | SegmentsReceivedPerSec float64 `perfdata:"Segments Received/sec"` 32 | SegmentsRetransmittedPerSec float64 `perfdata:"Segments Retransmitted/sec"` 33 | SegmentsSentPerSec float64 `perfdata:"Segments Sent/sec"` 34 | } 35 | -------------------------------------------------------------------------------- /internal/utils/counter_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package utils_test 19 | 20 | import ( 21 | "math" 22 | "testing" 23 | 24 | "github.com/prometheus-community/windows_exporter/internal/utils" 25 | "github.com/stretchr/testify/require" 26 | ) 27 | 28 | func TestCounter(t *testing.T) { 29 | t.Parallel() 30 | 31 | c := utils.NewCounter(0) 32 | require.Equal(t, 0.0, c.Value()) //nolint:testifylint 33 | 34 | c.AddValue(10) 35 | 36 | require.Equal(t, 10.0, c.Value()) //nolint:testifylint 37 | 38 | c.AddValue(50) 39 | 40 | require.Equal(t, 50.0, c.Value()) //nolint:testifylint 41 | 42 | c.AddValue(math.MaxUint32 - 10) 43 | 44 | require.Equal(t, float64(math.MaxUint32)-10, c.Value()) //nolint:testifylint 45 | 46 | c.AddValue(20) 47 | 48 | require.Equal(t, float64(math.MaxUint32)+21, c.Value()) //nolint:testifylint 49 | 50 | c.AddValue(40) 51 | 52 | require.Equal(t, float64(math.MaxUint32)+41, c.Value()) //nolint:testifylint 53 | 54 | c.AddValue(math.MaxUint32 - 10) 55 | 56 | require.Equal(t, float64(math.MaxUint32)*2-9, c.Value()) //nolint:testifylint 57 | } 58 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.yaml: -------------------------------------------------------------------------------- 1 | name: ✨ Enhancement / Feature / Task 2 | description: Some feature is missing or incomplete. 3 | labels: [ ✨ enhancement ] 4 | body: 5 | - type: textarea 6 | attributes: 7 | label: Problem Statement 8 | description: Without specifying a solution, describe what the project is missing today. 9 | placeholder: | 10 | The rotating project logo has a fixed size and color. 11 | There is no way to make it larger and more shiny. 12 | validations: 13 | required: false 14 | - type: textarea 15 | attributes: 16 | label: Proposed Solution 17 | description: Describe the proposed solution to the problem above. 18 | placeholder: | 19 | - Implement 2 new flags CLI: ```--logo-color=FFD700``` and ```--logo-size=100``` 20 | - Let these flags control the size of the rotating project logo. 21 | validations: 22 | required: false 23 | - type: textarea 24 | attributes: 25 | label: Additional information 26 | placeholder: | 27 | We considered adjusting the logo size to the phase of the moon, but there was no 28 | reliable data source in air-gapped environments. 29 | validations: 30 | required: false 31 | - type: textarea 32 | attributes: 33 | label: Acceptance Criteria 34 | placeholder: | 35 | - [ ] As a user, I can control the size of the rotating logo using a CLI flag. 36 | - [ ] As a user, I can control the color of the rotating logo using a CLI flag. 37 | - [ ] Defaults are reasonably set. 38 | - [ ] New settings are appropriately documented. 39 | - [ ] No breaking change for current users of the rotating logo feature. 40 | validations: 41 | required: false 42 | -------------------------------------------------------------------------------- /internal/headers/iphlpapi/iphlpapi_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package iphlpapi_test 19 | 20 | import ( 21 | "net" 22 | "os" 23 | "testing" 24 | 25 | "github.com/prometheus-community/windows_exporter/internal/headers/iphlpapi" 26 | "github.com/stretchr/testify/require" 27 | "golang.org/x/sys/windows" 28 | ) 29 | 30 | func TestGetTCPConnectionStates(t *testing.T) { 31 | t.Parallel() 32 | 33 | pid, err := iphlpapi.GetTCPConnectionStates(windows.AF_INET) 34 | require.NoError(t, err) 35 | require.NotEmpty(t, pid) 36 | } 37 | 38 | func TestGetOwnerPIDOfTCPPort(t *testing.T) { 39 | t.Parallel() 40 | 41 | var listenConf net.ListenConfig 42 | 43 | lister, err := listenConf.Listen(t.Context(), "tcp", "127.0.0.1:0") 44 | require.NoError(t, err) 45 | 46 | t.Cleanup(func() { 47 | require.NoError(t, lister.Close()) 48 | }) 49 | 50 | tcpAddr, ok := lister.Addr().(*net.TCPAddr) 51 | require.True(t, ok) 52 | 53 | pid, err := iphlpapi.GetOwnerPIDOfTCPPort(windows.AF_INET, uint16(tcpAddr.Port)) 54 | require.NoError(t, err) 55 | require.EqualValues(t, os.Getpid(), pid) 56 | } 57 | -------------------------------------------------------------------------------- /internal/headers/shell32/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package shell32 19 | 20 | type IShellItem2 struct { 21 | lpVtbl *IShellItem2Vtbl 22 | } 23 | 24 | type IShellItem2Vtbl struct { 25 | // IUnknown 26 | QueryInterface uintptr 27 | AddRef uintptr 28 | Release uintptr 29 | 30 | // IShellItem 31 | BindToHandler uintptr 32 | GetParent uintptr 33 | GetDisplayName uintptr 34 | GetAttributes uintptr 35 | Compare uintptr 36 | 37 | // IShellItem2 38 | GetPropertyStore uintptr 39 | GetPropertyStoreWithCreateObject uintptr 40 | GetPropertyStoreForKeys uintptr 41 | GetPropertyDescriptionList uintptr 42 | Update uintptr 43 | GetProperty uintptr 44 | GetCLSID uintptr 45 | GetFileTime uintptr 46 | GetInt32 uintptr 47 | GetString uintptr 48 | GetUInt32 uintptr 49 | GetUInt64 uintptr 50 | GetBool uintptr 51 | } 52 | -------------------------------------------------------------------------------- /internal/log/flag/flag.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package flag 19 | 20 | import ( 21 | "github.com/alecthomas/kingpin/v2" 22 | "github.com/prometheus-community/windows_exporter/internal/log" 23 | "github.com/prometheus/common/promslog" 24 | "github.com/prometheus/common/promslog/flag" 25 | ) 26 | 27 | // FileFlagName is the canonical flag name to configure the log file. 28 | const FileFlagName = "log.file" 29 | 30 | // FileFlagHelp is the help description for the log.file flag. 31 | const FileFlagHelp = "Output file of log messages. One of [stdout, stderr, eventlog, ]" 32 | 33 | // AddFlags adds the flags used by this package to the Kingpin application. 34 | // To use the default Kingpin application, call AddFlags(kingpin.CommandLine). 35 | func AddFlags(a *kingpin.Application, config *log.Config) { 36 | config.Config = new(promslog.Config) 37 | flag.AddFlags(a, config.Config) 38 | 39 | if config.File == nil { 40 | config.File = &log.AllowedFile{} 41 | } 42 | 43 | a.Flag(FileFlagName, FileFlagHelp).Default(config.File.String()).SetValue(config.File) 44 | } 45 | -------------------------------------------------------------------------------- /internal/collector/performancecounter/performancecounter_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package performancecounter_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/alecthomas/kingpin/v2" 24 | "github.com/prometheus-community/windows_exporter/internal/collector/performancecounter" 25 | "github.com/prometheus-community/windows_exporter/internal/utils/testutils" 26 | ) 27 | 28 | func BenchmarkCollector(b *testing.B) { 29 | perfDataObjects := `[{"object":"Processor Information","instances":["*"],"instance_label":"core","counters":[{"name":"% Processor Time","metric":"windows_performancecounter_processor_information_processor_time","labels":{"state":"active"}},{"name":"% Idle Time","metric":"windows_performancecounter_processor_information_processor_time","labels":{"state":"idle"}}]},{"object":"Memory","counters":[{"name":"Cache Faults/sec","type":"counter"}]}]` 30 | 31 | testutils.FuncBenchmarkCollector(b, performancecounter.Name, performancecounter.NewWithFlags, func(app *kingpin.Application) { 32 | app.GetFlag("collector.perfdata.objects").StringVar(&perfDataObjects) 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /docs/collector.pagefile.md: -------------------------------------------------------------------------------- 1 | # pagefile collector 2 | 3 | The pagefile collector exposes metrics about the pagefile usage 4 | 5 | ||| 6 | -|- 7 | Metric name prefix | `pagefile` 8 | Classes | [`Win32_OperatingSystem`](https://msdn.microsoft.com/en-us/library/aa394239) 9 | Enabled by default? | Yes 10 | 11 | ## Flags 12 | 13 | None 14 | 15 | ## Metrics 16 | 17 | | Name | Description | Type | Labels | 18 | |--------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-------|--------| 19 | | `windows_pagefile_free_bytes` | Number of bytes that can be mapped into the operating system paging files without causing any other pages to be swapped out | gauge | `file` | 20 | | `windows_pagefile_limit_bytes` | Number of bytes that can be stored in the operating system paging files. 0 (zero) indicates that there are no paging files | gauge | `file` | 21 | 22 | 23 | ### Example metric 24 | 25 | ``` 26 | # HELP windows_pagefile_free_bytes OperatingSystem.FreeSpaceInPagingFiles 27 | # TYPE windows_pagefile_free_bytes gauge 28 | windows_pagefile_free_bytes{file="C:\\pagefile.sys"} 6.025797632e+09 29 | # HELP windows_pagefile_limit_bytes OperatingSystem.SizeStoredInPagingFiles 30 | # TYPE windows_pagefile_limit_bytes gauge 31 | windows_pagefile_limit_bytes{file="C:\\pagefile.sys"} 6.442450944e+09 32 | ``` 33 | 34 | ## Useful queries 35 | _This collector does not yet have useful queries, we would appreciate your help adding them!_ 36 | 37 | ## Alerting examples 38 | _This collector does not yet have alerting examples, we would appreciate your help adding them!_ 39 | -------------------------------------------------------------------------------- /internal/headers/slc/slc.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package slc 19 | 20 | import ( 21 | "errors" 22 | "unsafe" 23 | 24 | "golang.org/x/sys/windows" 25 | ) 26 | 27 | //nolint:gochecknoglobals 28 | var ( 29 | slc = windows.NewLazySystemDLL("slc.dll") 30 | procSLIsWindowsGenuineLocal = slc.NewProc("SLIsWindowsGenuineLocal") 31 | ) 32 | 33 | // SL_GENUINE_STATE enumeration 34 | // 35 | // https://learn.microsoft.com/en-us/windows/win32/api/slpublic/ne-slpublic-sl_genuine_state 36 | type SL_GENUINE_STATE uint32 37 | 38 | const ( 39 | SL_GEN_STATE_IS_GENUINE SL_GENUINE_STATE = iota 40 | SL_GEN_STATE_INVALID_LICENSE 41 | SL_GEN_STATE_TAMPERED 42 | SL_GEN_STATE_OFFLINE 43 | SL_GEN_STATE_LAST 44 | ) 45 | 46 | // SLIsWindowsGenuineLocal function wrapper. 47 | func SLIsWindowsGenuineLocal() (SL_GENUINE_STATE, error) { 48 | var genuineState SL_GENUINE_STATE 49 | 50 | _, _, err := procSLIsWindowsGenuineLocal.Call( 51 | uintptr(unsafe.Pointer(&genuineState)), 52 | ) 53 | if !errors.Is(err, windows.NTE_OP_OK) { 54 | return 0, err 55 | } 56 | 57 | return genuineState, nil 58 | } 59 | -------------------------------------------------------------------------------- /internal/headers/kernel32/job.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package kernel32 19 | 20 | import ( 21 | "unsafe" 22 | 23 | "golang.org/x/sys/windows" 24 | ) 25 | 26 | const ( 27 | // JobObjectQuery is required to retrieve certain information about a job object, 28 | // such as attributes and accounting information (see QueryInformationJobObject and IsProcessInJob). 29 | // https://learn.microsoft.com/en-us/windows/win32/procthread/job-object-security-and-access-rights 30 | JobObjectQuery = 0x0004 31 | ) 32 | 33 | func OpenJobObject(name string) (windows.Handle, error) { 34 | ptr, _ := windows.UTF16PtrFromString(name) 35 | handle, _, err := procOpenJobObject.Call( 36 | JobObjectQuery, 37 | 0, 38 | uintptr(unsafe.Pointer(ptr)), 39 | ) 40 | 41 | if handle == 0 { 42 | return 0, err 43 | } 44 | 45 | return windows.Handle(handle), nil 46 | } 47 | 48 | func IsProcessInJob(process windows.Handle, job windows.Handle, result *bool) error { 49 | ret, _, err := procIsProcessInJob.Call( 50 | uintptr(process), 51 | uintptr(job), 52 | uintptr(unsafe.Pointer(&result)), 53 | ) 54 | if ret == 0 { 55 | return err 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /internal/pdh/registry/utf16.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package registry 19 | 20 | import ( 21 | "encoding/binary" 22 | "io" 23 | 24 | "golang.org/x/sys/windows" 25 | ) 26 | 27 | // readUTF16StringAtPos Read an unterminated UTF16 string at a given position, specifying its length. 28 | func readUTF16StringAtPos(r io.ReadSeeker, absPos int64, length uint32) (string, error) { 29 | value := make([]uint16, length/2) 30 | 31 | _, err := r.Seek(absPos, io.SeekStart) 32 | if err != nil { 33 | return "", err 34 | } 35 | 36 | err = binary.Read(r, bo, value) 37 | if err != nil { 38 | return "", err 39 | } 40 | 41 | return windows.UTF16ToString(value), nil 42 | } 43 | 44 | // readUTF16String Reads a null-terminated UTF16 string at the current offset. 45 | func readUTF16String(r io.Reader) (string, error) { 46 | var err error 47 | 48 | b := make([]byte, 2) 49 | out := make([]uint16, 0, 100) 50 | 51 | for i := 0; err == nil; i += 2 { 52 | _, err = r.Read(b) 53 | 54 | if b[0] == 0 && b[1] == 0 { 55 | break 56 | } 57 | 58 | out = append(out, bo.Uint16(b)) 59 | } 60 | 61 | if err != nil { 62 | return "", err 63 | } 64 | 65 | return windows.UTF16ToString(out), nil 66 | } 67 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/prometheus-community/windows_exporter 2 | 3 | go 1.25 4 | 5 | require ( 6 | github.com/alecthomas/kingpin/v2 v2.4.0 7 | github.com/bmatcuk/doublestar/v4 v4.9.1 8 | github.com/dimchansky/utfbom v1.1.1 9 | github.com/go-ole/go-ole v1.3.0 10 | github.com/prometheus/client_golang v1.23.2 11 | github.com/prometheus/client_model v0.6.2 12 | github.com/prometheus/common v0.67.4 13 | github.com/prometheus/exporter-toolkit v0.15.0 14 | github.com/stretchr/testify v1.11.1 15 | go.yaml.in/yaml/v3 v3.0.4 16 | golang.org/x/sys v0.39.0 17 | ) 18 | 19 | require ( 20 | github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect 21 | github.com/beorn7/perks v1.0.1 // indirect 22 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 23 | github.com/coreos/go-systemd/v22 v22.6.0 // indirect 24 | github.com/davecgh/go-spew v1.1.1 // indirect 25 | github.com/golang-jwt/jwt/v5 v5.3.0 // indirect 26 | github.com/google/uuid v1.6.0 // indirect 27 | github.com/jpillora/backoff v1.0.0 // indirect 28 | github.com/mdlayher/socket v0.5.1 // indirect 29 | github.com/mdlayher/vsock v1.2.1 // indirect 30 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 31 | github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect 32 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect 33 | github.com/prometheus/procfs v0.19.2 // indirect 34 | github.com/xhit/go-str2duration/v2 v2.1.0 // indirect 35 | go.yaml.in/yaml/v2 v2.4.3 // indirect 36 | golang.org/x/crypto v0.46.0 // indirect 37 | golang.org/x/net v0.48.0 // indirect 38 | golang.org/x/oauth2 v0.34.0 // indirect 39 | golang.org/x/sync v0.19.0 // indirect 40 | golang.org/x/text v0.32.0 // indirect 41 | golang.org/x/time v0.14.0 // indirect 42 | google.golang.org/protobuf v1.36.11 // indirect 43 | gopkg.in/yaml.v3 v3.0.1 // indirect 44 | ) 45 | -------------------------------------------------------------------------------- /internal/mi/mi_bench_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package mi_test 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/mi" 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func Benchmark_MI_Query_Unmarshal(b *testing.B) { 28 | application, err := mi.ApplicationInitialize() 29 | require.NoError(b, err) 30 | require.NotEmpty(b, application) 31 | 32 | session, err := application.NewSession(nil) 33 | require.NoError(b, err) 34 | require.NotEmpty(b, session) 35 | 36 | b.ResetTimer() 37 | 38 | var processes []win32Process 39 | 40 | query, err := mi.NewQuery("SELECT Name FROM Win32_Process WHERE Handle = 0 OR Handle = 4") 41 | require.NoError(b, err) 42 | 43 | for b.Loop() { 44 | err := session.QueryUnmarshal(&processes, mi.OperationFlagsStandardRTTI, nil, mi.NamespaceRootCIMv2, mi.QueryDialectWQL, query) 45 | require.NoError(b, err) 46 | require.Equal(b, []win32Process{{Name: "System Idle Process"}, {Name: "System"}}, processes) 47 | } 48 | 49 | b.StopTimer() 50 | 51 | err = session.Close() 52 | require.NoError(b, err) 53 | 54 | err = application.Close() 55 | require.NoError(b, err) 56 | 57 | b.ReportAllocs() 58 | } 59 | -------------------------------------------------------------------------------- /internal/collector/gpu/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package gpu 19 | 20 | type gpuEnginePerfDataCounterValues struct { 21 | Name string 22 | 23 | RunningTime float64 `perfdata:"Running Time"` 24 | UtilizationPercentage float64 `perfdata:"Utilization Percentage"` 25 | } 26 | 27 | type gpuAdapterMemoryPerfDataCounterValues struct { 28 | Name string 29 | 30 | DedicatedUsage float64 `perfdata:"Dedicated Usage"` 31 | SharedUsage float64 `perfdata:"Shared Usage"` 32 | TotalCommitted float64 `perfdata:"Total Committed"` 33 | } 34 | 35 | type gpuLocalAdapterMemoryPerfDataCounterValues struct { 36 | Name string 37 | 38 | LocalUsage float64 `perfdata:"Local Usage"` 39 | } 40 | 41 | type gpuNonLocalAdapterMemoryPerfDataCounterValues struct { 42 | Name string 43 | 44 | NonLocalUsage float64 `perfdata:"Non Local Usage"` 45 | } 46 | 47 | type gpuProcessMemoryPerfDataCounterValues struct { 48 | Name string 49 | 50 | DedicatedUsage float64 `perfdata:"Dedicated Usage"` 51 | LocalUsage float64 `perfdata:"Local Usage"` 52 | NonLocalUsage float64 `perfdata:"Non Local Usage"` 53 | SharedUsage float64 `perfdata:"Shared Usage"` 54 | TotalCommitted float64 `perfdata:"Total Committed"` 55 | } 56 | -------------------------------------------------------------------------------- /docs/collector.udp.md: -------------------------------------------------------------------------------- 1 | # udp collector 2 | 3 | The udp collector exposes metrics about the UDP network stack. 4 | 5 | ||| 6 | -|- 7 | Metric name prefix | `udp` 8 | Data source | Perflib 9 | Enabled by default? | No 10 | 11 | ## Flags 12 | 13 | None 14 | 15 | ## Metrics 16 | 17 | | Name | Description | Type | Labels | 18 | |-----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|---------|--------| 19 | | `windows_udp_datagram_datagram_no_port_total` | Number of received UDP datagrams for which there was no application at the destination port | counter | af | 20 | | `windows_udp_datagram_received_errors_total` | Number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port | counter | af | 21 | | `windows_udp_datagram_received_total` | Number of UDP datagrams segments received | counter | af | 22 | | `windows_udp_datagram_sent_total` | Number of UDP datagrams segments sent | counter | af | 23 | 24 | ### Example metric 25 | _This collector does not yet have explained examples, we would appreciate your help adding them!_ 26 | 27 | ## Useful queries 28 | _This collector does not yet have any useful queries added, we would appreciate your help adding them!_ 29 | 30 | ## Alerting examples 31 | _This collector does not yet have alerting examples, we would appreciate your help adding them!_ 32 | -------------------------------------------------------------------------------- /internal/headers/win32/utils.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package win32 17 | 18 | // ParseMultiSz splits a UTF-16 encoded MULTI_SZ buffer (Windows style) into 19 | // individual UTF-16 string slices. 20 | // 21 | // A MULTI_SZ buffer is a sequence of UTF-16 strings separated by single null 22 | // terminators (0x0000) and terminated by an extra null (i.e., two consecutive 23 | // nulls) to mark the end of the list. 24 | // 25 | // Example layout in memory (UTF-16): 26 | // 27 | // "foo\0bar\0baz\0\0" 28 | // 29 | // Given such a []uint16, this function returns a [][]uint16 where each inner 30 | // slice is one null-terminated string segment without the trailing null. 31 | // 32 | // The returned slices reference the original buffer (no copying). 33 | func ParseMultiSz(buf []uint16) [][]uint16 { 34 | var ( 35 | result [][]uint16 36 | start int 37 | ) 38 | 39 | for i := range buf { 40 | if buf[i] == 0 { 41 | // Found a null terminator. 42 | if i == start { 43 | // Two consecutive nulls → end of list. 44 | break 45 | } 46 | 47 | // Append current string slice (excluding null). 48 | result = append(result, buf[start:i]) 49 | // Move start to next character after null. 50 | start = i + 1 51 | } 52 | } 53 | 54 | return result 55 | } 56 | -------------------------------------------------------------------------------- /internal/log/eventlog/eventlog.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | // Package eventlog provides a Logger that writes to Windows Event Log. 19 | package eventlog 20 | 21 | import ( 22 | "io" 23 | "regexp" 24 | "strings" 25 | 26 | "golang.org/x/sys/windows/svc/eventlog" 27 | ) 28 | 29 | // Interface guard. 30 | var _ io.Writer = (*Writer)(nil) 31 | 32 | var reStripTimeAndLevel = regexp.MustCompile(`^time=\S+ level=\S+ `) 33 | 34 | type Writer struct { 35 | handle *eventlog.Log 36 | } 37 | 38 | // NewEventLogWriter returns a new Writer, which writes to Windows EventLog. 39 | func NewEventLogWriter(handle *eventlog.Log) *Writer { 40 | return &Writer{handle: handle} 41 | } 42 | 43 | func (w *Writer) Write(p []byte) (int, error) { 44 | var err error 45 | 46 | msg := strings.TrimSpace(string(p)) 47 | eventLogMsg := reStripTimeAndLevel.ReplaceAllString(msg, "") 48 | 49 | switch { 50 | case strings.Contains(msg, " level=ERROR") || strings.Contains(msg, `"level":"error"`): 51 | err = w.handle.Error(102, eventLogMsg) 52 | case strings.Contains(msg, " level=WARN") || strings.Contains(msg, `"level":"warn"`): 53 | err = w.handle.Warning(101, eventLogMsg) 54 | default: 55 | err = w.handle.Info(100, eventLogMsg) 56 | } 57 | 58 | return len(p), err 59 | } 60 | -------------------------------------------------------------------------------- /internal/collector/logical_disk/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package logical_disk 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | AvgDiskReadQueueLength float64 `perfdata:"Avg. Disk Read Queue Length"` 24 | AvgDiskSecPerRead float64 `perfdata:"Avg. Disk sec/Read"` 25 | AvgDiskSecPerTransfer float64 `perfdata:"Avg. Disk sec/Transfer"` 26 | AvgDiskSecPerWrite float64 `perfdata:"Avg. Disk sec/Write"` 27 | AvgDiskWriteQueueLength float64 `perfdata:"Avg. Disk Write Queue Length"` 28 | CurrentDiskQueueLength float64 `perfdata:"Current Disk Queue Length"` 29 | FreeSpace float64 `perfdata:"Free Megabytes"` 30 | DiskReadBytesPerSec float64 `perfdata:"Disk Read Bytes/sec"` 31 | DiskReadsPerSec float64 `perfdata:"Disk Reads/sec"` 32 | DiskWriteBytesPerSec float64 `perfdata:"Disk Write Bytes/sec"` 33 | DiskWritesPerSec float64 `perfdata:"Disk Writes/sec"` 34 | PercentDiskReadTime float64 `perfdata:"% Disk Read Time"` 35 | PercentDiskWriteTime float64 `perfdata:"% Disk Write Time"` 36 | PercentFreeSpace float64 `perfdata:"% Free Space,secondvalue"` 37 | PercentIdleTime float64 `perfdata:"% Idle Time"` 38 | SplitIOPerSec float64 `perfdata:"Split IO/Sec"` 39 | } 40 | -------------------------------------------------------------------------------- /internal/collector/performancecounter/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package performancecounter 19 | 20 | import ( 21 | "github.com/prometheus-community/windows_exporter/internal/pdh" 22 | "go.yaml.in/yaml/v3" 23 | ) 24 | 25 | type Object struct { 26 | Name string `json:"name" yaml:"name"` 27 | Object string `json:"object" yaml:"object"` 28 | Type pdh.CounterType `json:"type" yaml:"type"` 29 | Instances []string `json:"instances" yaml:"instances"` 30 | Counters []Counter `json:"counters" yaml:"counters"` 31 | InstanceLabel string `json:"instance_label" yaml:"instance_label"` 32 | 33 | collector *pdh.Collector 34 | perfDataObject any 35 | } 36 | 37 | type Counter struct { 38 | Name string `json:"name" yaml:"name"` 39 | Type string `json:"type" yaml:"type"` 40 | Metric string `json:"metric" yaml:"metric"` 41 | Labels map[string]string `json:"labels" yaml:"labels"` 42 | } 43 | 44 | // https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/54691ebe11bb9ec32b4e35cd31fcb94a352de134/receiver/windowsperfcountersreceiver/README.md?plain=1#L150 45 | 46 | func (*Config) UnmarshalYAML(*yaml.Node) error { 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /pkg/collector/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package collector 19 | 20 | import ( 21 | "log/slog" 22 | "time" 23 | 24 | "github.com/alecthomas/kingpin/v2" 25 | "github.com/prometheus-community/windows_exporter/internal/mi" 26 | "github.com/prometheus/client_golang/prometheus" 27 | ) 28 | 29 | const DefaultCollectors = "cpu,memory,logical_disk,physical_disk,net,os,service,system" 30 | 31 | type Collection struct { 32 | collectors Map 33 | miSession *mi.Session 34 | startTime time.Time 35 | concurrencyCh chan struct{} 36 | 37 | scrapeDurationDesc *prometheus.Desc 38 | collectorScrapeDurationDesc *prometheus.Desc 39 | collectorScrapeSuccessDesc *prometheus.Desc 40 | collectorScrapeTimeoutDesc *prometheus.Desc 41 | } 42 | 43 | type ( 44 | BuilderWithFlags[C Collector] func(*kingpin.Application) C 45 | Map map[string]Collector 46 | ) 47 | 48 | // Collector interface that a collector has to implement. 49 | type Collector interface { 50 | // GetName get the name of the collector 51 | GetName() string 52 | // Build build the collector 53 | Build(logger *slog.Logger, miSession *mi.Session) error 54 | // Collect Get new metrics and expose them via prometheus registry. 55 | Collect(ch chan<- prometheus.Metric) (err error) 56 | // Close closes the collector 57 | Close() error 58 | } 59 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | This directory contains documentation of the collectors in the windows_exporter, with information such as what metrics are exported, any flags for additional configuration, and some example usage in alerts and queries. 3 | 4 | # Collectors 5 | - [`ad`](collector.ad.md) 6 | - [`adcs`](collector.adcs.md) 7 | - [`adfs`](collector.adfs.md) 8 | - [`cache`](collector.cache.md) 9 | - [`container`](collector.container.md) 10 | - [`cpu`](collector.cpu.md) 11 | - [`cpu_info`](collector.cpu_info.md) 12 | - [`dfsr`](collector.dfsr.md) 13 | - [`dhcp`](collector.dhcp.md) 14 | - [`diskdrive`](collector.diskdrive.md) 15 | - [`dns`](collector.dns.md) 16 | - [`exchange`](collector.exchange.md) 17 | - [`file`](collector.file.md) 18 | - [`fsrmquota`](collector.fsrmquota.md) 19 | - [`hyperv`](collector.hyperv.md) 20 | - [`iis`](collector.iis.md) 21 | - [`license`](collector.license.md) 22 | - [`logical_disk`](collector.logical_disk.md) 23 | - [`memory`](collector.memory.md) 24 | - [`mscluster`](collector.mscluster.md) 25 | - [`msmq`](collector.msmq.md) 26 | - [`mssql`](collector.mssql.md) 27 | - [`net`](collector.net.md) 28 | - [`netframework`](collector.netframework.md) 29 | - [`nps`](collector.nps.md) 30 | - [`os`](collector.os.md) 31 | - [`pagefile`](collector.pagefile.md) 32 | - [`performancecounter`](collector.performancecounter.md) 33 | - [`physical_disk`](collector.physical_disk.md) 34 | - [`printer`](collector.printer.md) 35 | - [`process`](collector.process.md) 36 | - [`remote_fx`](collector.remote_fx.md) 37 | - [`scheduled_task`](collector.scheduled_task.md) 38 | - [`service`](collector.service.md) 39 | - [`smb`](collector.smb.md) 40 | - [`smbclient`](collector.smbclient.md) 41 | - [`smtp`](collector.smtp.md) 42 | - [`system`](collector.system.md) 43 | - [`tcp`](collector.tcp.md) 44 | - [`terminal_services`](collector.terminal_services.md) 45 | - [`textfile`](collector.textfile.md) 46 | - [`time`](collector.time.md) 47 | - [`udp`](collector.udp.md) 48 | - [`update`](collector.update.md) 49 | - [`vmware`](collector.vmware.md) 50 | -------------------------------------------------------------------------------- /internal/headers/win32/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package win32 19 | 20 | import ( 21 | "strconv" 22 | "unsafe" 23 | 24 | "golang.org/x/sys/windows" 25 | ) 26 | 27 | const MAX_PATH = 260 28 | 29 | type ( 30 | BOOL = int32 // BOOL is a 32-bit signed int in Win32 31 | DATE_TIME = windows.Filetime 32 | DWORD = uint32 33 | LPWSTR struct { 34 | *uint16 35 | } 36 | ULONG uint32 // ULONG is a 32-bit unsigned int in Win32 37 | UINT uint32 // UINT is a 32-bit unsigned int in Win32 38 | ) 39 | 40 | // NewLPWSTR creates a new LPWSTR from a string. 41 | // If the string is empty, it returns nil. 42 | // This function converts the string to a UTF-16 pointer. 43 | func NewLPWSTR(str string) *LPWSTR { 44 | if str == "" { 45 | return nil 46 | } 47 | 48 | // Convert the string to a UTF-16 pointer 49 | ptr, _ := windows.UTF16PtrFromString(str) 50 | 51 | return &LPWSTR{ptr} 52 | } 53 | 54 | // Pointer returns the uintptr representation of the LPWSTR. 55 | // This is useful for passing the pointer to Windows API functions. 56 | func (s *LPWSTR) Pointer() uintptr { 57 | return uintptr(unsafe.Pointer(s.uint16)) 58 | } 59 | 60 | // String converts the LPWSTR back to a string. 61 | func (s *LPWSTR) String() string { 62 | return windows.UTF16PtrToString(s.uint16) 63 | } 64 | 65 | func (u *UINT) String() string { 66 | return strconv.FormatUint(uint64(*u), 10) 67 | } 68 | -------------------------------------------------------------------------------- /kubernetes/windows-exporter-daemonset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: monitoring 5 | labels: 6 | name: monitoring 7 | --- 8 | apiVersion: apps/v1 9 | kind: DaemonSet 10 | metadata: 11 | labels: 12 | app: windows-exporter 13 | name: windows-exporter 14 | namespace: monitoring 15 | spec: 16 | selector: 17 | matchLabels: 18 | app: windows-exporter 19 | template: 20 | metadata: 21 | labels: 22 | app: windows-exporter 23 | spec: 24 | securityContext: 25 | windowsOptions: 26 | hostProcess: true 27 | runAsUserName: "NT AUTHORITY\\system" 28 | hostNetwork: true 29 | initContainers: 30 | - name: configure-firewall 31 | image: mcr.microsoft.com/powershell:lts-nanoserver-1809 32 | command: ["powershell"] 33 | args: ["New-NetFirewallRule", "-DisplayName", "'windows-exporter'", "-Direction", "inbound", "-Profile", "Any", "-Action", "Allow", "-LocalPort", "9182", "-Protocol", "TCP"] 34 | containers: 35 | - args: 36 | - --config.file=%CONTAINER_SANDBOX_MOUNT_POINT%/config.yml 37 | name: windows-exporter 38 | image: ghcr.io/prometheus-community/windows-exporter:latest 39 | imagePullPolicy: Always 40 | ports: 41 | - containerPort: 9182 42 | hostPort: 9182 43 | name: http 44 | volumeMounts: 45 | - name: windows-exporter-config 46 | mountPath: /config.yml 47 | subPath: config.yml 48 | nodeSelector: 49 | kubernetes.io/os: windows 50 | volumes: 51 | - name: windows-exporter-config 52 | configMap: 53 | name: windows-exporter-config 54 | --- 55 | kind: ConfigMap 56 | apiVersion: v1 57 | metadata: 58 | name: windows-exporter-config 59 | namespace: monitoring 60 | labels: 61 | app: windows-exporter 62 | data: 63 | config.yml: | 64 | collectors: 65 | enabled: '[defaults],container' 66 | collector: 67 | service: 68 | include: "containerd|kubelet" 69 | -------------------------------------------------------------------------------- /.run/all.run.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/collector.nps.md: -------------------------------------------------------------------------------- 1 | # nps collector 2 | 3 | The nps collector exposes metrics about the NPS server 4 | 5 | ||| 6 | -|- 7 | Metric name prefix | `nps` 8 | Classes | Win32_PerfRawData_IAS_NPSAuthenticationServer
Win32_PerfRawData_IAS_NPSAccountingServer 9 | Enabled by default? | No 10 | 11 | ## Flags 12 | 13 | None 14 | 15 | ## Metrics 16 | 17 | Name | Description | Type | Labels 18 | -----|-------------|------|------- 19 | `windows_nps_access_accepts` | | counter | None 20 | `windows_nps_access_bad_authenticators` | | counter | None 21 | `windows_nps_access_challenges` | | counter | None 22 | `windows_nps_access_dropped_packets` | | counter | None 23 | `windows_nps_access_invalid_requests` | | counter | None 24 | `windows_nps_access_malformed_packets` | | counter | None 25 | `windows_nps_access_packets_received` | | counter | None 26 | `windows_nps_access_packets_sent` | | counter | None 27 | `windows_nps_access_rejects` | | counter | None 28 | `windows_nps_access_requests` | | counter | None 29 | `windows_nps_access_server_reset_time` | | counter | None 30 | `windows_nps_access_server_up_time` | | counter | None 31 | `windows_nps_access_unknown_type` | | counter | None 32 | `windows_nps_accounting_bad_authenticators` | | counter | None 33 | `windows_nps_accounting_dropped_packets` | | counter | None 34 | `windows_nps_accounting_invalid_requests` | | counter | None 35 | `windows_nps_accounting_malformed_packets` | | counter | None 36 | `windows_nps_accounting_no_record` | | counter | None 37 | `windows_nps_accounting_packets_received` | | counter | None 38 | `windows_nps_accounting_packets_sent` | | counter | None 39 | `windows_nps_accounting_requests` | | counter | None 40 | `windows_nps_accounting_responses` | | counter | None 41 | `windows_nps_accounting_server_reset_time` | | counter | None 42 | `windows_nps_accounting_server_up_time` | | counter | None 43 | `windows_nps_accounting_unknown_type` | | counter | None 44 | 45 | ### Example metric 46 | Show current number of processes 47 | ``` 48 | windows_nps_access_accepts{instance="localhost"} 49 | ``` -------------------------------------------------------------------------------- /internal/collector/terminal_services/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package terminal_services 19 | 20 | type perfDataCounterValuesTerminalServicesSession struct { 21 | Name string 22 | 23 | HandleCount float64 `perfdata:"Handle Count"` 24 | PageFaultsPersec float64 `perfdata:"Page Faults/sec"` 25 | PageFileBytes float64 `perfdata:"Page File Bytes"` 26 | PageFileBytesPeak float64 `perfdata:"Page File Bytes Peak"` 27 | PercentPrivilegedTime float64 `perfdata:"% Privileged Time"` 28 | PercentProcessorTime float64 `perfdata:"% Processor Time"` 29 | PercentUserTime float64 `perfdata:"% User Time"` 30 | PoolNonpagedBytes float64 `perfdata:"Pool Nonpaged Bytes"` 31 | PoolPagedBytes float64 `perfdata:"Pool Paged Bytes"` 32 | PrivateBytes float64 `perfdata:"Private Bytes"` 33 | ThreadCount float64 `perfdata:"Thread Count"` 34 | VirtualBytes float64 `perfdata:"Virtual Bytes"` 35 | VirtualBytesPeak float64 `perfdata:"Virtual Bytes Peak"` 36 | WorkingSet float64 `perfdata:"Working Set"` 37 | WorkingSetPeak float64 `perfdata:"Working Set Peak"` 38 | } 39 | 40 | type perfDataCounterValuesBroker struct { 41 | SuccessfulConnections float64 `perfdata:"Successful Connections"` 42 | PendingConnections float64 `perfdata:"Pending Connections"` 43 | FailedConnections float64 `perfdata:"Failed Connections"` 44 | } 45 | -------------------------------------------------------------------------------- /internal/httphandler/version.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package httphandler 19 | 20 | import ( 21 | "encoding/json" 22 | "fmt" 23 | "net/http" 24 | 25 | "github.com/prometheus/common/version" 26 | ) 27 | 28 | type VersionHandler struct{} 29 | 30 | // Same struct prometheus uses for their /version endpoint. 31 | // Separate copy to avoid pulling all of prometheus as a dependency. 32 | type prometheusVersion struct { 33 | Version string `json:"version"` 34 | Revision string `json:"revision"` 35 | Branch string `json:"branch"` 36 | BuildUser string `json:"buildUser"` 37 | BuildDate string `json:"buildDate"` 38 | GoVersion string `json:"goVersion"` 39 | } 40 | 41 | // Interface guard. 42 | var _ http.Handler = (*VersionHandler)(nil) 43 | 44 | func NewVersionHandler() VersionHandler { 45 | return VersionHandler{} 46 | } 47 | 48 | func (h VersionHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) { 49 | // we can't use "version" directly as it is a package, and not an object that 50 | // can be serialized. 51 | err := json.NewEncoder(w).Encode(prometheusVersion{ 52 | Version: version.Version, 53 | Revision: version.Revision, 54 | Branch: version.Branch, 55 | BuildUser: version.BuildUser, 56 | BuildDate: version.BuildDate, 57 | GoVersion: version.GoVersion, 58 | }) 59 | if err != nil { 60 | http.Error(w, fmt.Sprintf("error encoding JSON: %s", err), http.StatusInternalServerError) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /internal/collector/adcs/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package adcs 19 | 20 | type perfDataCounterValues struct { 21 | Name string 22 | 23 | ChallengeResponseProcessingTime float64 `perfdata:"Challenge Response processing time (ms)"` 24 | ChallengeResponsesPerSecond float64 `perfdata:"Challenge Responses/sec"` 25 | FailedRequestsPerSecond float64 `perfdata:"Failed Requests/sec"` 26 | IssuedRequestsPerSecond float64 `perfdata:"Issued Requests/sec"` 27 | PendingRequestsPerSecond float64 `perfdata:"Pending Requests/sec"` 28 | RequestCryptographicSigningTime float64 `perfdata:"Request cryptographic signing time (ms)"` 29 | RequestPolicyModuleProcessingTime float64 `perfdata:"Request policy module processing time (ms)"` 30 | RequestProcessingTime float64 `perfdata:"Request processing time (ms)"` 31 | RequestsPerSecond float64 `perfdata:"Requests/sec"` 32 | RetrievalProcessingTime float64 `perfdata:"Retrieval processing time (ms)"` 33 | RetrievalsPerSecond float64 `perfdata:"Retrievals/sec"` 34 | SignedCertificateTimestampListProcessingTime float64 `perfdata:"Signed Certificate Timestamp List processing time (ms)"` 35 | SignedCertificateTimestampListsPerSecond float64 `perfdata:"Signed Certificate Timestamp Lists/sec"` 36 | } 37 | -------------------------------------------------------------------------------- /cmd/windows_exporter/winres/winres.json: -------------------------------------------------------------------------------- 1 | { 2 | "RT_GROUP_ICON": { 3 | "APP": { 4 | "0000": [ 5 | "icon.png" 6 | ] 7 | } 8 | }, 9 | "RT_MANIFEST": { 10 | "#1": { 11 | "0409": { 12 | "description": "A Prometheus exporter for Windows machines.", 13 | "minimum-os": "win7", 14 | "execution-level": "as invoker", 15 | "ui-access": false, 16 | "auto-elevate": false, 17 | "dpi-awareness": "system", 18 | "disable-theming": false, 19 | "disable-window-filtering": false, 20 | "high-resolution-scrolling-aware": false, 21 | "ultra-high-resolution-scrolling-aware": false, 22 | "long-path-aware": false, 23 | "printer-driver-isolation": false, 24 | "gdi-scaling": false, 25 | "segment-heap": false, 26 | "use-common-controls-v6": false 27 | } 28 | } 29 | }, 30 | "RT_VERSION": { 31 | "#1": { 32 | "0000": { 33 | "fixed": { 34 | "file_version": "0.0.0.0", 35 | "product_version": "0.0.0.0" 36 | }, 37 | "info": { 38 | "0409": { 39 | "Comments": "", 40 | "CompanyName": "Prometheus Community", 41 | "FileDescription": "A Prometheus exporter for Windows machines.", 42 | "FileVersion": "", 43 | "InternalName": "windows_exporter", 44 | "LegalCopyright": "", 45 | "LegalTrademarks": "", 46 | "OriginalFilename": "", 47 | "PrivateBuild": "", 48 | "ProductName": "windows_exporter", 49 | "ProductVersion": "", 50 | "SpecialBuild": "" 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /internal/headers/psapi/psapi.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package psapi 19 | 20 | import ( 21 | "unsafe" 22 | 23 | "golang.org/x/sys/windows" 24 | ) 25 | 26 | // PerformanceInformation is a wrapper of the PERFORMANCE_INFORMATION struct. 27 | // https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-performance_information 28 | type PerformanceInformation struct { 29 | cb uint32 30 | CommitTotal uint 31 | CommitLimit uint 32 | CommitPeak uint 33 | PhysicalTotal uint 34 | PhysicalAvailable uint 35 | SystemCache uint 36 | KernelTotal uint 37 | KernelPaged uint 38 | KernelNonpaged uint 39 | PageSize uint 40 | HandleCount uint32 41 | ProcessCount uint32 42 | ThreadCount uint32 43 | } 44 | 45 | //nolint:gochecknoglobals 46 | var ( 47 | psapi = windows.NewLazySystemDLL("psapi.dll") 48 | procGetPerformanceInfo = psapi.NewProc("GetPerformanceInfo") 49 | ) 50 | 51 | // GetPerformanceInfo returns the dereferenced version of GetLPPerformanceInfo. 52 | func GetPerformanceInfo() (PerformanceInformation, error) { 53 | var lppi PerformanceInformation 54 | 55 | size := (uint32)(unsafe.Sizeof(lppi)) 56 | lppi.cb = size 57 | r1, _, err := procGetPerformanceInfo.Call(uintptr(unsafe.Pointer(&lppi)), uintptr(size)) 58 | 59 | if ret := *(*bool)(unsafe.Pointer(&r1)); !ret { 60 | return PerformanceInformation{}, err 61 | } 62 | 63 | return lppi, nil 64 | } 65 | -------------------------------------------------------------------------------- /internal/pdh/collector_test.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package pdh_test 19 | 20 | import ( 21 | "log/slog" 22 | "testing" 23 | "time" 24 | 25 | "github.com/prometheus-community/windows_exporter/internal/pdh" 26 | "github.com/stretchr/testify/require" 27 | ) 28 | 29 | type process struct { 30 | Name string 31 | ThreadCount float64 `perfdata:"Thread Count"` 32 | } 33 | 34 | func TestCollector(t *testing.T) { 35 | t.Parallel() 36 | 37 | for _, tc := range []struct { 38 | object string 39 | instances []string 40 | }{ 41 | { 42 | object: "Process", 43 | instances: []string{"*"}, 44 | }, 45 | } { 46 | t.Run(tc.object, func(t *testing.T) { 47 | t.Parallel() 48 | 49 | performanceData, err := pdh.NewCollector[process](slog.New(slog.DiscardHandler), pdh.CounterTypeRaw, tc.object, tc.instances) 50 | require.NoError(t, err) 51 | 52 | time.Sleep(100 * time.Millisecond) 53 | 54 | var data []process 55 | 56 | err = performanceData.Collect(&data) 57 | require.NoError(t, err) 58 | require.NotEmpty(t, data) 59 | 60 | err = performanceData.Collect(&data) 61 | require.NoError(t, err) 62 | require.NotEmpty(t, data) 63 | 64 | for _, instance := range data { 65 | if instance.Name == "Idle" || instance.Name == "Secure System" { 66 | continue 67 | } 68 | 69 | require.NotZerof(t, instance.ThreadCount, "object: %s, instance: %s, counter: %s", tc.object, instance, instance.ThreadCount) 70 | } 71 | }) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /internal/config/flatten.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package config 19 | 20 | import ( 21 | "fmt" 22 | "strings" 23 | ) 24 | 25 | // convertMap converts a map with any comparable key type to a map with string keys. 26 | func convertMap[K comparable, V any](originalMap map[K]V) map[string]V { 27 | convertedMap := make(map[string]V, len(originalMap)) 28 | for key, value := range originalMap { 29 | if keyString, ok := any(key).(string); ok { 30 | convertedMap[keyString] = value 31 | } 32 | } 33 | 34 | return convertedMap 35 | } 36 | 37 | // flatten flattens a nested map, joining keys with dots. 38 | // e.g. {"a": {"b":"c"}} => {"a.b":"c"} 39 | func flatten(data map[string]any) map[string]string { 40 | result := make(map[string]string) 41 | 42 | flattenHelper("", data, result) 43 | 44 | return result 45 | } 46 | 47 | func flattenHelper(prefix string, data map[string]any, result map[string]string) { 48 | for k, v := range data { 49 | fullKey := k 50 | if prefix != "" { 51 | fullKey = prefix + "." + k 52 | } 53 | 54 | switch val := v.(type) { 55 | case map[any]any: 56 | flattenHelper(fullKey, convertMap(val), result) 57 | case map[string]any: 58 | flattenHelper(fullKey, val, result) 59 | case []any: 60 | strSlice := make([]string, len(val)) 61 | for i, elem := range val { 62 | strSlice[i] = fmt.Sprint(elem) 63 | } 64 | 65 | result[fullKey] = strings.Join(strSlice, ",") 66 | default: 67 | result[fullKey] = fmt.Sprint(val) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /internal/osversion/osversion_windows.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package osversion 19 | 20 | import ( 21 | "fmt" 22 | "sync" 23 | 24 | "golang.org/x/sys/windows" 25 | ) 26 | 27 | // OSVersion is a wrapper for Windows version information 28 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx 29 | type OSVersion struct { 30 | Version uint32 31 | MajorVersion uint8 32 | MinorVersion uint8 33 | Build uint16 34 | } 35 | 36 | //nolint:gochecknoglobals 37 | var osv = sync.OnceValue(func() OSVersion { 38 | v := *windows.RtlGetVersion() 39 | 40 | return OSVersion{ 41 | MajorVersion: uint8(v.MajorVersion), 42 | MinorVersion: uint8(v.MinorVersion), 43 | Build: uint16(v.BuildNumber), 44 | // Fill version value so that existing clients don't break 45 | Version: v.BuildNumber<<16 | (v.MinorVersion << 8) | v.MajorVersion, 46 | } 47 | }) 48 | 49 | // Get gets the operating system version on Windows. 50 | // The calling application must be manifested to get the correct version information. 51 | func Get() OSVersion { 52 | return osv() 53 | } 54 | 55 | // Build gets the build-number on Windows 56 | // The calling application must be manifested to get the correct version information. 57 | func Build() uint16 { 58 | return Get().Build 59 | } 60 | 61 | // String returns the OSVersion formatted as a string. It implements the 62 | // [fmt.Stringer] interface. 63 | func (osv OSVersion) String() string { 64 | return fmt.Sprintf("%d.%d.%d", osv.MajorVersion, osv.MinorVersion, osv.Build) 65 | } 66 | -------------------------------------------------------------------------------- /docs/collector.printer.md: -------------------------------------------------------------------------------- 1 | # printer collector 2 | 3 | The printer collector exposes metrics about printers and their jobs. 4 | 5 | | | | 6 | |---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 7 | | Metric name prefix | `printer` | 8 | | Data source | WMI | 9 | | Classes | [Win32_Printer](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer)
[Win32_PrintJob](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printjob) | 10 | | Enabled by default? | false | 11 | 12 | ## Flags 13 | 14 | ### `--collector.printer.include` 15 | 16 | If given, a printer needs to match the include regexp in order for the corresponding printer metrics to be reported 17 | 18 | ### `--collector.printer.exclude` 19 | 20 | If given, a printer needs to *not* match the exclude regexp in order for the corresponding printer metrics to be reported 21 | 22 | ## Metrics 23 | 24 | Name | Description | Type | Labels 25 | -----|-------------|---------|------- 26 | `windows_printer_status` | Status of the printer at the time the performance data is collected | counter | `printer`, `status` 27 | `windows_printer_job_count` | Number of jobs processed by the printer since the last reset | gauge | `printer` 28 | `windows_printer_job_status` | A counter of printer jobs by status | gauge | `printer`, `status` 29 | -------------------------------------------------------------------------------- /docs/collector.os.md: -------------------------------------------------------------------------------- 1 | # os collector 2 | 3 | The os collector exposes metrics about the operating system 4 | 5 | ||| 6 | -|- 7 | Metric name prefix | `os` 8 | Classes | [`Win32_OperatingSystem`](https://msdn.microsoft.com/en-us/library/aa394239) 9 | Enabled by default? | Yes 10 | 11 | ## Flags 12 | 13 | None 14 | 15 | ## Metrics 16 | 17 | | Name | Description | Type | Labels | 18 | |-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|------------------------------------------------------------------------| 19 | | `windows_os_hostname` | Labelled system hostname information as provided by ComputerSystem.DNSHostName and ComputerSystem.Domain | gauge | `domain`, `fqdn`, `hostname` | 20 | | `windows_os_info` | Contains full product name & version in labels. Note that the `major_version` for Windows 11 is "10"; a build number greater than 22000 represents Windows 11. | gauge | `product`, `version`, `major_version`, `minor_version`, `build_number`, `installation_type`| 21 | 22 | ### Example metric 23 | 24 | ``` 25 | # HELP windows_os_hostname Labelled system hostname information as provided by ComputerSystem.DNSHostName and ComputerSystem.Domain 26 | # TYPE windows_os_hostname gauge 27 | windows_os_hostname{domain="",fqdn="PC",hostname="PC"} 1 28 | # HELP windows_os_info Contains full product name & version in labels. Note that the "major_version" for Windows 11 is \\"10\\"; a build number greater than 22000 represents Windows 11. 29 | # TYPE windows_os_info gauge 30 | windows_os_info{build_number="19045",major_version="10",minor_version="0",product="Windows 10 Pro",revision="4842",version="10.0.19045"} 1 31 | ``` 32 | 33 | ## Useful queries 34 | _This collector does not yet have useful queries, we would appreciate your help adding them!_ 35 | 36 | ## Alerting examples 37 | _This collector does not yet have alerting examples, we would appreciate your help adding them!_ 38 | -------------------------------------------------------------------------------- /internal/collector/gpu/utils.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package gpu 19 | 20 | import ( 21 | "fmt" 22 | "strings" 23 | ) 24 | 25 | type Instance struct { 26 | Pid string 27 | Luid string 28 | DeviceID string 29 | Phys string 30 | Eng string 31 | Engtype string 32 | Part string 33 | } 34 | 35 | type PidPhys struct { 36 | Pid string 37 | Luid string 38 | DeviceID string 39 | Phys string 40 | } 41 | 42 | type PidPhysEngEngType struct { 43 | Pid string 44 | Luid string 45 | DeviceID string 46 | Phys string 47 | Eng string 48 | Engtype string 49 | } 50 | 51 | func parseGPUCounterInstanceString(s string) Instance { 52 | // Example: "pid_1234_luid_0x00000000_0x00005678_phys_0_eng_0_engtype_3D" 53 | // Example: "luid_0x00000000_0x00005678_phys_0" 54 | // Example: "luid_0x00000000_0x00005678_phys_0_part_0" 55 | parts := strings.Split(s, "_") 56 | 57 | var instance Instance 58 | 59 | for i, part := range parts { 60 | switch part { 61 | case "pid": 62 | if i+1 < len(parts) { 63 | instance.Pid = parts[i+1] 64 | } 65 | case "luid": 66 | if i+2 < len(parts) { 67 | instance.Luid = fmt.Sprintf("%s_%s", parts[i+1], parts[i+2]) 68 | } 69 | case "phys": 70 | if i+1 < len(parts) { 71 | instance.Phys = parts[i+1] 72 | } 73 | case "eng": 74 | if i+1 < len(parts) { 75 | instance.Eng = parts[i+1] 76 | } 77 | case "engtype": 78 | if i+1 < len(parts) { 79 | instance.Engtype = parts[i+1] 80 | } 81 | case "part": 82 | if i+1 < len(parts) { 83 | instance.Part = parts[i+1] 84 | } 85 | } 86 | } 87 | 88 | return instance 89 | } 90 | -------------------------------------------------------------------------------- /internal/headers/cfgmgr32/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package cfgmgr32 17 | 18 | import ( 19 | "github.com/go-ole/go-ole" 20 | "github.com/prometheus-community/windows_exporter/internal/headers/win32" 21 | ) 22 | 23 | const ( 24 | // Configuration Manager return codes 25 | CR_SUCCESS = 0x00 26 | 27 | // Filter flags 28 | CM_GETIDLIST_FILTER_ENUMERATOR = 0x00000001 29 | CM_GETIDLIST_FILTER_PRESENT = 0x00000100 30 | 31 | DEVPROP_TYPE_UINT32 uint32 = 0x00000007 32 | ) 33 | 34 | // DEVPROPKEY represents a device property key (GUID + pid) 35 | type DEVPROPKEY struct { 36 | FmtID ole.GUID 37 | PID uint32 38 | } 39 | 40 | type Device struct { 41 | InstanceID string 42 | BusNumber win32.UINT 43 | DeviceNumber win32.UINT 44 | FunctionNumber win32.UINT 45 | } 46 | 47 | //nolint:gochecknoglobals 48 | var ( 49 | // https://github.com/Infinidat/infi.devicemanager/blob/8be9ead6b04ff45c63d9e3bc70d82cceafb75c47/src/infi/devicemanager/setupapi/properties.py#L138C1-L143C34 50 | DEVPKEYDeviceBusNumber = &DEVPROPKEY{ 51 | FmtID: ole.GUID{ 52 | Data1: 0xa45c254e, 53 | Data2: 0xdf1c, 54 | Data3: 0x4efd, 55 | Data4: [8]byte{0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0}, 56 | }, 57 | PID: 23, // DEVPROP_TYPE_UINT32 58 | } 59 | 60 | // https://github.com/Infinidat/infi.devicemanager/blob/8be9ead6b04ff45c63d9e3bc70d82cceafb75c47/src/infi/devicemanager/setupapi/properties.py#L187-L192 61 | DEVPKEYDeviceAddress = &DEVPROPKEY{ 62 | FmtID: ole.GUID{ 63 | Data1: 0xa45c254e, 64 | Data2: 0xdf1c, 65 | Data3: 0x4efd, 66 | Data4: [8]byte{0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0}, 67 | }, 68 | PID: 30, // DEVPROP_TYPE_UINT32 69 | } 70 | ) 71 | -------------------------------------------------------------------------------- /internal/collector/net/types.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package net 19 | 20 | import "golang.org/x/sys/windows" 21 | 22 | //nolint:gochecknoglobals 23 | var ( 24 | addressFamily = map[uint16]string{ 25 | windows.AF_INET: "ipv4", 26 | windows.AF_INET6: "ipv6", 27 | } 28 | operStatus = map[uint32]string{ 29 | windows.IfOperStatusUp: "up", 30 | windows.IfOperStatusDown: "down", 31 | windows.IfOperStatusTesting: "testing", 32 | windows.IfOperStatusUnknown: "unknown", 33 | windows.IfOperStatusDormant: "dormant", 34 | windows.IfOperStatusNotPresent: "not present", 35 | windows.IfOperStatusLowerLayerDown: "lower layer down", 36 | } 37 | ) 38 | 39 | type perfDataCounterValues struct { 40 | Name string 41 | 42 | BytesReceivedPerSec float64 `perfdata:"Bytes Received/sec"` 43 | BytesSentPerSec float64 `perfdata:"Bytes Sent/sec"` 44 | BytesTotalPerSec float64 `perfdata:"Bytes Total/sec"` 45 | CurrentBandwidth float64 `perfdata:"Current Bandwidth"` 46 | OutputQueueLength float64 `perfdata:"Output Queue Length"` 47 | PacketsOutboundDiscarded float64 `perfdata:"Packets Outbound Discarded"` 48 | PacketsOutboundErrors float64 `perfdata:"Packets Outbound Errors"` 49 | PacketsPerSec float64 `perfdata:"Packets/sec"` 50 | PacketsReceivedDiscarded float64 `perfdata:"Packets Received Discarded"` 51 | PacketsReceivedErrors float64 `perfdata:"Packets Received Errors"` 52 | PacketsReceivedPerSec float64 `perfdata:"Packets Received/sec"` 53 | PacketsReceivedUnknown float64 `perfdata:"Packets Received Unknown"` 54 | PacketsSentPerSec float64 `perfdata:"Packets Sent/sec"` 55 | } 56 | -------------------------------------------------------------------------------- /.github/workflows/pr-check.yaml: -------------------------------------------------------------------------------- 1 | name: Validate Pull Request 2 | on: 3 | pull_request: 4 | types: 5 | - opened 6 | - reopened 7 | - synchronize 8 | - labeled 9 | - unlabeled 10 | 11 | jobs: 12 | required-labels-missing: 13 | name: required labels missing 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: check 17 | if: >- 18 | !contains(github.event.pull_request.labels.*.name, '💥 breaking-change') 19 | && !contains(github.event.pull_request.labels.*.name, '✨ enhancement') 20 | && !contains(github.event.pull_request.labels.*.name, '🐞 bug') 21 | && !contains(github.event.pull_request.labels.*.name, '📖 docs') 22 | && !contains(github.event.pull_request.labels.*.name, 'chore') 23 | && !contains(github.event.pull_request.labels.*.name, '🛠️ dependencies') 24 | run: >- 25 | echo One of the following labels is missing on this PR: 26 | breaking-change 27 | enhancement 28 | bug 29 | docs 30 | chore 31 | && exit 1 32 | title: 33 | name: check title prefix 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 37 | - name: check 38 | run: | 39 | PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1) 40 | if [[ -d "internal/collector/$PR_TITLE_PREFIX" ]] || [[ -d "internal/$PR_TITLE_PREFIX" ]] || [[ -d "pkg/$PR_TITLE_PREFIX" ]] || [[ -d "$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "docs" ]] || [[ "$PR_TITLE_PREFIX" == "ci" ]] || [[ "$PR_TITLE_PREFIX" == "revert" ]] || [[ "$PR_TITLE_PREFIX" == "fix" ]] || [[ "$PR_TITLE_PREFIX" == "fix(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "feat" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "chore(docs)" ]] || [[ "$PR_TITLE_PREFIX" == "chore(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]] || [[ "$PR_TITLE_PREFIX" == "Release"* ]] || [[ "$PR_TITLE_PREFIX" == "Synchronize common files from prometheus/prometheus" ]] || [[ "$PR_TITLE_PREFIX" == "[0."* ]] || [[ "$PR_TITLE_PREFIX" == "[1."* ]]; then 41 | exit 0 42 | fi 43 | 44 | echo "PR title must start with an name of an collector package" 45 | echo "Example: 'logical_disk: description'" 46 | exit 1 47 | env: 48 | PR_TITLE: ${{ github.event.pull_request.title }} 49 | -------------------------------------------------------------------------------- /pkg/collector/handler.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package collector 19 | 20 | import ( 21 | "fmt" 22 | "log/slog" 23 | "sync" 24 | "time" 25 | 26 | "github.com/prometheus/client_golang/prometheus" 27 | ) 28 | 29 | // Interface guard. 30 | var _ prometheus.Collector = (*Handler)(nil) 31 | 32 | // We are expose metrics directly from the memory region of the Win32 API. 33 | // We should not allow more than one request at a time. 34 | // 35 | //nolint:gochecknoglobals 36 | var concurrencyMu sync.Mutex 37 | 38 | // Handler implements [prometheus.Collector] for a set of Windows Collection. 39 | type Handler struct { 40 | maxScrapeDuration time.Duration 41 | logger *slog.Logger 42 | collection *Collection 43 | } 44 | 45 | // NewHandler returns a new Handler that implements a [prometheus.Collector] for the given metrics Collection. 46 | func (c *Collection) NewHandler(maxScrapeDuration time.Duration, logger *slog.Logger, collectors []string) (*Handler, error) { 47 | collection := c 48 | 49 | if len(collectors) != 0 { 50 | var err error 51 | 52 | collection, err = c.WithCollectors(collectors) 53 | if err != nil { 54 | return nil, fmt.Errorf("failed to create handler with collectors: %w", err) 55 | } 56 | } 57 | 58 | return &Handler{ 59 | maxScrapeDuration: maxScrapeDuration, 60 | collection: collection, 61 | logger: logger, 62 | }, nil 63 | } 64 | 65 | func (p *Handler) Describe(_ chan<- *prometheus.Desc) {} 66 | 67 | // Collect sends the collected metrics from each of the Collection to 68 | // prometheus. 69 | func (p *Handler) Collect(ch chan<- prometheus.Metric) { 70 | concurrencyMu.Lock() 71 | p.collection.collectAll(ch, p.logger, p.maxScrapeDuration) 72 | concurrencyMu.Unlock() 73 | } 74 | -------------------------------------------------------------------------------- /internal/log/logger.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package log 19 | 20 | import ( 21 | "errors" 22 | "fmt" 23 | "io" 24 | "log/slog" 25 | "os" 26 | 27 | "github.com/prometheus-community/windows_exporter/internal/log/eventlog" 28 | "github.com/prometheus/common/promslog" 29 | wineventlog "golang.org/x/sys/windows/svc/eventlog" 30 | ) 31 | 32 | // AllowedFile is a settable identifier for the output file that the logger can have. 33 | type AllowedFile struct { 34 | s string 35 | w io.Writer 36 | } 37 | 38 | func (f *AllowedFile) String() string { 39 | if f == nil { 40 | return "" 41 | } 42 | 43 | return f.s 44 | } 45 | 46 | // Set updates the value of the allowed format. 47 | func (f *AllowedFile) Set(s string) error { 48 | f.s = s 49 | 50 | switch s { 51 | case "stdout": 52 | f.w = os.Stdout 53 | case "stderr": 54 | f.w = os.Stderr 55 | case "eventlog": 56 | eventLog, err := wineventlog.Open("windows_exporter") 57 | if err != nil { 58 | return fmt.Errorf("failed to open event log: %w", err) 59 | } 60 | 61 | f.w = eventlog.NewEventLogWriter(eventLog) 62 | default: 63 | file, err := os.OpenFile(s, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o200) 64 | if err != nil { 65 | return fmt.Errorf("failed to open log file: %w", err) 66 | } 67 | 68 | f.w = file 69 | } 70 | 71 | return nil 72 | } 73 | 74 | // Config is a struct containing configurable settings for the logger. 75 | type Config struct { 76 | *promslog.Config 77 | 78 | File *AllowedFile 79 | } 80 | 81 | func New(config *Config) (*slog.Logger, error) { 82 | if config.File == nil { 83 | return nil, errors.New("log file undefined") 84 | } 85 | 86 | config.Writer = config.File.w 87 | config.Style = promslog.SlogStyle 88 | 89 | return promslog.New(config.Config), nil 90 | } 91 | -------------------------------------------------------------------------------- /internal/collector/mssql/mssql_instance.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package mssql 19 | 20 | import ( 21 | "fmt" 22 | "log/slog" 23 | 24 | "github.com/prometheus-community/windows_exporter/internal/types" 25 | "github.com/prometheus/client_golang/prometheus" 26 | "golang.org/x/sys/windows/registry" 27 | ) 28 | 29 | type collectorInstance struct { 30 | instances *prometheus.Desc 31 | } 32 | 33 | func (c *Collector) buildInstance() error { 34 | c.instances = prometheus.NewDesc( 35 | prometheus.BuildFQName(types.Namespace, Name, "instance_info"), 36 | "A metric with a constant '1' value labeled with mssql instance information", 37 | []string{"edition", "mssql_instance", "patch", "version"}, 38 | nil, 39 | ) 40 | 41 | return nil 42 | } 43 | 44 | func (c *Collector) collectInstance(ch chan<- prometheus.Metric) error { 45 | for _, instance := range c.mssqlInstances { 46 | regKeyName := fmt.Sprintf(`Software\Microsoft\Microsoft SQL Server\%s\Setup`, instance.instanceName) 47 | 48 | regKey, err := registry.OpenKey(registry.LOCAL_MACHINE, regKeyName, registry.QUERY_VALUE) 49 | if err != nil { 50 | c.logger.Debug(fmt.Sprintf("couldn't open registry %s:", regKeyName), 51 | slog.Any("err", err), 52 | ) 53 | 54 | continue 55 | } 56 | 57 | patchVersion, _, err := regKey.GetStringValue("PatchLevel") 58 | _ = regKey.Close() 59 | 60 | if err != nil { 61 | c.logger.Debug("couldn't get version from registry", 62 | slog.Any("err", err), 63 | ) 64 | 65 | continue 66 | } 67 | 68 | ch <- prometheus.MustNewConstMetric( 69 | c.instances, 70 | prometheus.GaugeValue, 71 | 1, 72 | instance.edition, 73 | instance.name, 74 | patchVersion, 75 | instance.majorVersion.String(), 76 | ) 77 | } 78 | 79 | return nil 80 | } 81 | 82 | func (c *Collector) closeInstance() { 83 | } 84 | -------------------------------------------------------------------------------- /internal/collector/exchange/exchange_autodiscover.go: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // 3 | // Copyright The Prometheus Authors 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //go:build windows 17 | 18 | package exchange 19 | 20 | import ( 21 | "fmt" 22 | 23 | "github.com/prometheus-community/windows_exporter/internal/pdh" 24 | "github.com/prometheus-community/windows_exporter/internal/types" 25 | "github.com/prometheus/client_golang/prometheus" 26 | ) 27 | 28 | type collectorAutoDiscover struct { 29 | perfDataCollectorAutoDiscover *pdh.Collector 30 | perfDataObjectAutoDiscover []perfDataCounterValuesAutoDiscover 31 | 32 | autoDiscoverRequestsPerSec *prometheus.Desc 33 | } 34 | 35 | type perfDataCounterValuesAutoDiscover struct { 36 | RequestsPerSec float64 `perfdata:"Requests/sec"` 37 | } 38 | 39 | func (c *Collector) buildAutoDiscover() error { 40 | var err error 41 | 42 | c.perfDataCollectorAutoDiscover, err = pdh.NewCollector[perfDataCounterValuesAutoDiscover](c.logger, pdh.CounterTypeRaw, "MSExchangeAutodiscover", nil) 43 | if err != nil { 44 | return fmt.Errorf("failed to create MSExchange Autodiscover collector: %w", err) 45 | } 46 | 47 | c.autoDiscoverRequestsPerSec = prometheus.NewDesc( 48 | prometheus.BuildFQName(types.Namespace, Name, "autodiscover_requests_total"), 49 | "Number of autodiscover service requests processed each second", 50 | nil, 51 | nil, 52 | ) 53 | 54 | return nil 55 | } 56 | 57 | func (c *Collector) collectAutoDiscover(ch chan<- prometheus.Metric) error { 58 | err := c.perfDataCollectorAutoDiscover.Collect(&c.perfDataObjectAutoDiscover) 59 | if err != nil { 60 | return fmt.Errorf("failed to collect MSExchange Autodiscover metrics: %w", err) 61 | } 62 | 63 | for _, data := range c.perfDataObjectAutoDiscover { 64 | ch <- prometheus.MustNewConstMetric( 65 | c.autoDiscoverRequestsPerSec, 66 | prometheus.CounterValue, 67 | data.RequestsPerSec, 68 | ) 69 | } 70 | 71 | return nil 72 | } 73 | --------------------------------------------------------------------------------