mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-11 07:26:37 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e460bc24c | ||
|
|
b5ceb27836 | ||
|
|
f6965b10f4 | ||
|
|
d7f052fb27 | ||
|
|
ca4ad46e2d | ||
|
|
dd956c986b | ||
|
|
7bb16d2f5b | ||
|
|
e478843faa | ||
|
|
9b02e4a0ea | ||
|
|
27a3553dac | ||
|
|
b2548e02bd | ||
|
|
0ada09ee3c | ||
|
|
3c360c05f3 | ||
|
|
fe8e72e38f | ||
|
|
2d091c7187 | ||
|
|
b4999eda4b | ||
|
|
d1e3a63f93 |
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.go text eol=lf
|
||||||
|
*.sh text eol=lf
|
||||||
|
Makefile text eol=lf
|
||||||
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@@ -100,5 +100,5 @@ jobs:
|
|||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v6
|
||||||
with:
|
with:
|
||||||
version: v1.58
|
version: v1.59
|
||||||
args: "--timeout=5m --out-format github-actions,colored-line-number"
|
args: "--timeout=5m"
|
||||||
12
.github/workflows/pr-check.yaml
vendored
12
.github/workflows/pr-check.yaml
vendored
@@ -33,14 +33,16 @@ jobs:
|
|||||||
name: check title prefix
|
name: check title prefix
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: check
|
- name: check
|
||||||
run: |
|
run: |
|
||||||
PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1)
|
PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1)
|
||||||
if [[ ! -d "pkg/collector/$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "chore(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]]; then
|
if [[ -d "pkg/collector/$PR_TITLE_PREFIX" ]] || [[ -d "$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "chore(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]] || [[ "$PR_TITLE_PREFIX" == "Synchronize common files from prometheus/prometheus" ]]; then
|
||||||
echo "PR title must start with an name of an collector package"
|
exit 0
|
||||||
echo "Example: 'logical_disk: description'"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "PR title must start with an name of an collector package"
|
||||||
|
echo "Example: 'logical_disk: description'"
|
||||||
|
exit 1
|
||||||
env:
|
env:
|
||||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -77,7 +77,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
$Version = git describe --tag
|
$Version = git describe --tags --always
|
||||||
$Version = $Version -replace 'v', ''
|
$Version = $Version -replace 'v', ''
|
||||||
# '+' symbols are invalid characters in image tags
|
# '+' symbols are invalid characters in image tags
|
||||||
$Version = $Version -replace '\+', '_'
|
$Version = $Version -replace '\+', '_'
|
||||||
|
|||||||
@@ -1,100 +1,52 @@
|
|||||||
linters:
|
linters:
|
||||||
enable-all: true
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
- asasalint
|
|
||||||
- asciicheck
|
|
||||||
- bidichk
|
|
||||||
- bodyclose
|
|
||||||
- canonicalheader
|
|
||||||
- containedctx
|
- containedctx
|
||||||
- contextcheck
|
- contextcheck
|
||||||
- copyloopvar
|
|
||||||
- cyclop
|
- cyclop
|
||||||
- decorder
|
|
||||||
- depguard
|
- depguard
|
||||||
- dogsled
|
- dogsled
|
||||||
- dupl
|
- dupl
|
||||||
- dupword
|
|
||||||
- durationcheck
|
|
||||||
- err113
|
- err113
|
||||||
- errchkjson
|
|
||||||
- errname
|
|
||||||
- errorlint
|
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exhaustruct
|
- exhaustruct
|
||||||
- exportloopref
|
|
||||||
- fatcontext
|
- fatcontext
|
||||||
- forbidigo
|
|
||||||
- forcetypeassert
|
|
||||||
- funlen
|
- funlen
|
||||||
- gci
|
|
||||||
- ginkgolinter
|
|
||||||
- gocheckcompilerdirectives
|
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
|
||||||
- gochecksumtype
|
|
||||||
- gocognit
|
- gocognit
|
||||||
- goconst
|
- goconst
|
||||||
- gocritic
|
|
||||||
- gocyclo
|
- gocyclo
|
||||||
- godot
|
|
||||||
- godox
|
- godox
|
||||||
- gofumpt
|
|
||||||
- goheader
|
|
||||||
- goimports
|
|
||||||
- gomoddirectives
|
|
||||||
- gomodguard
|
|
||||||
- goprintffuncname
|
|
||||||
- gosec
|
|
||||||
- gosimple
|
|
||||||
- gosmopolitan
|
|
||||||
- grouper
|
|
||||||
- importas
|
|
||||||
- inamedparam
|
- inamedparam
|
||||||
- interfacebloat
|
|
||||||
- intrange
|
|
||||||
- ireturn
|
- ireturn
|
||||||
- lll
|
- lll
|
||||||
- maintidx
|
|
||||||
- makezero
|
|
||||||
- mirror
|
|
||||||
- misspell
|
|
||||||
- mnd
|
- mnd
|
||||||
- musttag
|
|
||||||
- nakedret
|
|
||||||
- nestif
|
|
||||||
- nlreturn
|
- nlreturn
|
||||||
- noctx
|
- noctx
|
||||||
- nolintlint
|
|
||||||
- nonamedreturns
|
|
||||||
- nosprintfhostport
|
|
||||||
- paralleltest
|
|
||||||
- predeclared
|
|
||||||
- protogetter
|
|
||||||
- reassign
|
|
||||||
- rowserrcheck
|
|
||||||
- sloglint
|
|
||||||
- spancheck
|
|
||||||
- sqlclosecheck
|
|
||||||
- staticcheck
|
|
||||||
- stylecheck
|
|
||||||
- tagalign
|
|
||||||
- tagliatelle
|
|
||||||
- tenv
|
|
||||||
- testableexamples
|
|
||||||
- testifylint
|
|
||||||
- testpackage
|
- testpackage
|
||||||
- thelper
|
|
||||||
- tparallel
|
|
||||||
- usestdlibvars
|
|
||||||
- varnamelen
|
- varnamelen
|
||||||
- wastedassign
|
|
||||||
- whitespace
|
|
||||||
- wrapcheck
|
- wrapcheck
|
||||||
- wsl
|
- wsl
|
||||||
- zerologlint
|
|
||||||
- execinquery
|
- execinquery
|
||||||
- gomnd
|
- gomnd
|
||||||
|
- stylecheck
|
||||||
|
- maintidx
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gci:
|
||||||
|
sections:
|
||||||
|
- prefix(github.com/prometheus-community/windows_exporter/pkg/initiate)
|
||||||
|
- standard # Standard section: captures all standard packages.
|
||||||
|
- default # Default section: contains all imports that could not be matched to another section type.
|
||||||
|
custom-order: true
|
||||||
|
tagliatelle:
|
||||||
|
case:
|
||||||
|
use-field-name: true
|
||||||
|
rules:
|
||||||
|
# Any struct tag type can be used.
|
||||||
|
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `upperSnake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`
|
||||||
|
json: camel
|
||||||
|
yaml: snake
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude:
|
exclude:
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ Name | Description | Enabled by default
|
|||||||
[time](docs/collector.time.md) | Windows Time Service |
|
[time](docs/collector.time.md) | Windows Time Service |
|
||||||
[thermalzone](docs/collector.thermalzone.md) | Thermal information
|
[thermalzone](docs/collector.thermalzone.md) | Thermal information
|
||||||
[terminal_services](docs/collector.terminal_services.md) | Terminal services (RDS)
|
[terminal_services](docs/collector.terminal_services.md) | Terminal services (RDS)
|
||||||
[textfile](docs/collector.textfile.md) | Read prometheus metrics from a text file | ✓
|
[textfile](docs/collector.textfile.md) | Read prometheus metrics from a text file |
|
||||||
[vmware_blast](docs/collector.vmware_blast.md) | VMware Blast session metrics |
|
[vmware_blast](docs/collector.vmware_blast.md) | VMware Blast session metrics |
|
||||||
[vmware](docs/collector.vmware.md) | Performance counters installed by the Vmware Guest agent |
|
[vmware](docs/collector.vmware.md) | Performance counters installed by the Vmware Guest agent |
|
||||||
|
|
||||||
|
|||||||
7
config.yaml
Normal file
7
config.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
collectors:
|
||||||
|
enabled: cpu,cpu_info,cs,exchange,iis,logical_disk,logon,memory,net,os,process,remote_fx,service,system,tcp,time,terminal_services,textfile
|
||||||
|
collector:
|
||||||
|
service:
|
||||||
|
services-where: "Name='windows_exporter'"
|
||||||
|
log:
|
||||||
|
level: warn
|
||||||
@@ -5,11 +5,11 @@ If the Windows Time Service is stopped after collection has started, collector m
|
|||||||
|
|
||||||
Please note the Time Service perflib counters are only available on [Windows Server 2016 or newer](https://docs.microsoft.com/en-us/windows-server/networking/windows-time-service/windows-server-2016-improvements).
|
Please note the Time Service perflib counters are only available on [Windows Server 2016 or newer](https://docs.microsoft.com/en-us/windows-server/networking/windows-time-service/windows-server-2016-improvements).
|
||||||
|
|
||||||
|||
|
| | |
|
||||||
-|-
|
|---------------------|---------|
|
||||||
Metric name prefix | `time`
|
| Metric name prefix | `time` |
|
||||||
Data source | Perflib
|
| Data source | Perflib |
|
||||||
Enabled by default? | No
|
| Enabled by default? | No |
|
||||||
|
|
||||||
## Flags
|
## Flags
|
||||||
|
|
||||||
@@ -17,14 +17,14 @@ None
|
|||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
|
||||||
Name | Description | Type | Labels
|
| Name | Description | Type | Labels |
|
||||||
-----|-------------|------|-------
|
|-----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
|
||||||
`windows_time_clock_frequency_Adjustment_ppb_total` | Total adjustment made to the local system clock frequency by W32Time in parts per billion (PPB) units. 1 PPB adjustment implies the system clock was adjusted at a rate of 1 nanosecond per second (1 ns/s). The smallest possible adjustment can vary and is expected to be in the order of 100's of PPB. | counter | None
|
| `windows_time_clock_frequency_adjustment_ppb_total` | Total adjustment made to the local system clock frequency by W32Time in parts per billion (PPB) units. 1 PPB adjustment implies the system clock was adjusted at a rate of 1 nanosecond per second (1 ns/s). The smallest possible adjustment can vary and is expected to be in the order of 100's of PPB. | counter | None |
|
||||||
`windows_time_computed_time_offset_seconds` | Absolute time offset between the system clock and the chosen time source, in seconds. | counter | None
|
| `windows_time_computed_time_offset_seconds` | The absolute time offset between the system clock and the chosen time source, as computed by the W32Time service in microseconds. When a new valid sample is available, the computed time is updated with the time offset indicated by the sample. This time is the actual time offset of the local clock. W32Time initiates clock correction by using this offset and updates the computed time in between samples with the remaining time offset that needs to be applied to the local clock. Clock accuracy can be tracked by using this performance counter with a low polling interval (for example, 256 seconds or less) and looking for the counter value to be smaller than the desired clock accuracy limit. | gauge | None |
|
||||||
`windows_time_ntp_client_time_sources` | Active number of NTP Time sources being used by the client. This is a count of active, distinct IP addresses of time servers that are responding to this client's requests. | gauge | None
|
| `windows_time_ntp_client_time_sources` | Active number of NTP Time sources being used by the client. This is a count of active, distinct IP addresses of time servers that are responding to this client's requests. | gauge | None |
|
||||||
`windows_time_ntp_round_trip_delay_seconds` | Total roundtrip delay experienced by the NTP client in receiving a response from the server for the most recent request, in seconds. This is the time elapsed on the NTP client between transmitting a request to the NTP server and receiving a valid response from the server. | gauge | None
|
| `windows_time_ntp_round_trip_delay_seconds` | Total roundtrip delay experienced by the NTP client in receiving a response from the server for the most recent request, in seconds. This is the time elapsed on the NTP client between transmitting a request to the NTP server and receiving a valid response from the server. | gauge | None |
|
||||||
`windows_time_ntp_server_outgoing_responses_total` | Total number of requests responded to by the NTP server. | counter | None
|
| `windows_time_ntp_server_outgoing_responses_total` | Total number of requests responded to by the NTP server. | counter | None |
|
||||||
`windows_time_ntp_server_incoming_requests_total` | Total number of requests received by the NTP server. | counter | None
|
| `windows_time_ntp_server_incoming_requests_total` | Total number of requests received by the NTP server. | counter | None |
|
||||||
|
|
||||||
### Example metric
|
### Example metric
|
||||||
_This collector does not yet have explained examples, we would appreciate your help adding them!_
|
_This collector does not yet have explained examples, we would appreciate your help adding them!_
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
# Note this is not an exhaustive list of all configuration values
|
# Note this is not an exhaustive list of all configuration values
|
||||||
collectors:
|
collectors:
|
||||||
enabled: cpu,cs,logical_disk,net,os,service,system,textfile
|
enabled: cpu,cs,logical_disk,net,os,service,system
|
||||||
collector:
|
collector:
|
||||||
service:
|
service:
|
||||||
services-where: Name='windows_exporter'
|
services-where: Name='windows_exporter'
|
||||||
|
|||||||
71
exporter.go
71
exporter.go
@@ -4,41 +4,42 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//goland:noinspection GoUnsortedImport
|
||||||
|
//nolint:gofumpt
|
||||||
import (
|
import (
|
||||||
// Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts
|
// Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts.
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/initiate"
|
"github.com/prometheus-community/windows_exporter/pkg/initiate"
|
||||||
|
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
"net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"os/user"
|
"os/user"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
winlog "github.com/prometheus-community/windows_exporter/pkg/log"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector"
|
"github.com/prometheus-community/windows_exporter/pkg/collector"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/config"
|
"github.com/prometheus-community/windows_exporter/pkg/config"
|
||||||
|
winlog "github.com/prometheus-community/windows_exporter/pkg/log"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/log/flag"
|
"github.com/prometheus-community/windows_exporter/pkg/log/flag"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/common/version"
|
"github.com/prometheus/common/version"
|
||||||
"github.com/prometheus/exporter-toolkit/web"
|
"github.com/prometheus/exporter-toolkit/web"
|
||||||
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
|
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
|
|
||||||
const PROCESS_ALL_ACCESS = windows.STANDARD_RIGHTS_REQUIRED | windows.SYNCHRONIZE | windows.SPECIFIC_RIGHTS_ALL
|
|
||||||
|
|
||||||
// Same struct prometheus uses for their /version endpoint.
|
// Same struct prometheus uses for their /version endpoint.
|
||||||
// Separate copy to avoid pulling all of prometheus as a dependency
|
// Separate copy to avoid pulling all of prometheus as a dependency.
|
||||||
type prometheusVersion struct {
|
type prometheusVersion struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Revision string `json:"revision"`
|
Revision string `json:"revision"`
|
||||||
@@ -48,7 +49,7 @@ type prometheusVersion struct {
|
|||||||
GoVersion string `json:"goVersion"`
|
GoVersion string `json:"goVersion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapping of priority names to uin32 values required by windows.SetPriorityClass
|
// Mapping of priority names to uin32 values required by windows.SetPriorityClass.
|
||||||
var priorityStringToInt = map[string]uint32{
|
var priorityStringToInt = map[string]uint32{
|
||||||
"realtime": windows.REALTIME_PRIORITY_CLASS,
|
"realtime": windows.REALTIME_PRIORITY_CLASS,
|
||||||
"high": windows.HIGH_PRIORITY_CLASS,
|
"high": windows.HIGH_PRIORITY_CLASS,
|
||||||
@@ -59,18 +60,23 @@ var priorityStringToInt = map[string]uint32{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setPriorityWindows(pid int, priority uint32) error {
|
func setPriorityWindows(pid int, priority uint32) error {
|
||||||
handle, err := windows.OpenProcess(PROCESS_ALL_ACCESS, false, uint32(pid))
|
// https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
|
||||||
|
handle, err := windows.OpenProcess(
|
||||||
|
windows.STANDARD_RIGHTS_REQUIRED|windows.SYNCHRONIZE|windows.SPECIFIC_RIGHTS_ALL,
|
||||||
|
false, uint32(pid),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//nolint:errcheck
|
|
||||||
defer windows.CloseHandle(handle) // Technically this can fail, but we ignore it
|
|
||||||
|
|
||||||
err = windows.SetPriorityClass(handle, priority)
|
if err = windows.SetPriorityClass(handle, priority); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = windows.CloseHandle(handle); err != nil {
|
||||||
|
return fmt.Errorf("failed to close handle: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,9 +177,9 @@ func main() {
|
|||||||
collectorNames := collector.Available()
|
collectorNames := collector.Available()
|
||||||
sort.Strings(collectorNames)
|
sort.Strings(collectorNames)
|
||||||
|
|
||||||
fmt.Printf("Available collectors:\n")
|
fmt.Printf("Available collectors:\n") //nolint:forbidigo
|
||||||
for _, n := range collectorNames {
|
for _, n := range collectorNames {
|
||||||
fmt.Printf(" - %s\n", n)
|
fmt.Printf(" - %s\n", n) //nolint:forbidigo
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -259,20 +265,37 @@ func main() {
|
|||||||
_ = level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
|
_ = level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
|
||||||
_ = level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))
|
_ = level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0))
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
ReadHeaderTimeout: 5 * time.Second,
|
||||||
|
IdleTimeout: 60 * time.Second,
|
||||||
|
ReadTimeout: 5 * time.Second,
|
||||||
|
WriteTimeout: 10 * time.Minute,
|
||||||
|
Handler: mux,
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
server := &http.Server{Handler: mux}
|
|
||||||
if err := web.ListenAndServe(server, webConfig, logger); err != nil {
|
if err := web.ListenAndServe(server, webConfig, logger); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "cannot start windows_exporter", "err", err)
|
_ = level.Error(logger).Log("msg", "cannot start windows_exporter", "err", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
|
||||||
if <-initiate.StopCh {
|
defer stop()
|
||||||
_ = level.Info(logger).Log("msg", "Shutting down windows_exporter")
|
|
||||||
break
|
select {
|
||||||
}
|
case <-ctx.Done():
|
||||||
|
_ = level.Info(logger).Log("msg", "Shutting down windows_exporter via kill signal")
|
||||||
|
case <-initiate.StopCh:
|
||||||
|
_ = level.Info(logger).Log("msg", "Shutting down windows_exporter via service control")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
_ = server.Shutdown(ctx)
|
||||||
|
|
||||||
|
_ = level.Info(logger).Log("msg", "windows_exporter has shut down")
|
||||||
}
|
}
|
||||||
|
|
||||||
func withConcurrencyLimit(n int, next http.HandlerFunc) http.HandlerFunc {
|
func withConcurrencyLimit(n int, next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -17,10 +17,12 @@ require (
|
|||||||
github.com/yusufpapurcu/wmi v1.2.4
|
github.com/yusufpapurcu/wmi v1.2.4
|
||||||
go.opencensus.io v0.24.0 // indirect
|
go.opencensus.io v0.24.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
|
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
|
||||||
golang.org/x/sys v0.22.0
|
golang.org/x/sys v0.24.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require github.com/pkg/errors v0.9.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||||
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
|
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
|
||||||
@@ -36,7 +38,6 @@ require (
|
|||||||
github.com/jpillora/backoff v1.0.0 // indirect
|
github.com/jpillora/backoff v1.0.0 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
|
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
|
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -141,8 +141,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<Property Id="ADD_FIREWALL_EXCEPTION" Secure="yes" />
|
<Property Id="ADD_FIREWALL_EXCEPTION" Secure="yes" />
|
||||||
|
|
||||||
<Property Id="ENABLE_V1_PERFORMANCE_COUNTERS" Secure="yes" Value="yes"/>
|
<Property Id="ENABLE_V1_PERFORMANCE_COUNTERS" Secure="yes" />
|
||||||
|
|
||||||
<Property Id="LISTEN_PORT" Secure="yes" Value="9182" />
|
<Property Id="LISTEN_PORT" Secure="yes" Value="9182" />
|
||||||
<SetProperty Id="ListenFlag" After="InstallFiles" Sequence="execute" Value="--web.listen-address [LISTEN_ADDR]:[LISTEN_PORT]" Condition="LISTEN_ADDR<>"" OR LISTEN_PORT<>9182" />
|
<SetProperty Id="ListenFlag" After="InstallFiles" Sequence="execute" Value="--web.listen-address [LISTEN_ADDR]:[LISTEN_PORT]" Condition="LISTEN_ADDR<>"" OR LISTEN_PORT<>9182" />
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -21,120 +21,133 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
RequestsPerSecond *prometheus.Desc
|
challengeResponseProcessingTime *prometheus.Desc
|
||||||
RequestProcessingTime *prometheus.Desc
|
challengeResponsesPerSecond *prometheus.Desc
|
||||||
RetrievalsPerSecond *prometheus.Desc
|
failedRequestsPerSecond *prometheus.Desc
|
||||||
RetrievalProcessingTime *prometheus.Desc
|
issuedRequestsPerSecond *prometheus.Desc
|
||||||
FailedRequestsPerSecond *prometheus.Desc
|
pendingRequestsPerSecond *prometheus.Desc
|
||||||
IssuedRequestsPerSecond *prometheus.Desc
|
requestCryptographicSigningTime *prometheus.Desc
|
||||||
PendingRequestsPerSecond *prometheus.Desc
|
requestPolicyModuleProcessingTime *prometheus.Desc
|
||||||
RequestCryptographicSigningTime *prometheus.Desc
|
requestProcessingTime *prometheus.Desc
|
||||||
RequestPolicyModuleProcessingTime *prometheus.Desc
|
requestsPerSecond *prometheus.Desc
|
||||||
ChallengeResponsesPerSecond *prometheus.Desc
|
retrievalProcessingTime *prometheus.Desc
|
||||||
ChallengeResponseProcessingTime *prometheus.Desc
|
retrievalsPerSecond *prometheus.Desc
|
||||||
SignedCertificateTimestampListsPerSecond *prometheus.Desc
|
signedCertificateTimestampListProcessingTime *prometheus.Desc
|
||||||
SignedCertificateTimestampListProcessingTime *prometheus.Desc
|
signedCertificateTimestampListsPerSecond *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Certification Authority"}, nil
|
return []string{"Certification Authority"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.RequestsPerSecond = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.requestsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
||||||
"Total certificate requests processed",
|
"Total certificate requests processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RequestProcessingTime = prometheus.NewDesc(
|
c.requestProcessingTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "request_processing_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "request_processing_time_seconds"),
|
||||||
"Last time elapsed for certificate requests",
|
"Last time elapsed for certificate requests",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RetrievalsPerSecond = prometheus.NewDesc(
|
c.retrievalsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "retrievals_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "retrievals_total"),
|
||||||
"Total certificate retrieval requests processed",
|
"Total certificate retrieval requests processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RetrievalProcessingTime = prometheus.NewDesc(
|
c.retrievalProcessingTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "retrievals_processing_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "retrievals_processing_time_seconds"),
|
||||||
"Last time elapsed for certificate retrieval request",
|
"Last time elapsed for certificate retrieval request",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailedRequestsPerSecond = prometheus.NewDesc(
|
c.failedRequestsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failed_requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failed_requests_total"),
|
||||||
"Total failed certificate requests processed",
|
"Total failed certificate requests processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.IssuedRequestsPerSecond = prometheus.NewDesc(
|
c.issuedRequestsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "issued_requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "issued_requests_total"),
|
||||||
"Total issued certificate requests processed",
|
"Total issued certificate requests processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PendingRequestsPerSecond = prometheus.NewDesc(
|
c.pendingRequestsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pending_requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "pending_requests_total"),
|
||||||
"Total pending certificate requests processed",
|
"Total pending certificate requests processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RequestCryptographicSigningTime = prometheus.NewDesc(
|
c.requestCryptographicSigningTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "request_cryptographic_signing_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "request_cryptographic_signing_time_seconds"),
|
||||||
"Last time elapsed for signing operation request",
|
"Last time elapsed for signing operation request",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RequestPolicyModuleProcessingTime = prometheus.NewDesc(
|
c.requestPolicyModuleProcessingTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "request_policy_module_processing_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "request_policy_module_processing_time_seconds"),
|
||||||
"Last time elapsed for policy module processing request",
|
"Last time elapsed for policy module processing request",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ChallengeResponsesPerSecond = prometheus.NewDesc(
|
c.challengeResponsesPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "challenge_responses_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "challenge_responses_total"),
|
||||||
"Total certificate challenge responses processed",
|
"Total certificate challenge responses processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ChallengeResponseProcessingTime = prometheus.NewDesc(
|
c.challengeResponseProcessingTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "challenge_response_processing_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "challenge_response_processing_time_seconds"),
|
||||||
"Last time elapsed for challenge response",
|
"Last time elapsed for challenge response",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SignedCertificateTimestampListsPerSecond = prometheus.NewDesc(
|
c.signedCertificateTimestampListsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_lists_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_lists_total"),
|
||||||
"Total Signed Certificate Timestamp Lists processed",
|
"Total Signed Certificate Timestamp Lists processed",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SignedCertificateTimestampListProcessingTime = prometheus.NewDesc(
|
c.signedCertificateTimestampListProcessingTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_list_processing_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "signed_certificate_timestamp_list_processing_time_seconds"),
|
||||||
"Last time elapsed for Signed Certificate Timestamp List",
|
"Last time elapsed for Signed Certificate Timestamp List",
|
||||||
[]string{"cert_template"},
|
[]string{"cert_template"},
|
||||||
@@ -144,7 +157,7 @@ func (c *collector) Build() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collectADCSCounters(ctx, ch); err != nil {
|
if err := c.collectADCSCounters(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting ADCS metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting ADCS metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -169,7 +182,7 @@ type perflibADCS struct {
|
|||||||
SignedCertificateTimestampListProcessingTime float64 `perflib:"Signed Certificate Timestamp List processing time (ms)"`
|
SignedCertificateTimestampListProcessingTime float64 `perflib:"Signed Certificate Timestamp List processing time (ms)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
dst := make([]perflibADCS, 0)
|
dst := make([]perflibADCS, 0)
|
||||||
if _, ok := ctx.PerfObjects["Certification Authority"]; !ok {
|
if _, ok := ctx.PerfObjects["Certification Authority"]; !ok {
|
||||||
return errors.New("perflib did not contain an entry for Certification Authority")
|
return errors.New("perflib did not contain an entry for Certification Authority")
|
||||||
@@ -188,79 +201,79 @@ func (c *collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestsPerSecond,
|
c.requestsPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.RequestsPerSecond,
|
d.RequestsPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestProcessingTime,
|
c.requestProcessingTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.RequestProcessingTime),
|
utils.MilliSecToSec(d.RequestProcessingTime),
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RetrievalsPerSecond,
|
c.retrievalsPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.RetrievalsPerSecond,
|
d.RetrievalsPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RetrievalProcessingTime,
|
c.retrievalProcessingTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.RetrievalProcessingTime),
|
utils.MilliSecToSec(d.RetrievalProcessingTime),
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailedRequestsPerSecond,
|
c.failedRequestsPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.FailedRequestsPerSecond,
|
d.FailedRequestsPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IssuedRequestsPerSecond,
|
c.issuedRequestsPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.IssuedRequestsPerSecond,
|
d.IssuedRequestsPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PendingRequestsPerSecond,
|
c.pendingRequestsPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.PendingRequestsPerSecond,
|
d.PendingRequestsPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestCryptographicSigningTime,
|
c.requestCryptographicSigningTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.RequestCryptographicSigningTime),
|
utils.MilliSecToSec(d.RequestCryptographicSigningTime),
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestPolicyModuleProcessingTime,
|
c.requestPolicyModuleProcessingTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.RequestPolicyModuleProcessingTime),
|
utils.MilliSecToSec(d.RequestPolicyModuleProcessingTime),
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ChallengeResponsesPerSecond,
|
c.challengeResponsesPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.ChallengeResponsesPerSecond,
|
d.ChallengeResponsesPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ChallengeResponseProcessingTime,
|
c.challengeResponseProcessingTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.ChallengeResponseProcessingTime),
|
utils.MilliSecToSec(d.ChallengeResponseProcessingTime),
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SignedCertificateTimestampListsPerSecond,
|
c.signedCertificateTimestampListsPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.SignedCertificateTimestampListsPerSecond,
|
d.SignedCertificateTimestampListsPerSecond,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SignedCertificateTimestampListProcessingTime,
|
c.signedCertificateTimestampListProcessingTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.SignedCertificateTimestampListProcessingTime),
|
utils.MilliSecToSec(d.SignedCertificateTimestampListProcessingTime),
|
||||||
d.Name,
|
d.Name,
|
||||||
|
|||||||
@@ -18,20 +18,22 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
adLoginConnectionFailures *prometheus.Desc
|
adLoginConnectionFailures *prometheus.Desc
|
||||||
|
artifactDBFailures *prometheus.Desc
|
||||||
|
avgArtifactDBQueryTime *prometheus.Desc
|
||||||
|
avgConfigDBQueryTime *prometheus.Desc
|
||||||
certificateAuthentications *prometheus.Desc
|
certificateAuthentications *prometheus.Desc
|
||||||
|
configDBFailures *prometheus.Desc
|
||||||
deviceAuthentications *prometheus.Desc
|
deviceAuthentications *prometheus.Desc
|
||||||
|
externalAuthenticationFailures *prometheus.Desc
|
||||||
|
externalAuthentications *prometheus.Desc
|
||||||
extranetAccountLockouts *prometheus.Desc
|
extranetAccountLockouts *prometheus.Desc
|
||||||
federatedAuthentications *prometheus.Desc
|
federatedAuthentications *prometheus.Desc
|
||||||
passportAuthentications *prometheus.Desc
|
federationMetadataRequests *prometheus.Desc
|
||||||
passiveRequests *prometheus.Desc
|
|
||||||
passwordChangeFailed *prometheus.Desc
|
|
||||||
passwordChangeSucceeded *prometheus.Desc
|
|
||||||
tokenRequests *prometheus.Desc
|
|
||||||
windowsIntegratedAuthentications *prometheus.Desc
|
|
||||||
oAuthAuthZRequests *prometheus.Desc
|
oAuthAuthZRequests *prometheus.Desc
|
||||||
oAuthClientAuthentications *prometheus.Desc
|
oAuthClientAuthentications *prometheus.Desc
|
||||||
oAuthClientAuthenticationsFailures *prometheus.Desc
|
oAuthClientAuthenticationsFailures *prometheus.Desc
|
||||||
@@ -50,45 +52,56 @@ type collector struct {
|
|||||||
oAuthPasswordGrantRequestFailures *prometheus.Desc
|
oAuthPasswordGrantRequestFailures *prometheus.Desc
|
||||||
oAuthPasswordGrantRequests *prometheus.Desc
|
oAuthPasswordGrantRequests *prometheus.Desc
|
||||||
oAuthTokenRequests *prometheus.Desc
|
oAuthTokenRequests *prometheus.Desc
|
||||||
|
passiveRequests *prometheus.Desc
|
||||||
|
passportAuthentications *prometheus.Desc
|
||||||
|
passwordChangeFailed *prometheus.Desc
|
||||||
|
passwordChangeSucceeded *prometheus.Desc
|
||||||
samlPTokenRequests *prometheus.Desc
|
samlPTokenRequests *prometheus.Desc
|
||||||
ssoAuthenticationFailures *prometheus.Desc
|
ssoAuthenticationFailures *prometheus.Desc
|
||||||
ssoAuthentications *prometheus.Desc
|
ssoAuthentications *prometheus.Desc
|
||||||
wsfedTokenRequests *prometheus.Desc
|
tokenRequests *prometheus.Desc
|
||||||
wstrustTokenRequests *prometheus.Desc
|
|
||||||
upAuthenticationFailures *prometheus.Desc
|
upAuthenticationFailures *prometheus.Desc
|
||||||
upAuthentications *prometheus.Desc
|
upAuthentications *prometheus.Desc
|
||||||
externalAuthenticationFailures *prometheus.Desc
|
windowsIntegratedAuthentications *prometheus.Desc
|
||||||
externalAuthentications *prometheus.Desc
|
wsfedTokenRequests *prometheus.Desc
|
||||||
artifactDBFailures *prometheus.Desc
|
wstrustTokenRequests *prometheus.Desc
|
||||||
avgArtifactDBQueryTime *prometheus.Desc
|
|
||||||
configDBFailures *prometheus.Desc
|
|
||||||
avgConfigDBQueryTime *prometheus.Desc
|
|
||||||
federationMetadataRequests *prometheus.Desc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"AD FS"}, nil
|
return []string{"AD FS"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
c.adLoginConnectionFailures = prometheus.NewDesc(
|
c.adLoginConnectionFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ad_login_connection_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "ad_login_connection_failures_total"),
|
||||||
"Total number of connection failures to an Active Directory domain controller",
|
"Total number of connection failures to an Active Directory domain controller",
|
||||||
@@ -397,7 +410,7 @@ type perflibADFS struct {
|
|||||||
FederationMetadataRequests float64 `perflib:"Federation Metadata Requests"`
|
FederationMetadataRequests float64 `perflib:"Federation Metadata Requests"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var adfsData []perflibADFS
|
var adfsData []perflibADFS
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["AD FS"], &adfsData, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["AD FS"], &adfsData, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
414
pkg/collector/cache/cache.go
vendored
414
pkg/collector/cache/cache.go
vendored
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@@ -17,233 +18,246 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for Perflib Cache metrics
|
// A Collector is a Prometheus Collector for Perflib Cache metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
AsyncCopyReadsTotal *prometheus.Desc
|
asyncCopyReadsTotal *prometheus.Desc
|
||||||
AsyncDataMapsTotal *prometheus.Desc
|
asyncDataMapsTotal *prometheus.Desc
|
||||||
AsyncFastReadsTotal *prometheus.Desc
|
asyncFastReadsTotal *prometheus.Desc
|
||||||
AsyncMDLReadsTotal *prometheus.Desc
|
asyncMDLReadsTotal *prometheus.Desc
|
||||||
AsyncPinReadsTotal *prometheus.Desc
|
asyncPinReadsTotal *prometheus.Desc
|
||||||
CopyReadHitsTotal *prometheus.Desc
|
copyReadHitsTotal *prometheus.Desc
|
||||||
CopyReadsTotal *prometheus.Desc
|
copyReadsTotal *prometheus.Desc
|
||||||
DataFlushesTotal *prometheus.Desc
|
dataFlushesTotal *prometheus.Desc
|
||||||
DataFlushPagesTotal *prometheus.Desc
|
dataFlushPagesTotal *prometheus.Desc
|
||||||
DataMapHitsPercent *prometheus.Desc
|
dataMapHitsPercent *prometheus.Desc
|
||||||
DataMapPinsTotal *prometheus.Desc
|
dataMapPinsTotal *prometheus.Desc
|
||||||
DataMapsTotal *prometheus.Desc
|
dataMapsTotal *prometheus.Desc
|
||||||
DirtyPages *prometheus.Desc
|
dirtyPages *prometheus.Desc
|
||||||
DirtyPageThreshold *prometheus.Desc
|
dirtyPageThreshold *prometheus.Desc
|
||||||
FastReadNotPossiblesTotal *prometheus.Desc
|
fastReadNotPossiblesTotal *prometheus.Desc
|
||||||
FastReadResourceMissesTotal *prometheus.Desc
|
fastReadResourceMissesTotal *prometheus.Desc
|
||||||
FastReadsTotal *prometheus.Desc
|
fastReadsTotal *prometheus.Desc
|
||||||
LazyWriteFlushesTotal *prometheus.Desc
|
lazyWriteFlushesTotal *prometheus.Desc
|
||||||
LazyWritePagesTotal *prometheus.Desc
|
lazyWritePagesTotal *prometheus.Desc
|
||||||
MDLReadHitsTotal *prometheus.Desc
|
mdlReadHitsTotal *prometheus.Desc
|
||||||
MDLReadsTotal *prometheus.Desc
|
mdlReadsTotal *prometheus.Desc
|
||||||
PinReadHitsTotal *prometheus.Desc
|
pinReadHitsTotal *prometheus.Desc
|
||||||
PinReadsTotal *prometheus.Desc
|
pinReadsTotal *prometheus.Desc
|
||||||
ReadAheadsTotal *prometheus.Desc
|
readAheadsTotal *prometheus.Desc
|
||||||
SyncCopyReadsTotal *prometheus.Desc
|
syncCopyReadsTotal *prometheus.Desc
|
||||||
SyncDataMapsTotal *prometheus.Desc
|
syncDataMapsTotal *prometheus.Desc
|
||||||
SyncFastReadsTotal *prometheus.Desc
|
syncFastReadsTotal *prometheus.Desc
|
||||||
SyncMDLReadsTotal *prometheus.Desc
|
syncMDLReadsTotal *prometheus.Desc
|
||||||
SyncPinReadsTotal *prometheus.Desc
|
syncPinReadsTotal *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Cache"}, nil
|
return []string{"Cache"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.AsyncCopyReadsTotal = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.asyncCopyReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "async_copy_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "async_copy_reads_total"),
|
||||||
"(AsyncCopyReadsTotal)",
|
"(AsyncCopyReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AsyncDataMapsTotal = prometheus.NewDesc(
|
c.asyncDataMapsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "async_data_maps_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "async_data_maps_total"),
|
||||||
"(AsyncDataMapsTotal)",
|
"(AsyncDataMapsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AsyncFastReadsTotal = prometheus.NewDesc(
|
c.asyncFastReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "async_fast_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "async_fast_reads_total"),
|
||||||
"(AsyncFastReadsTotal)",
|
"(AsyncFastReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AsyncMDLReadsTotal = prometheus.NewDesc(
|
c.asyncMDLReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "async_mdl_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "async_mdl_reads_total"),
|
||||||
"(AsyncMDLReadsTotal)",
|
"(AsyncMDLReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AsyncPinReadsTotal = prometheus.NewDesc(
|
c.asyncPinReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "async_pin_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "async_pin_reads_total"),
|
||||||
"(AsyncPinReadsTotal)",
|
"(AsyncPinReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CopyReadHitsTotal = prometheus.NewDesc(
|
c.copyReadHitsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "copy_read_hits_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "copy_read_hits_total"),
|
||||||
"(CopyReadHitsTotal)",
|
"(CopyReadHitsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CopyReadsTotal = prometheus.NewDesc(
|
c.copyReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "copy_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "copy_reads_total"),
|
||||||
"(CopyReadsTotal)",
|
"(CopyReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DataFlushesTotal = prometheus.NewDesc(
|
c.dataFlushesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "data_flushes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "data_flushes_total"),
|
||||||
"(DataFlushesTotal)",
|
"(DataFlushesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DataFlushPagesTotal = prometheus.NewDesc(
|
c.dataFlushPagesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "data_flush_pages_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "data_flush_pages_total"),
|
||||||
"(DataFlushPagesTotal)",
|
"(DataFlushPagesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DataMapHitsPercent = prometheus.NewDesc(
|
c.dataMapHitsPercent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "data_map_hits_percent"),
|
prometheus.BuildFQName(types.Namespace, Name, "data_map_hits_percent"),
|
||||||
"(DataMapHitsPercent)",
|
"(DataMapHitsPercent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DataMapPinsTotal = prometheus.NewDesc(
|
c.dataMapPinsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "data_map_pins_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "data_map_pins_total"),
|
||||||
"(DataMapPinsTotal)",
|
"(DataMapPinsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DataMapsTotal = prometheus.NewDesc(
|
c.dataMapsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "data_maps_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "data_maps_total"),
|
||||||
"(DataMapsTotal)",
|
"(DataMapsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DirtyPages = prometheus.NewDesc(
|
c.dirtyPages = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dirty_pages"),
|
prometheus.BuildFQName(types.Namespace, Name, "dirty_pages"),
|
||||||
"(DirtyPages)",
|
"(DirtyPages)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DirtyPageThreshold = prometheus.NewDesc(
|
c.dirtyPageThreshold = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dirty_page_threshold"),
|
prometheus.BuildFQName(types.Namespace, Name, "dirty_page_threshold"),
|
||||||
"(DirtyPageThreshold)",
|
"(DirtyPageThreshold)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FastReadNotPossiblesTotal = prometheus.NewDesc(
|
c.fastReadNotPossiblesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "fast_read_not_possibles_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "fast_read_not_possibles_total"),
|
||||||
"(FastReadNotPossiblesTotal)",
|
"(FastReadNotPossiblesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FastReadResourceMissesTotal = prometheus.NewDesc(
|
c.fastReadResourceMissesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "fast_read_resource_misses_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "fast_read_resource_misses_total"),
|
||||||
"(FastReadResourceMissesTotal)",
|
"(FastReadResourceMissesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FastReadsTotal = prometheus.NewDesc(
|
c.fastReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "fast_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "fast_reads_total"),
|
||||||
"(FastReadsTotal)",
|
"(FastReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.LazyWriteFlushesTotal = prometheus.NewDesc(
|
c.lazyWriteFlushesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "lazy_write_flushes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "lazy_write_flushes_total"),
|
||||||
"(LazyWriteFlushesTotal)",
|
"(LazyWriteFlushesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.LazyWritePagesTotal = prometheus.NewDesc(
|
c.lazyWritePagesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "lazy_write_pages_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "lazy_write_pages_total"),
|
||||||
"(LazyWritePagesTotal)",
|
"(LazyWritePagesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MDLReadHitsTotal = prometheus.NewDesc(
|
c.mdlReadHitsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mdl_read_hits_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "mdl_read_hits_total"),
|
||||||
"(MDLReadHitsTotal)",
|
"(MDLReadHitsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MDLReadsTotal = prometheus.NewDesc(
|
c.mdlReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mdl_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "mdl_reads_total"),
|
||||||
"(MDLReadsTotal)",
|
"(MDLReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PinReadHitsTotal = prometheus.NewDesc(
|
c.pinReadHitsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pin_read_hits_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "pin_read_hits_total"),
|
||||||
"(PinReadHitsTotal)",
|
"(PinReadHitsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PinReadsTotal = prometheus.NewDesc(
|
c.pinReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pin_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "pin_reads_total"),
|
||||||
"(PinReadsTotal)",
|
"(PinReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ReadAheadsTotal = prometheus.NewDesc(
|
c.readAheadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_aheads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_aheads_total"),
|
||||||
"(ReadAheadsTotal)",
|
"(ReadAheadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SyncCopyReadsTotal = prometheus.NewDesc(
|
c.syncCopyReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "sync_copy_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "sync_copy_reads_total"),
|
||||||
"(SyncCopyReadsTotal)",
|
"(SyncCopyReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SyncDataMapsTotal = prometheus.NewDesc(
|
c.syncDataMapsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "sync_data_maps_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "sync_data_maps_total"),
|
||||||
"(SyncDataMapsTotal)",
|
"(SyncDataMapsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SyncFastReadsTotal = prometheus.NewDesc(
|
c.syncFastReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "sync_fast_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "sync_fast_reads_total"),
|
||||||
"(SyncFastReadsTotal)",
|
"(SyncFastReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SyncMDLReadsTotal = prometheus.NewDesc(
|
c.syncMDLReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "sync_mdl_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "sync_mdl_reads_total"),
|
||||||
"(SyncMDLReadsTotal)",
|
"(SyncMDLReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SyncPinReadsTotal = prometheus.NewDesc(
|
c.syncPinReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "sync_pin_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "sync_pin_reads_total"),
|
||||||
"(SyncPinReadsTotal)",
|
"(SyncPinReadsTotal)",
|
||||||
nil,
|
nil,
|
||||||
@@ -252,12 +266,14 @@ func (c *collector) Build() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect implements the Collector interface
|
// Collect implements the Collector interface.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting cache metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting cache metrics", "err", err)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,23 +285,20 @@ type perflibCache struct {
|
|||||||
AsyncFastReadsTotal float64 `perflib:"Async Fast Reads/sec"`
|
AsyncFastReadsTotal float64 `perflib:"Async Fast Reads/sec"`
|
||||||
AsyncMDLReadsTotal float64 `perflib:"Async MDL Reads/sec"`
|
AsyncMDLReadsTotal float64 `perflib:"Async MDL Reads/sec"`
|
||||||
AsyncPinReadsTotal float64 `perflib:"Async Pin Reads/sec"`
|
AsyncPinReadsTotal float64 `perflib:"Async Pin Reads/sec"`
|
||||||
CopyReadHitsTotal float64 `perflib:"Copy Read Hits %"`
|
CopyReadHitsTotal float64 `perflib:"Copy Read Hits/sec"`
|
||||||
CopyReadsTotal float64 `perflib:"Copy Reads/sec"`
|
CopyReadsTotal float64 `perflib:"Copy Reads/sec"`
|
||||||
DataFlushesTotal float64 `perflib:"Data Flushes/sec"`
|
DataFlushesTotal float64 `perflib:"Data Flushes/sec"`
|
||||||
DataFlushPagesTotal float64 `perflib:"Data Flush Pages/sec"`
|
DataFlushPagesTotal float64 `perflib:"Data Flush Pages/sec"`
|
||||||
DataMapHitsPercent float64 `perflib:"Data Map Hits %"`
|
|
||||||
DataMapPinsTotal float64 `perflib:"Data Map Pins/sec"`
|
DataMapPinsTotal float64 `perflib:"Data Map Pins/sec"`
|
||||||
DataMapsTotal float64 `perflib:"Data Maps/sec"`
|
DataMapsTotal float64 `perflib:"Data Maps/sec"`
|
||||||
DirtyPages float64 `perflib:"Dirty Pages"`
|
|
||||||
DirtyPageThreshold float64 `perflib:"Dirty Page Threshold"`
|
|
||||||
FastReadNotPossiblesTotal float64 `perflib:"Fast Read Not Possibles/sec"`
|
FastReadNotPossiblesTotal float64 `perflib:"Fast Read Not Possibles/sec"`
|
||||||
FastReadResourceMissesTotal float64 `perflib:"Fast Read Resource Misses/sec"`
|
FastReadResourceMissesTotal float64 `perflib:"Fast Read Resource Misses/sec"`
|
||||||
FastReadsTotal float64 `perflib:"Fast Reads/sec"`
|
FastReadsTotal float64 `perflib:"Fast Reads/sec"`
|
||||||
LazyWriteFlushesTotal float64 `perflib:"Lazy Write Flushes/sec"`
|
LazyWriteFlushesTotal float64 `perflib:"Lazy Write Flushes/sec"`
|
||||||
LazyWritePagesTotal float64 `perflib:"Lazy Write Pages/sec"`
|
LazyWritePagesTotal float64 `perflib:"Lazy Write Pages/sec"`
|
||||||
MDLReadHitsTotal float64 `perflib:"MDL Read Hits %"`
|
MDLReadHitsTotal float64 `perflib:"MDL Read Hits/sec"`
|
||||||
MDLReadsTotal float64 `perflib:"MDL Reads/sec"`
|
MDLReadsTotal float64 `perflib:"MDL Reads/sec"`
|
||||||
PinReadHitsTotal float64 `perflib:"Pin Read Hits %"`
|
PinReadHitsTotal float64 `perflib:"Pin Read Hits/sec"`
|
||||||
PinReadsTotal float64 `perflib:"Pin Reads/sec"`
|
PinReadsTotal float64 `perflib:"Pin Reads/sec"`
|
||||||
ReadAheadsTotal float64 `perflib:"Read Aheads/sec"`
|
ReadAheadsTotal float64 `perflib:"Read Aheads/sec"`
|
||||||
SyncCopyReadsTotal float64 `perflib:"Sync Copy Reads/sec"`
|
SyncCopyReadsTotal float64 `perflib:"Sync Copy Reads/sec"`
|
||||||
@@ -293,187 +306,166 @@ type perflibCache struct {
|
|||||||
SyncFastReadsTotal float64 `perflib:"Sync Fast Reads/sec"`
|
SyncFastReadsTotal float64 `perflib:"Sync Fast Reads/sec"`
|
||||||
SyncMDLReadsTotal float64 `perflib:"Sync MDL Reads/sec"`
|
SyncMDLReadsTotal float64 `perflib:"Sync MDL Reads/sec"`
|
||||||
SyncPinReadsTotal float64 `perflib:"Sync Pin Reads/sec"`
|
SyncPinReadsTotal float64 `perflib:"Sync Pin Reads/sec"`
|
||||||
|
DirtyPages float64 `perflib:"Dirty Pages"`
|
||||||
|
DirtyPageThreshold float64 `perflib:"Dirty Page Threshold"`
|
||||||
|
DataMapHitsPercent float64 `perflib:"Data Map Hits %"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []perflibCache // Single-instance class, array is required but will have single entry.
|
var dst []perflibCache // Single-instance class, array is required but will have single entry.
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["Cache"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["Cache"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(dst) != 1 {
|
||||||
|
return errors.New("expected single instance of Cache")
|
||||||
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AsyncCopyReadsTotal,
|
c.asyncCopyReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].AsyncCopyReadsTotal,
|
dst[0].AsyncCopyReadsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AsyncDataMapsTotal,
|
c.asyncDataMapsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].AsyncDataMapsTotal,
|
dst[0].AsyncDataMapsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AsyncFastReadsTotal,
|
c.asyncFastReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].AsyncFastReadsTotal,
|
dst[0].AsyncFastReadsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AsyncMDLReadsTotal,
|
c.asyncMDLReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].AsyncMDLReadsTotal,
|
dst[0].AsyncMDLReadsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AsyncPinReadsTotal,
|
c.asyncPinReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].AsyncPinReadsTotal,
|
dst[0].AsyncPinReadsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CopyReadHitsTotal,
|
c.copyReadHitsTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.CounterValue,
|
||||||
dst[0].CopyReadHitsTotal,
|
dst[0].CopyReadHitsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CopyReadsTotal,
|
c.copyReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].CopyReadsTotal,
|
dst[0].CopyReadsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DataFlushesTotal,
|
c.dataFlushesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].DataFlushesTotal,
|
dst[0].DataFlushesTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DataFlushPagesTotal,
|
c.dataFlushPagesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].DataFlushPagesTotal,
|
dst[0].DataFlushPagesTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DataMapHitsPercent,
|
c.dataMapPinsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].DataMapPinsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.dataMapsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].DataMapsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.fastReadNotPossiblesTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].FastReadNotPossiblesTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.fastReadResourceMissesTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].FastReadResourceMissesTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.fastReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].FastReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.lazyWriteFlushesTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].LazyWriteFlushesTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.lazyWritePagesTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].LazyWritePagesTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.mdlReadHitsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].MDLReadHitsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.mdlReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].MDLReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.pinReadHitsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].PinReadHitsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.pinReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].PinReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.readAheadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].ReadAheadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.syncCopyReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].SyncCopyReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.syncDataMapsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].SyncDataMapsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.syncFastReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].SyncFastReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.syncMDLReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].SyncMDLReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.syncPinReadsTotal,
|
||||||
|
prometheus.CounterValue,
|
||||||
|
dst[0].SyncPinReadsTotal,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.dirtyPages,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
dst[0].DirtyPages,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.dirtyPageThreshold,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
dst[0].DirtyPageThreshold,
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.dataMapHitsPercent,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].DataMapHitsPercent,
|
dst[0].DataMapHitsPercent,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.DataMapPinsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].DataMapPinsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.DataMapsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].DataMapsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.DirtyPages,
|
|
||||||
prometheus.GaugeValue,
|
|
||||||
dst[0].DirtyPages,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.DirtyPageThreshold,
|
|
||||||
prometheus.GaugeValue,
|
|
||||||
dst[0].DirtyPageThreshold,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.FastReadNotPossiblesTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].FastReadNotPossiblesTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.FastReadResourceMissesTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].FastReadResourceMissesTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.FastReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].FastReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.LazyWriteFlushesTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].LazyWriteFlushesTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.LazyWritePagesTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].LazyWritePagesTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.MDLReadHitsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].MDLReadHitsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.MDLReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].MDLReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.PinReadHitsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].PinReadHitsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.PinReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].PinReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.ReadAheadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].ReadAheadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.SyncCopyReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].SyncCopyReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.SyncDataMapsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].SyncDataMapsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.SyncFastReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].SyncFastReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.SyncMDLReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].SyncMDLReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.SyncPinReadsTotal,
|
|
||||||
prometheus.CounterValue,
|
|
||||||
dst[0].SyncPinReadsTotal,
|
|
||||||
)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
12
pkg/collector/cache/cache_test.go
vendored
Normal file
12
pkg/collector/cache/cache_test.go
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package cache_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/collector/cache"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/testutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCollector(b *testing.B) {
|
||||||
|
testutils.FuncBenchmarkCollector(b, cache.Name, cache.NewWithFlags)
|
||||||
|
}
|
||||||
@@ -3,12 +3,12 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/ad"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/ad"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/adcs"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/adcs"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/adfs"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/adfs"
|
||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/diskdrive"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/diskdrive"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/dns"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/dns"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/exchange"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/exchange"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/collector/fsrmquota"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/hyperv"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/hyperv"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/iis"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/iis"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/license"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/license"
|
||||||
@@ -68,45 +69,44 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Collectors struct {
|
// NewWithFlags To be called by the exporter for collector initialization before running kingpin.Parse.
|
||||||
logger log.Logger
|
|
||||||
|
|
||||||
collectors map[string]types.Collector
|
|
||||||
perfCounterQuery string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWithFlags To be called by the exporter for collector initialization before running kingpin.Parse
|
|
||||||
func NewWithFlags(app *kingpin.Application) Collectors {
|
func NewWithFlags(app *kingpin.Application) Collectors {
|
||||||
collectors := map[string]types.Collector{}
|
collectors := map[string]Collector{}
|
||||||
|
|
||||||
for name, builder := range Map {
|
for name, builder := range BuildersWithFlags {
|
||||||
collectors[name] = builder(app)
|
collectors[name] = builder(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(collectors)
|
return New(collectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewBuilderWithFlags[C Collector](fn BuilderWithFlags[C]) BuilderWithFlags[Collector] {
|
||||||
|
return func(app *kingpin.Application) Collector {
|
||||||
|
return fn(app)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewWithConfig To be called by the external libraries for collector initialization without running kingpin.Parse
|
// NewWithConfig To be called by the external libraries for collector initialization without running kingpin.Parse
|
||||||
//
|
//
|
||||||
//goland:noinspection GoUnusedExportedFunction
|
//goland:noinspection GoUnusedExportedFunction
|
||||||
func NewWithConfig(logger log.Logger, config Config) Collectors {
|
func NewWithConfig(logger log.Logger, config Config) Collectors {
|
||||||
collectors := map[string]types.Collector{}
|
collectors := map[string]Collector{}
|
||||||
collectors[ad.Name] = ad.New(logger, &config.Ad)
|
collectors[ad.Name] = ad.New(logger, &config.AD)
|
||||||
collectors[adcs.Name] = adcs.New(logger, &config.Adcs)
|
collectors[adcs.Name] = adcs.New(logger, &config.ADCS)
|
||||||
collectors[adfs.Name] = adfs.New(logger, &config.Adfs)
|
collectors[adfs.Name] = adfs.New(logger, &config.ADFS)
|
||||||
collectors[cache.Name] = cache.New(logger, &config.Cache)
|
collectors[cache.Name] = cache.New(logger, &config.Cache)
|
||||||
collectors[container.Name] = container.New(logger, &config.Container)
|
collectors[container.Name] = container.New(logger, &config.Container)
|
||||||
collectors[cpu.Name] = cpu.New(logger, &config.Cpu)
|
collectors[cpu.Name] = cpu.New(logger, &config.CPU)
|
||||||
collectors[cpu_info.Name] = cpu_info.New(logger, &config.CpuInfo)
|
collectors[cpu_info.Name] = cpu_info.New(logger, &config.CPUInfo)
|
||||||
collectors[cs.Name] = cs.New(logger, &config.Cs)
|
collectors[cs.Name] = cs.New(logger, &config.Cs)
|
||||||
collectors[dfsr.Name] = dfsr.New(logger, &config.Dfsr)
|
collectors[dfsr.Name] = dfsr.New(logger, &config.DFSR)
|
||||||
collectors[dhcp.Name] = dhcp.New(logger, &config.Dhcp)
|
collectors[dhcp.Name] = dhcp.New(logger, &config.Dhcp)
|
||||||
collectors[diskdrive.Name] = diskdrive.New(logger, &config.Diskdrive)
|
collectors[diskdrive.Name] = diskdrive.New(logger, &config.DiskDrive)
|
||||||
collectors[dns.Name] = dns.New(logger, &config.Dns)
|
collectors[dns.Name] = dns.New(logger, &config.DNS)
|
||||||
collectors[exchange.Name] = exchange.New(logger, &config.Exchange)
|
collectors[exchange.Name] = exchange.New(logger, &config.Exchange)
|
||||||
collectors[exchange.Name] = exchange.New(logger, &config.Fsrmquota)
|
collectors[fsrmquota.Name] = fsrmquota.New(logger, &config.Fsrmquota)
|
||||||
collectors[hyperv.Name] = hyperv.New(logger, &config.Hyperv)
|
collectors[hyperv.Name] = hyperv.New(logger, &config.Hyperv)
|
||||||
collectors[iis.Name] = iis.New(logger, &config.Iis)
|
collectors[iis.Name] = iis.New(logger, &config.IIS)
|
||||||
collectors[license.Name] = license.New(logger, &config.License)
|
collectors[license.Name] = license.New(logger, &config.License)
|
||||||
collectors[logical_disk.Name] = logical_disk.New(logger, &config.LogicalDisk)
|
collectors[logical_disk.Name] = logical_disk.New(logger, &config.LogicalDisk)
|
||||||
collectors[logon.Name] = logon.New(logger, &config.Logon)
|
collectors[logon.Name] = logon.New(logger, &config.Logon)
|
||||||
@@ -135,12 +135,12 @@ func NewWithConfig(logger log.Logger, config Config) Collectors {
|
|||||||
collectors[remote_fx.Name] = remote_fx.New(logger, &config.RemoteFx)
|
collectors[remote_fx.Name] = remote_fx.New(logger, &config.RemoteFx)
|
||||||
collectors[scheduled_task.Name] = scheduled_task.New(logger, &config.ScheduledTask)
|
collectors[scheduled_task.Name] = scheduled_task.New(logger, &config.ScheduledTask)
|
||||||
collectors[service.Name] = service.New(logger, &config.Service)
|
collectors[service.Name] = service.New(logger, &config.Service)
|
||||||
collectors[smb.Name] = smb.New(logger, &config.Smb)
|
collectors[smb.Name] = smb.New(logger, &config.SMB)
|
||||||
collectors[smbclient.Name] = smbclient.New(logger, &config.SmbClient)
|
collectors[smbclient.Name] = smbclient.New(logger, &config.SMBClient)
|
||||||
collectors[smtp.Name] = smtp.New(logger, &config.Smtp)
|
collectors[smtp.Name] = smtp.New(logger, &config.SMTP)
|
||||||
collectors[system.Name] = system.New(logger, &config.System)
|
collectors[system.Name] = system.New(logger, &config.System)
|
||||||
collectors[teradici_pcoip.Name] = teradici_pcoip.New(logger, &config.TeradiciPcoip)
|
collectors[teradici_pcoip.Name] = teradici_pcoip.New(logger, &config.TeradiciPcoip)
|
||||||
collectors[tcp.Name] = tcp.New(logger, &config.Tcp)
|
collectors[tcp.Name] = tcp.New(logger, &config.TCP)
|
||||||
collectors[terminal_services.Name] = terminal_services.New(logger, &config.TerminalServices)
|
collectors[terminal_services.Name] = terminal_services.New(logger, &config.TerminalServices)
|
||||||
collectors[textfile.Name] = textfile.New(logger, &config.Textfile)
|
collectors[textfile.Name] = textfile.New(logger, &config.Textfile)
|
||||||
collectors[thermalzone.Name] = thermalzone.New(logger, &config.Thermalzone)
|
collectors[thermalzone.Name] = thermalzone.New(logger, &config.Thermalzone)
|
||||||
@@ -151,8 +151,8 @@ func NewWithConfig(logger log.Logger, config Config) Collectors {
|
|||||||
return New(collectors)
|
return New(collectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New To be called by the external libraries for collector initialization
|
// New To be called by the external libraries for collector initialization.
|
||||||
func New(collectors map[string]types.Collector) Collectors {
|
func New(collectors Map) Collectors {
|
||||||
return Collectors{
|
return Collectors{
|
||||||
collectors: collectors,
|
collectors: collectors,
|
||||||
}
|
}
|
||||||
@@ -195,7 +195,7 @@ func (c *Collectors) SetPerfCounterQuery() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable removes all collectors that not enabledCollectors
|
// Enable removes all collectors that not enabledCollectors.
|
||||||
func (c *Collectors) Enable(enabledCollectors []string) {
|
func (c *Collectors) Enable(enabledCollectors []string) {
|
||||||
for name := range c.collectors {
|
for name := range c.collectors {
|
||||||
if !slices.Contains(enabledCollectors, name) {
|
if !slices.Contains(enabledCollectors, name) {
|
||||||
@@ -204,9 +204,10 @@ func (c *Collectors) Enable(enabledCollectors []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build To be called by the exporter for collector initialization
|
// Build To be called by the exporter for collector initialization.
|
||||||
func (c *Collectors) Build() error {
|
func (c *Collectors) Build() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for _, collector := range c.collectors {
|
for _, collector := range c.collectors {
|
||||||
if err = collector.Build(); err != nil {
|
if err = collector.Build(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -216,7 +217,7 @@ func (c *Collectors) Build() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareScrapeContext creates a ScrapeContext to be used during a single scrape
|
// PrepareScrapeContext creates a ScrapeContext to be used during a single scrape.
|
||||||
func (c *Collectors) PrepareScrapeContext() (*types.ScrapeContext, error) {
|
func (c *Collectors) PrepareScrapeContext() (*types.ScrapeContext, error) {
|
||||||
objs, err := perflib.GetPerflibSnapshot(c.perfCounterQuery)
|
objs, err := perflib.GetPerflibSnapshot(c.perfCounterQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -225,3 +226,16 @@ func (c *Collectors) PrepareScrapeContext() (*types.ScrapeContext, error) {
|
|||||||
|
|
||||||
return &types.ScrapeContext{PerfObjects: objs}, nil
|
return &types.ScrapeContext{PerfObjects: objs}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close To be called by the exporter for collector cleanup.
|
||||||
|
func (c *Collectors) Close() error {
|
||||||
|
errs := make([]error, 0, len(c.collectors))
|
||||||
|
|
||||||
|
for _, collector := range c.collectors {
|
||||||
|
if err := collector.Build(); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/diskdrive"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/diskdrive"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/dns"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/dns"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/exchange"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/exchange"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/collector/fsrmquota"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/hyperv"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/hyperv"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/iis"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/iis"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/license"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/license"
|
||||||
@@ -59,22 +60,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Ad ad.Config `yaml:"ad"`
|
AD ad.Config `yaml:"ad"`
|
||||||
Adcs adcs.Config `yaml:"adcs"`
|
ADCS adcs.Config `yaml:"adcs"`
|
||||||
Adfs adfs.Config `yaml:"adfs"`
|
ADFS adfs.Config `yaml:"adfs"`
|
||||||
Cache cache.Config `yaml:"cache"`
|
Cache cache.Config `yaml:"cache"`
|
||||||
Container container.Config `yaml:"container"`
|
Container container.Config `yaml:"container"`
|
||||||
Cpu cpu.Config `yaml:"cpu"`
|
CPU cpu.Config `yaml:"cpu"`
|
||||||
CpuInfo cpu_info.Config `yaml:"cpu_info"`
|
CPUInfo cpu_info.Config `yaml:"cpu_info"`
|
||||||
Cs cs.Config `yaml:"cs"`
|
Cs cs.Config `yaml:"cs"`
|
||||||
Dfsr dfsr.Config `yaml:"dfsr"`
|
DFSR dfsr.Config `yaml:"dfsr"`
|
||||||
Dhcp dhcp.Config `yaml:"dhcp"`
|
Dhcp dhcp.Config `yaml:"dhcp"`
|
||||||
Diskdrive diskdrive.Config `yaml:"diskdrive"`
|
DiskDrive diskdrive.Config `yaml:"diskdrive"` //nolint:tagliatelle
|
||||||
Dns dns.Config `yaml:"dns"`
|
DNS dns.Config `yaml:"dns"`
|
||||||
Exchange exchange.Config `yaml:"exchange"`
|
Exchange exchange.Config `yaml:"exchange"`
|
||||||
Fsrmquota exchange.Config `yaml:"fsrmquota"`
|
Fsrmquota fsrmquota.Config `yaml:"fsrmquota"`
|
||||||
Hyperv hyperv.Config `yaml:"hyperv"`
|
Hyperv hyperv.Config `yaml:"hyperv"`
|
||||||
Iis iis.Config `yaml:"iis"`
|
IIS iis.Config `yaml:"iis"`
|
||||||
License license.Config `yaml:"license"`
|
License license.Config `yaml:"license"`
|
||||||
LogicalDisk logical_disk.Config `yaml:"logical_disk"`
|
LogicalDisk logical_disk.Config `yaml:"logical_disk"`
|
||||||
Logon logon.Config `yaml:"logon"`
|
Logon logon.Config `yaml:"logon"`
|
||||||
@@ -83,7 +84,7 @@ type Config struct {
|
|||||||
MsclusterNetwork mscluster_network.Config `yaml:"mscluster_network"`
|
MsclusterNetwork mscluster_network.Config `yaml:"mscluster_network"`
|
||||||
MsclusterNode mscluster_node.Config `yaml:"mscluster_node"`
|
MsclusterNode mscluster_node.Config `yaml:"mscluster_node"`
|
||||||
MsclusterResource mscluster_resource.Config `yaml:"mscluster_resource"`
|
MsclusterResource mscluster_resource.Config `yaml:"mscluster_resource"`
|
||||||
MsclusterResourceGroup mscluster_resourcegroup.Config `yaml:"mscluster_resourcegroup"`
|
MsclusterResourceGroup mscluster_resourcegroup.Config `yaml:"mscluster_resourcegroup"` //nolint:tagliatelle
|
||||||
Msmq msmq.Config `yaml:"msmq"`
|
Msmq msmq.Config `yaml:"msmq"`
|
||||||
Mssql mssql.Config `yaml:"mssql"`
|
Mssql mssql.Config `yaml:"mssql"`
|
||||||
Net net.Config `yaml:"net"`
|
Net net.Config `yaml:"net"`
|
||||||
@@ -103,12 +104,12 @@ type Config struct {
|
|||||||
RemoteFx remote_fx.Config `yaml:"remote_fx"`
|
RemoteFx remote_fx.Config `yaml:"remote_fx"`
|
||||||
ScheduledTask scheduled_task.Config `yaml:"scheduled_task"`
|
ScheduledTask scheduled_task.Config `yaml:"scheduled_task"`
|
||||||
Service service.Config `yaml:"service"`
|
Service service.Config `yaml:"service"`
|
||||||
Smb smb.Config `yaml:"smb"`
|
SMB smb.Config `yaml:"smb"`
|
||||||
SmbClient smbclient.Config `yaml:"smbclient"`
|
SMBClient smbclient.Config `yaml:"smbclient"` //nolint:tagliatelle
|
||||||
Smtp smtp.Config `yaml:"smtp"`
|
SMTP smtp.Config `yaml:"smtp"`
|
||||||
System system.Config `yaml:"system"`
|
System system.Config `yaml:"system"`
|
||||||
TeradiciPcoip teradici_pcoip.Config `yaml:"teradici_pcoip"`
|
TeradiciPcoip teradici_pcoip.Config `yaml:"teradici_pcoip"`
|
||||||
Tcp tcp.Config `yaml:"tcp"`
|
TCP tcp.Config `yaml:"tcp"`
|
||||||
TerminalServices terminal_services.Config `yaml:"terminal_services"`
|
TerminalServices terminal_services.Config `yaml:"terminal_services"`
|
||||||
Textfile textfile.Config `yaml:"textfile"`
|
Textfile textfile.Config `yaml:"textfile"`
|
||||||
Thermalzone thermalzone.Config `yaml:"thermalzone"`
|
Thermalzone thermalzone.Config `yaml:"thermalzone"`
|
||||||
@@ -121,22 +122,22 @@ type Config struct {
|
|||||||
//
|
//
|
||||||
//goland:noinspection GoUnusedGlobalVariable
|
//goland:noinspection GoUnusedGlobalVariable
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
Ad: ad.ConfigDefaults,
|
AD: ad.ConfigDefaults,
|
||||||
Adcs: adcs.ConfigDefaults,
|
ADCS: adcs.ConfigDefaults,
|
||||||
Adfs: adfs.ConfigDefaults,
|
ADFS: adfs.ConfigDefaults,
|
||||||
Cache: cache.ConfigDefaults,
|
Cache: cache.ConfigDefaults,
|
||||||
Container: container.ConfigDefaults,
|
Container: container.ConfigDefaults,
|
||||||
Cpu: cpu.ConfigDefaults,
|
CPU: cpu.ConfigDefaults,
|
||||||
CpuInfo: cpu_info.ConfigDefaults,
|
CPUInfo: cpu_info.ConfigDefaults,
|
||||||
Cs: cs.ConfigDefaults,
|
Cs: cs.ConfigDefaults,
|
||||||
Dfsr: dfsr.ConfigDefaults,
|
DFSR: dfsr.ConfigDefaults,
|
||||||
Dhcp: dhcp.ConfigDefaults,
|
Dhcp: dhcp.ConfigDefaults,
|
||||||
Diskdrive: diskdrive.ConfigDefaults,
|
DiskDrive: diskdrive.ConfigDefaults,
|
||||||
Dns: dns.ConfigDefaults,
|
DNS: dns.ConfigDefaults,
|
||||||
Exchange: exchange.ConfigDefaults,
|
Exchange: exchange.ConfigDefaults,
|
||||||
Fsrmquota: exchange.ConfigDefaults,
|
Fsrmquota: fsrmquota.ConfigDefaults,
|
||||||
Hyperv: hyperv.ConfigDefaults,
|
Hyperv: hyperv.ConfigDefaults,
|
||||||
Iis: iis.ConfigDefaults,
|
IIS: iis.ConfigDefaults,
|
||||||
License: license.ConfigDefaults,
|
License: license.ConfigDefaults,
|
||||||
LogicalDisk: logical_disk.ConfigDefaults,
|
LogicalDisk: logical_disk.ConfigDefaults,
|
||||||
Logon: logon.ConfigDefaults,
|
Logon: logon.ConfigDefaults,
|
||||||
@@ -165,12 +166,12 @@ var ConfigDefaults = Config{
|
|||||||
RemoteFx: remote_fx.ConfigDefaults,
|
RemoteFx: remote_fx.ConfigDefaults,
|
||||||
ScheduledTask: scheduled_task.ConfigDefaults,
|
ScheduledTask: scheduled_task.ConfigDefaults,
|
||||||
Service: service.ConfigDefaults,
|
Service: service.ConfigDefaults,
|
||||||
Smb: smb.ConfigDefaults,
|
SMB: smb.ConfigDefaults,
|
||||||
SmbClient: smbclient.ConfigDefaults,
|
SMBClient: smbclient.ConfigDefaults,
|
||||||
Smtp: smtp.ConfigDefaults,
|
SMTP: smtp.ConfigDefaults,
|
||||||
System: system.ConfigDefaults,
|
System: system.ConfigDefaults,
|
||||||
TeradiciPcoip: teradici_pcoip.ConfigDefaults,
|
TeradiciPcoip: teradici_pcoip.ConfigDefaults,
|
||||||
Tcp: tcp.ConfigDefaults,
|
TCP: tcp.ConfigDefaults,
|
||||||
TerminalServices: terminal_services.ConfigDefaults,
|
TerminalServices: terminal_services.ConfigDefaults,
|
||||||
Textfile: textfile.ConfigDefaults,
|
Textfile: textfile.ConfigDefaults,
|
||||||
Thermalzone: thermalzone.ConfigDefaults,
|
Thermalzone: thermalzone.ConfigDefaults,
|
||||||
|
|||||||
@@ -20,167 +20,181 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for containers metrics
|
// A Collector is a Prometheus Collector for containers metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
// Presence
|
// Presence
|
||||||
ContainerAvailable *prometheus.Desc
|
containerAvailable *prometheus.Desc
|
||||||
|
|
||||||
// Number of containers
|
// Number of containers
|
||||||
ContainersCount *prometheus.Desc
|
containersCount *prometheus.Desc
|
||||||
// memory
|
|
||||||
UsageCommitBytes *prometheus.Desc
|
// Memory
|
||||||
UsageCommitPeakBytes *prometheus.Desc
|
usageCommitBytes *prometheus.Desc
|
||||||
UsagePrivateWorkingSetBytes *prometheus.Desc
|
usageCommitPeakBytes *prometheus.Desc
|
||||||
|
usagePrivateWorkingSetBytes *prometheus.Desc
|
||||||
|
|
||||||
// CPU
|
// CPU
|
||||||
RuntimeTotal *prometheus.Desc
|
runtimeTotal *prometheus.Desc
|
||||||
RuntimeUser *prometheus.Desc
|
runtimeUser *prometheus.Desc
|
||||||
RuntimeKernel *prometheus.Desc
|
runtimeKernel *prometheus.Desc
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
BytesReceived *prometheus.Desc
|
bytesReceived *prometheus.Desc
|
||||||
BytesSent *prometheus.Desc
|
bytesSent *prometheus.Desc
|
||||||
PacketsReceived *prometheus.Desc
|
packetsReceived *prometheus.Desc
|
||||||
PacketsSent *prometheus.Desc
|
packetsSent *prometheus.Desc
|
||||||
DroppedPacketsIncoming *prometheus.Desc
|
droppedPacketsIncoming *prometheus.Desc
|
||||||
DroppedPacketsOutgoing *prometheus.Desc
|
droppedPacketsOutgoing *prometheus.Desc
|
||||||
|
|
||||||
// Storage
|
// Storage
|
||||||
ReadCountNormalized *prometheus.Desc
|
readCountNormalized *prometheus.Desc
|
||||||
ReadSizeBytes *prometheus.Desc
|
readSizeBytes *prometheus.Desc
|
||||||
WriteCountNormalized *prometheus.Desc
|
writeCountNormalized *prometheus.Desc
|
||||||
WriteSizeBytes *prometheus.Desc
|
writeSizeBytes *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
// New constructs a new collector
|
// New constructs a new Collector.
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.ContainerAvailable = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.containerAvailable = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "available"),
|
prometheus.BuildFQName(types.Namespace, Name, "available"),
|
||||||
"Available",
|
"Available",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ContainersCount = prometheus.NewDesc(
|
c.containersCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
||||||
"Number of containers",
|
"Number of containers",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.UsageCommitBytes = prometheus.NewDesc(
|
c.usageCommitBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "memory_usage_commit_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "memory_usage_commit_bytes"),
|
||||||
"Memory Usage Commit Bytes",
|
"Memory Usage Commit Bytes",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.UsageCommitPeakBytes = prometheus.NewDesc(
|
c.usageCommitPeakBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "memory_usage_commit_peak_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "memory_usage_commit_peak_bytes"),
|
||||||
"Memory Usage Commit Peak Bytes",
|
"Memory Usage Commit Peak Bytes",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.UsagePrivateWorkingSetBytes = prometheus.NewDesc(
|
c.usagePrivateWorkingSetBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "memory_usage_private_working_set_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "memory_usage_private_working_set_bytes"),
|
||||||
"Memory Usage Private Working Set Bytes",
|
"Memory Usage Private Working Set Bytes",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RuntimeTotal = prometheus.NewDesc(
|
c.runtimeTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_usage_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_usage_seconds_total"),
|
||||||
"Total Run time in Seconds",
|
"Total Run time in Seconds",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RuntimeUser = prometheus.NewDesc(
|
c.runtimeUser = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_usage_seconds_usermode"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_usage_seconds_usermode"),
|
||||||
"Run Time in User mode in Seconds",
|
"Run Time in User mode in Seconds",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RuntimeKernel = prometheus.NewDesc(
|
c.runtimeKernel = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_usage_seconds_kernelmode"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_usage_seconds_kernelmode"),
|
||||||
"Run time in Kernel mode in Seconds",
|
"Run time in Kernel mode in Seconds",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesReceived = prometheus.NewDesc(
|
c.bytesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "network_receive_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "network_receive_bytes_total"),
|
||||||
"Bytes Received on Interface",
|
"Bytes Received on Interface",
|
||||||
[]string{"container_id", "interface"},
|
[]string{"container_id", "interface"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesSent = prometheus.NewDesc(
|
c.bytesSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "network_transmit_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "network_transmit_bytes_total"),
|
||||||
"Bytes Sent on Interface",
|
"Bytes Sent on Interface",
|
||||||
[]string{"container_id", "interface"},
|
[]string{"container_id", "interface"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsReceived = prometheus.NewDesc(
|
c.packetsReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "network_receive_packets_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "network_receive_packets_total"),
|
||||||
"Packets Received on Interface",
|
"Packets Received on Interface",
|
||||||
[]string{"container_id", "interface"},
|
[]string{"container_id", "interface"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsSent = prometheus.NewDesc(
|
c.packetsSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "network_transmit_packets_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "network_transmit_packets_total"),
|
||||||
"Packets Sent on Interface",
|
"Packets Sent on Interface",
|
||||||
[]string{"container_id", "interface"},
|
[]string{"container_id", "interface"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DroppedPacketsIncoming = prometheus.NewDesc(
|
c.droppedPacketsIncoming = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "network_receive_packets_dropped_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "network_receive_packets_dropped_total"),
|
||||||
"Dropped Incoming Packets on Interface",
|
"Dropped Incoming Packets on Interface",
|
||||||
[]string{"container_id", "interface"},
|
[]string{"container_id", "interface"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DroppedPacketsOutgoing = prometheus.NewDesc(
|
c.droppedPacketsOutgoing = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "network_transmit_packets_dropped_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "network_transmit_packets_dropped_total"),
|
||||||
"Dropped Outgoing Packets on Interface",
|
"Dropped Outgoing Packets on Interface",
|
||||||
[]string{"container_id", "interface"},
|
[]string{"container_id", "interface"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ReadCountNormalized = prometheus.NewDesc(
|
c.readCountNormalized = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "storage_read_count_normalized_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "storage_read_count_normalized_total"),
|
||||||
"Read Count Normalized",
|
"Read Count Normalized",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ReadSizeBytes = prometheus.NewDesc(
|
c.readSizeBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "storage_read_size_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "storage_read_size_bytes_total"),
|
||||||
"Read Size Bytes",
|
"Read Size Bytes",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WriteCountNormalized = prometheus.NewDesc(
|
c.writeCountNormalized = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "storage_write_count_normalized_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "storage_write_count_normalized_total"),
|
||||||
"Write Count Normalized",
|
"Write Count Normalized",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WriteSizeBytes = prometheus.NewDesc(
|
c.writeSizeBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "storage_write_size_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "storage_write_size_bytes_total"),
|
||||||
"Write Size Bytes",
|
"Write Size Bytes",
|
||||||
[]string{"container_id"},
|
[]string{"container_id"},
|
||||||
@@ -191,7 +205,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting collector metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting collector metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -199,15 +213,15 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// containerClose closes the container resource
|
// containerClose closes the container resource.
|
||||||
func (c *collector) containerClose(container hcsshim.Container) {
|
func (c *Collector) containerClose(container hcsshim.Container) {
|
||||||
err := container.Close()
|
err := container.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = level.Error(c.logger).Log("err", err)
|
_ = level.Error(c.logger).Log("err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
// Types Container is passed to get the containers compute systems only
|
// Types Container is passed to get the containers compute systems only
|
||||||
containers, err := hcsshim.GetContainers(hcsshim.ComputeSystemQuery{Types: []string{"Container"}})
|
containers, err := hcsshim.GetContainers(hcsshim.ComputeSystemQuery{Types: []string{"Container"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -218,7 +232,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
count := len(containers)
|
count := len(containers)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContainersCount,
|
c.containersCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(count),
|
float64(count),
|
||||||
)
|
)
|
||||||
@@ -250,67 +264,67 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
containerPrefixes[containerDetails.ID] = containerIdWithPrefix
|
containerPrefixes[containerDetails.ID] = containerIdWithPrefix
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContainerAvailable,
|
c.containerAvailable,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
1,
|
1,
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UsageCommitBytes,
|
c.usageCommitBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(cstats.Memory.UsageCommitBytes),
|
float64(cstats.Memory.UsageCommitBytes),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UsageCommitPeakBytes,
|
c.usageCommitPeakBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(cstats.Memory.UsageCommitPeakBytes),
|
float64(cstats.Memory.UsageCommitPeakBytes),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UsagePrivateWorkingSetBytes,
|
c.usagePrivateWorkingSetBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(cstats.Memory.UsagePrivateWorkingSetBytes),
|
float64(cstats.Memory.UsagePrivateWorkingSetBytes),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RuntimeTotal,
|
c.runtimeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Processor.TotalRuntime100ns)*perflib.TicksToSecondScaleFactor,
|
float64(cstats.Processor.TotalRuntime100ns)*perflib.TicksToSecondScaleFactor,
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RuntimeUser,
|
c.runtimeUser,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Processor.RuntimeUser100ns)*perflib.TicksToSecondScaleFactor,
|
float64(cstats.Processor.RuntimeUser100ns)*perflib.TicksToSecondScaleFactor,
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RuntimeKernel,
|
c.runtimeKernel,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Processor.RuntimeKernel100ns)*perflib.TicksToSecondScaleFactor,
|
float64(cstats.Processor.RuntimeKernel100ns)*perflib.TicksToSecondScaleFactor,
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadCountNormalized,
|
c.readCountNormalized,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Storage.ReadCountNormalized),
|
float64(cstats.Storage.ReadCountNormalized),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadSizeBytes,
|
c.readSizeBytes,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Storage.ReadSizeBytes),
|
float64(cstats.Storage.ReadSizeBytes),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteCountNormalized,
|
c.writeCountNormalized,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Storage.WriteCountNormalized),
|
float64(cstats.Storage.WriteCountNormalized),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteSizeBytes,
|
c.writeSizeBytes,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(cstats.Storage.WriteSizeBytes),
|
float64(cstats.Storage.WriteSizeBytes),
|
||||||
containerIdWithPrefix,
|
containerIdWithPrefix,
|
||||||
@@ -346,38 +360,38 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesReceived,
|
c.bytesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(endpointStats.BytesReceived),
|
float64(endpointStats.BytesReceived),
|
||||||
containerIdWithPrefix, endpointId,
|
containerIdWithPrefix, endpointId,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesSent,
|
c.bytesSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(endpointStats.BytesSent),
|
float64(endpointStats.BytesSent),
|
||||||
containerIdWithPrefix, endpointId,
|
containerIdWithPrefix, endpointId,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceived,
|
c.packetsReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(endpointStats.PacketsReceived),
|
float64(endpointStats.PacketsReceived),
|
||||||
containerIdWithPrefix, endpointId,
|
containerIdWithPrefix, endpointId,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsSent,
|
c.packetsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(endpointStats.PacketsSent),
|
float64(endpointStats.PacketsSent),
|
||||||
containerIdWithPrefix, endpointId,
|
containerIdWithPrefix, endpointId,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DroppedPacketsIncoming,
|
c.droppedPacketsIncoming,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(endpointStats.DroppedPacketsIncoming),
|
float64(endpointStats.DroppedPacketsIncoming),
|
||||||
containerIdWithPrefix, endpointId,
|
containerIdWithPrefix, endpointId,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DroppedPacketsOutgoing,
|
c.droppedPacketsOutgoing,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(endpointStats.DroppedPacketsOutgoing),
|
float64(endpointStats.DroppedPacketsOutgoing),
|
||||||
containerIdWithPrefix, endpointId,
|
containerIdWithPrefix, endpointId,
|
||||||
|
|||||||
@@ -19,71 +19,82 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
CStateSecondsTotal *prometheus.Desc
|
cStateSecondsTotal *prometheus.Desc
|
||||||
TimeTotal *prometheus.Desc
|
timeTotal *prometheus.Desc
|
||||||
InterruptsTotal *prometheus.Desc
|
interruptsTotal *prometheus.Desc
|
||||||
DPCsTotal *prometheus.Desc
|
dpcsTotal *prometheus.Desc
|
||||||
|
clockInterruptsTotal *prometheus.Desc
|
||||||
ClockInterruptsTotal *prometheus.Desc
|
idleBreakEventsTotal *prometheus.Desc
|
||||||
IdleBreakEventsTotal *prometheus.Desc
|
parkingStatus *prometheus.Desc
|
||||||
ParkingStatus *prometheus.Desc
|
processorFrequencyMHz *prometheus.Desc
|
||||||
ProcessorFrequencyMHz *prometheus.Desc
|
processorPerformance *prometheus.Desc
|
||||||
ProcessorMaxFrequencyMHz *prometheus.Desc
|
processorMPerf *prometheus.Desc
|
||||||
ProcessorPerformance *prometheus.Desc
|
processorRTC *prometheus.Desc
|
||||||
ProcessorMPerf *prometheus.Desc
|
processorUtility *prometheus.Desc
|
||||||
ProcessorRTC *prometheus.Desc
|
processorPrivilegedUtility *prometheus.Desc
|
||||||
ProcessorUtility *prometheus.Desc
|
|
||||||
ProcessorPrivUtility *prometheus.Desc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
if winversion.WindowsVersionFloat > 6.05 {
|
if winversion.WindowsVersionFloat > 6.05 {
|
||||||
return []string{"Processor Information"}, nil
|
return []string{"Processor Information"}, nil
|
||||||
}
|
}
|
||||||
return []string{"Processor"}, nil
|
return []string{"Processor"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.CStateSecondsTotal = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.cStateSecondsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
|
||||||
"Time spent in low-power idle state",
|
"Time spent in low-power idle state",
|
||||||
[]string{"core", "state"},
|
[]string{"core", "state"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TimeTotal = prometheus.NewDesc(
|
c.timeTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "time_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "time_total"),
|
||||||
"Time that processor spent in different modes (dpc, idle, interrupt, privileged, user)",
|
"Time that processor spent in different modes (dpc, idle, interrupt, privileged, user)",
|
||||||
[]string{"core", "mode"},
|
[]string{"core", "mode"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.InterruptsTotal = prometheus.NewDesc(
|
c.interruptsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "interrupts_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "interrupts_total"),
|
||||||
"Total number of received and serviced hardware interrupts",
|
"Total number of received and serviced hardware interrupts",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DPCsTotal = prometheus.NewDesc(
|
c.dpcsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dpcs_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "dpcs_total"),
|
||||||
"Total number of received and serviced deferred procedure calls (DPCs)",
|
"Total number of received and serviced deferred procedure calls (DPCs)",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
@@ -100,79 +111,79 @@ func (c *collector) Build() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
c.CStateSecondsTotal = prometheus.NewDesc(
|
c.cStateSecondsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
|
||||||
"Time spent in low-power idle state",
|
"Time spent in low-power idle state",
|
||||||
[]string{"core", "state"},
|
[]string{"core", "state"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TimeTotal = prometheus.NewDesc(
|
c.timeTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "time_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "time_total"),
|
||||||
"Time that processor spent in different modes (dpc, idle, interrupt, privileged, user)",
|
"Time that processor spent in different modes (dpc, idle, interrupt, privileged, user)",
|
||||||
[]string{"core", "mode"},
|
[]string{"core", "mode"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.InterruptsTotal = prometheus.NewDesc(
|
c.interruptsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "interrupts_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "interrupts_total"),
|
||||||
"Total number of received and serviced hardware interrupts",
|
"Total number of received and serviced hardware interrupts",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DPCsTotal = prometheus.NewDesc(
|
c.dpcsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dpcs_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "dpcs_total"),
|
||||||
"Total number of received and serviced deferred procedure calls (DPCs)",
|
"Total number of received and serviced deferred procedure calls (DPCs)",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ClockInterruptsTotal = prometheus.NewDesc(
|
c.clockInterruptsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "clock_interrupts_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "clock_interrupts_total"),
|
||||||
"Total number of received and serviced clock tick interrupts",
|
"Total number of received and serviced clock tick interrupts",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.IdleBreakEventsTotal = prometheus.NewDesc(
|
c.idleBreakEventsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "idle_break_events_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "idle_break_events_total"),
|
||||||
"Total number of time processor was woken from idle",
|
"Total number of time processor was woken from idle",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ParkingStatus = prometheus.NewDesc(
|
c.parkingStatus = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "parking_status"),
|
prometheus.BuildFQName(types.Namespace, Name, "parking_status"),
|
||||||
"Parking Status represents whether a processor is parked or not",
|
"Parking Status represents whether a processor is parked or not",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorFrequencyMHz = prometheus.NewDesc(
|
c.processorFrequencyMHz = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "core_frequency_mhz"),
|
prometheus.BuildFQName(types.Namespace, Name, "core_frequency_mhz"),
|
||||||
"Core frequency in megahertz",
|
"Core frequency in megahertz",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorPerformance = prometheus.NewDesc(
|
c.processorPerformance = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processor_performance_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "processor_performance_total"),
|
||||||
"Processor Performance is the average performance of the processor while it is executing instructions, as a percentage of the nominal performance of the processor. On some processors, Processor Performance may exceed 100%",
|
"Processor Performance is the average performance of the processor while it is executing instructions, as a percentage of the nominal performance of the processor. On some processors, Processor Performance may exceed 100%",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorMPerf = prometheus.NewDesc(
|
c.processorMPerf = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processor_mperf_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "processor_mperf_total"),
|
||||||
"Processor MPerf is the number of TSC ticks incremented while executing instructions",
|
"Processor MPerf is the number of TSC ticks incremented while executing instructions",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorRTC = prometheus.NewDesc(
|
c.processorRTC = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processor_rtc_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "processor_rtc_total"),
|
||||||
"Processor RTC represents the number of RTC ticks made since the system booted. It should consistently be 64e6, and can be used to properly derive Processor Utility Rate",
|
"Processor RTC represents the number of RTC ticks made since the system booted. It should consistently be 64e6, and can be used to properly derive Processor Utility Rate",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorUtility = prometheus.NewDesc(
|
c.processorUtility = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processor_utility_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "processor_utility_total"),
|
||||||
"Processor Utility represents is the amount of time the core spends executing instructions",
|
"Processor Utility represents is the amount of time the core spends executing instructions",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorPrivUtility = prometheus.NewDesc(
|
c.processorPrivilegedUtility = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processor_privileged_utility_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "processor_privileged_utility_total"),
|
||||||
"Processor Privileged Utility represents is the amount of time the core has spent executing instructions inside the kernel",
|
"Processor Privileged Utility represents is the amount of time the core has spent executing instructions inside the kernel",
|
||||||
[]string{"core"},
|
[]string{"core"},
|
||||||
@@ -182,7 +193,7 @@ func (c *collector) Build() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if winversion.WindowsVersionFloat > 6.05 {
|
if winversion.WindowsVersionFloat > 6.05 {
|
||||||
return c.CollectFull(ctx, ch)
|
return c.CollectFull(ctx, ch)
|
||||||
}
|
}
|
||||||
@@ -209,7 +220,7 @@ type perflibProcessor struct {
|
|||||||
PercentUserTime float64 `perflib:"% User Time"`
|
PercentUserTime float64 `perflib:"% User Time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) CollectBasic(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) CollectBasic(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
data := make([]perflibProcessor, 0)
|
data := make([]perflibProcessor, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["Processor"], &data, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["Processor"], &data, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -223,63 +234,63 @@ func (c *collector) CollectBasic(ctx *types.ScrapeContext, ch chan<- prometheus.
|
|||||||
core := cpu.Name
|
core := cpu.Name
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CStateSecondsTotal,
|
c.cStateSecondsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentC1Time,
|
cpu.PercentC1Time,
|
||||||
core, "c1",
|
core, "c1",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CStateSecondsTotal,
|
c.cStateSecondsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentC2Time,
|
cpu.PercentC2Time,
|
||||||
core, "c2",
|
core, "c2",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CStateSecondsTotal,
|
c.cStateSecondsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentC3Time,
|
cpu.PercentC3Time,
|
||||||
core, "c3",
|
core, "c3",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentIdleTime,
|
cpu.PercentIdleTime,
|
||||||
core, "idle",
|
core, "idle",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentInterruptTime,
|
cpu.PercentInterruptTime,
|
||||||
core, "interrupt",
|
core, "interrupt",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentDPCTime,
|
cpu.PercentDPCTime,
|
||||||
core, "dpc",
|
core, "dpc",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentPrivilegedTime,
|
cpu.PercentPrivilegedTime,
|
||||||
core, "privileged",
|
core, "privileged",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PercentUserTime,
|
cpu.PercentUserTime,
|
||||||
core, "user",
|
core, "user",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InterruptsTotal,
|
c.interruptsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.Interrupts,
|
cpu.Interrupts,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DPCsTotal,
|
c.dpcsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.DPCsQueued,
|
cpu.DPCsQueued,
|
||||||
core,
|
core,
|
||||||
@@ -318,7 +329,7 @@ type perflibProcessorInformation struct {
|
|||||||
UserTimeSeconds float64 `perflib:"% User Time"`
|
UserTimeSeconds float64 `perflib:"% User Time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) CollectFull(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) CollectFull(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
data := make([]perflibProcessorInformation, 0)
|
data := make([]perflibProcessorInformation, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["Processor Information"], &data, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["Processor Information"], &data, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -332,119 +343,119 @@ func (c *collector) CollectFull(ctx *types.ScrapeContext, ch chan<- prometheus.M
|
|||||||
core := cpu.Name
|
core := cpu.Name
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CStateSecondsTotal,
|
c.cStateSecondsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.C1TimeSeconds,
|
cpu.C1TimeSeconds,
|
||||||
core, "c1",
|
core, "c1",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CStateSecondsTotal,
|
c.cStateSecondsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.C2TimeSeconds,
|
cpu.C2TimeSeconds,
|
||||||
core, "c2",
|
core, "c2",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CStateSecondsTotal,
|
c.cStateSecondsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.C3TimeSeconds,
|
cpu.C3TimeSeconds,
|
||||||
core, "c3",
|
core, "c3",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.IdleTimeSeconds,
|
cpu.IdleTimeSeconds,
|
||||||
core, "idle",
|
core, "idle",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.InterruptTimeSeconds,
|
cpu.InterruptTimeSeconds,
|
||||||
core, "interrupt",
|
core, "interrupt",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.DPCTimeSeconds,
|
cpu.DPCTimeSeconds,
|
||||||
core, "dpc",
|
core, "dpc",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PrivilegedTimeSeconds,
|
cpu.PrivilegedTimeSeconds,
|
||||||
core, "privileged",
|
core, "privileged",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeTotal,
|
c.timeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.UserTimeSeconds,
|
cpu.UserTimeSeconds,
|
||||||
core, "user",
|
core, "user",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InterruptsTotal,
|
c.interruptsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.InterruptsTotal,
|
cpu.InterruptsTotal,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DPCsTotal,
|
c.dpcsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.DPCsQueuedTotal,
|
cpu.DPCsQueuedTotal,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ClockInterruptsTotal,
|
c.clockInterruptsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.ClockInterruptsTotal,
|
cpu.ClockInterruptsTotal,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IdleBreakEventsTotal,
|
c.idleBreakEventsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.IdleBreakEventsTotal,
|
cpu.IdleBreakEventsTotal,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ParkingStatus,
|
c.parkingStatus,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
cpu.ParkingStatus,
|
cpu.ParkingStatus,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorFrequencyMHz,
|
c.processorFrequencyMHz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
cpu.ProcessorFrequencyMHz,
|
cpu.ProcessorFrequencyMHz,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorPerformance,
|
c.processorPerformance,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.ProcessorPerformance,
|
cpu.ProcessorPerformance,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorMPerf,
|
c.processorMPerf,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.ProcessorMPerf,
|
cpu.ProcessorMPerf,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorRTC,
|
c.processorRTC,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.ProcessorRTC,
|
cpu.ProcessorRTC,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorUtility,
|
c.processorUtility,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.ProcessorUtilityRate,
|
cpu.ProcessorUtilityRate,
|
||||||
core,
|
core,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorPrivUtility,
|
c.processorPrivilegedUtility,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
cpu.PrivilegedUtilitySeconds,
|
cpu.PrivilegedUtilitySeconds,
|
||||||
core,
|
core,
|
||||||
|
|||||||
@@ -25,39 +25,52 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for a few WMI metrics in Win32_Processor
|
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_Processor.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
CpuInfo *prometheus.Desc
|
cpuInfo *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.CpuInfo = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.cpuInfo = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, "", Name),
|
prometheus.BuildFQName(types.Namespace, "", Name),
|
||||||
"Labelled CPU information as provided provided by Win32_Processor",
|
"Labelled CPU information as provided by Win32_Processor",
|
||||||
[]string{
|
[]string{
|
||||||
"architecture",
|
"architecture",
|
||||||
"device_id",
|
"device_id",
|
||||||
@@ -85,7 +98,7 @@ type win32_Processor struct {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting cpu_info metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting cpu_info metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -93,7 +106,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_Processor
|
var dst []win32_Processor
|
||||||
// We use a static query here because the provided methods in wmi.go all issue a SELECT *;
|
// We use a static query here because the provided methods in wmi.go all issue a SELECT *;
|
||||||
// This results in the time-consuming LoadPercentage field being read which seems to measure each CPU
|
// This results in the time-consuming LoadPercentage field being read which seems to measure each CPU
|
||||||
@@ -108,7 +121,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
// Some CPUs end up exposing trailing spaces for certain strings, so clean them up
|
// Some CPUs end up exposing trailing spaces for certain strings, so clean them up
|
||||||
for _, processor := range dst {
|
for _, processor := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CpuInfo,
|
c.cpuInfo,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1.0,
|
1.0,
|
||||||
strconv.Itoa(int(processor.Architecture)),
|
strconv.Itoa(int(processor.Architecture)),
|
||||||
|
|||||||
12
pkg/collector/cpu_info/cpu_info_test.go
Normal file
12
pkg/collector/cpu_info/cpu_info_test.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package cpu_info_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/collector/cpu_info"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/testutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCollector(b *testing.B) {
|
||||||
|
testutils.FuncBenchmarkCollector(b, cpu_info.Name, cpu_info.NewWithFlags)
|
||||||
|
}
|
||||||
@@ -17,51 +17,64 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI metrics
|
// A Collector is a Prometheus Collector for WMI metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
PhysicalMemoryBytes *prometheus.Desc
|
physicalMemoryBytes *prometheus.Desc
|
||||||
LogicalProcessors *prometheus.Desc
|
logicalProcessors *prometheus.Desc
|
||||||
Hostname *prometheus.Desc
|
hostname *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.LogicalProcessors = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.logicalProcessors = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "logical_processors"),
|
prometheus.BuildFQName(types.Namespace, Name, "logical_processors"),
|
||||||
"ComputerSystem.NumberOfLogicalProcessors",
|
"ComputerSystem.NumberOfLogicalProcessors",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PhysicalMemoryBytes = prometheus.NewDesc(
|
c.physicalMemoryBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "physical_memory_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "physical_memory_bytes"),
|
||||||
"ComputerSystem.TotalPhysicalMemory",
|
"ComputerSystem.TotalPhysicalMemory",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Hostname = prometheus.NewDesc(
|
c.hostname = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "hostname"),
|
prometheus.BuildFQName(types.Namespace, Name, "hostname"),
|
||||||
"Labelled system hostname information as provided by ComputerSystem.DNSHostName and ComputerSystem.Domain",
|
"Labelled system hostname information as provided by ComputerSystem.DNSHostName and ComputerSystem.Domain",
|
||||||
[]string{
|
[]string{
|
||||||
@@ -76,7 +89,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting cs metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting cs metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -84,7 +97,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
// Get systeminfo for number of processors
|
// Get systeminfo for number of processors
|
||||||
systemInfo := sysinfoapi.GetSystemInfo()
|
systemInfo := sysinfoapi.GetSystemInfo()
|
||||||
|
|
||||||
@@ -95,13 +108,13 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogicalProcessors,
|
c.logicalProcessors,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(systemInfo.NumberOfProcessors),
|
float64(systemInfo.NumberOfProcessors),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PhysicalMemoryBytes,
|
c.physicalMemoryBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(mem.TotalPhys),
|
float64(mem.TotalPhys),
|
||||||
)
|
)
|
||||||
@@ -120,7 +133,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Hostname,
|
c.hostname,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1.0,
|
1.0,
|
||||||
hostname,
|
hostname,
|
||||||
|
|||||||
@@ -3,89 +3,87 @@
|
|||||||
package dfsr
|
package dfsr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "dfsr"
|
||||||
Name = "dfsr"
|
|
||||||
FlagDfsrEnabledCollectors = "collectors.dfsr.sources-enabled"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DfsrEnabledCollectors string `yaml:"enabled_collectors"`
|
CollectorsEnabled []string `yaml:"collectors_enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
DfsrEnabledCollectors: "connection,folder,volume",
|
CollectorsEnabled: []string{"connection", "folder", "volume"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// collector contains the metric and state data of the DFSR collectors.
|
// Collector contains the metric and state data of the DFSR collectors.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
dfsrEnabledCollectors *string
|
// connection source
|
||||||
|
connectionBandwidthSavingsUsingDFSReplicationTotal *prometheus.Desc
|
||||||
|
connectionBytesReceivedTotal *prometheus.Desc
|
||||||
|
connectionCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
connectionFilesReceivedTotal *prometheus.Desc
|
||||||
|
connectionRDCBytesReceivedTotal *prometheus.Desc
|
||||||
|
connectionRDCCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
connectionRDCSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
connectionRDCNumberofFilesReceivedTotal *prometheus.Desc
|
||||||
|
connectionSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
|
||||||
// Connection source
|
// folder source
|
||||||
ConnectionBandwidthSavingsUsingDFSReplicationTotal *prometheus.Desc
|
folderBandwidthSavingsUsingDFSReplicationTotal *prometheus.Desc
|
||||||
ConnectionBytesReceivedTotal *prometheus.Desc
|
folderCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
ConnectionCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
folderConflictBytesCleanedupTotal *prometheus.Desc
|
||||||
ConnectionFilesReceivedTotal *prometheus.Desc
|
folderConflictBytesGeneratedTotal *prometheus.Desc
|
||||||
ConnectionRDCBytesReceivedTotal *prometheus.Desc
|
folderConflictFilesCleanedUpTotal *prometheus.Desc
|
||||||
ConnectionRDCCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
folderConflictFilesGeneratedTotal *prometheus.Desc
|
||||||
ConnectionRDCSizeOfFilesReceivedTotal *prometheus.Desc
|
folderConflictfolderCleanupsCompletedTotal *prometheus.Desc
|
||||||
ConnectionRDCNumberofFilesReceivedTotal *prometheus.Desc
|
folderConflictSpaceInUse *prometheus.Desc
|
||||||
ConnectionSizeOfFilesReceivedTotal *prometheus.Desc
|
folderDeletedSpaceInUse *prometheus.Desc
|
||||||
|
folderDeletedBytesCleanedUpTotal *prometheus.Desc
|
||||||
|
folderDeletedBytesGeneratedTotal *prometheus.Desc
|
||||||
|
folderDeletedFilesCleanedUpTotal *prometheus.Desc
|
||||||
|
folderDeletedFilesGeneratedTotal *prometheus.Desc
|
||||||
|
folderFileInstallsRetriedTotal *prometheus.Desc
|
||||||
|
folderFileInstallsSucceededTotal *prometheus.Desc
|
||||||
|
folderFilesReceivedTotal *prometheus.Desc
|
||||||
|
folderRDCBytesReceivedTotal *prometheus.Desc
|
||||||
|
folderRDCCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
folderRDCNumberofFilesReceivedTotal *prometheus.Desc
|
||||||
|
folderRDCSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
folderSizeOfFilesReceivedTotal *prometheus.Desc
|
||||||
|
folderStagingSpaceInUse *prometheus.Desc
|
||||||
|
folderStagingBytesCleanedUpTotal *prometheus.Desc
|
||||||
|
folderStagingBytesGeneratedTotal *prometheus.Desc
|
||||||
|
folderStagingFilesCleanedUpTotal *prometheus.Desc
|
||||||
|
folderStagingFilesGeneratedTotal *prometheus.Desc
|
||||||
|
folderUpdatesDroppedTotal *prometheus.Desc
|
||||||
|
|
||||||
// Folder source
|
// volume source
|
||||||
FolderBandwidthSavingsUsingDFSReplicationTotal *prometheus.Desc
|
volumeDatabaseLookupsTotal *prometheus.Desc
|
||||||
FolderCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
volumeDatabaseCommitsTotal *prometheus.Desc
|
||||||
FolderConflictBytesCleanedupTotal *prometheus.Desc
|
volumeUSNJournalUnreadPercentage *prometheus.Desc
|
||||||
FolderConflictBytesGeneratedTotal *prometheus.Desc
|
volumeUSNJournalRecordsAcceptedTotal *prometheus.Desc
|
||||||
FolderConflictFilesCleanedUpTotal *prometheus.Desc
|
volumeUSNJournalRecordsReadTotal *prometheus.Desc
|
||||||
FolderConflictFilesGeneratedTotal *prometheus.Desc
|
|
||||||
FolderConflictFolderCleanupsCompletedTotal *prometheus.Desc
|
|
||||||
FolderConflictSpaceInUse *prometheus.Desc
|
|
||||||
FolderDeletedSpaceInUse *prometheus.Desc
|
|
||||||
FolderDeletedBytesCleanedUpTotal *prometheus.Desc
|
|
||||||
FolderDeletedBytesGeneratedTotal *prometheus.Desc
|
|
||||||
FolderDeletedFilesCleanedUpTotal *prometheus.Desc
|
|
||||||
FolderDeletedFilesGeneratedTotal *prometheus.Desc
|
|
||||||
FolderFileInstallsRetriedTotal *prometheus.Desc
|
|
||||||
FolderFileInstallsSucceededTotal *prometheus.Desc
|
|
||||||
FolderFilesReceivedTotal *prometheus.Desc
|
|
||||||
FolderRDCBytesReceivedTotal *prometheus.Desc
|
|
||||||
FolderRDCCompressedSizeOfFilesReceivedTotal *prometheus.Desc
|
|
||||||
FolderRDCNumberofFilesReceivedTotal *prometheus.Desc
|
|
||||||
FolderRDCSizeOfFilesReceivedTotal *prometheus.Desc
|
|
||||||
FolderSizeOfFilesReceivedTotal *prometheus.Desc
|
|
||||||
FolderStagingSpaceInUse *prometheus.Desc
|
|
||||||
FolderStagingBytesCleanedUpTotal *prometheus.Desc
|
|
||||||
FolderStagingBytesGeneratedTotal *prometheus.Desc
|
|
||||||
FolderStagingFilesCleanedUpTotal *prometheus.Desc
|
|
||||||
FolderStagingFilesGeneratedTotal *prometheus.Desc
|
|
||||||
FolderUpdatesDroppedTotal *prometheus.Desc
|
|
||||||
|
|
||||||
// Volume source
|
// Map of child Collector functions used during collection
|
||||||
VolumeDatabaseLookupsTotal *prometheus.Desc
|
|
||||||
VolumeDatabaseCommitsTotal *prometheus.Desc
|
|
||||||
VolumeUSNJournalUnreadPercentage *prometheus.Desc
|
|
||||||
VolumeUSNJournalRecordsAcceptedTotal *prometheus.Desc
|
|
||||||
VolumeUSNJournalRecordsReadTotal *prometheus.Desc
|
|
||||||
|
|
||||||
// Map of child collector functions used during collection
|
|
||||||
dfsrChildCollectors []dfsrCollectorFunc
|
dfsrChildCollectors []dfsrCollectorFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
type dfsrCollectorFunc func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error
|
type dfsrCollectorFunc func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error
|
||||||
|
|
||||||
// Map Perflib sources to DFSR collector names
|
// Map Perflib sources to DFSR Collector names
|
||||||
// e.g, volume -> DFS Replication Service Volumes
|
// e.g, volume -> DFS Replication Service Volumes.
|
||||||
func dfsrGetPerfObjectName(collector string) string {
|
func dfsrGetPerfObjectName(collector string) string {
|
||||||
prefix := "DFS "
|
prefix := "DFS "
|
||||||
suffix := ""
|
suffix := ""
|
||||||
@@ -100,38 +98,56 @@ func dfsrGetPerfObjectName(collector string) string {
|
|||||||
return prefix + suffix
|
return prefix + suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.CollectorsEnabled == nil {
|
||||||
dfsrEnabledCollectors: &config.DfsrEnabledCollectors,
|
config.CollectorsEnabled = ConfigDefaults.CollectorsEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
return &collector{
|
c := &Collector{
|
||||||
dfsrEnabledCollectors: app.
|
config: ConfigDefaults,
|
||||||
Flag(FlagDfsrEnabledCollectors, "Comma-seperated list of DFSR Perflib sources to use.").Default("connection,folder,volume").
|
|
||||||
Default(ConfigDefaults.DfsrEnabledCollectors).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var collectorsEnabled string
|
||||||
|
|
||||||
|
app.Flag("collectors.dfsr.sources-enabled", "Comma-separated list of DFSR Perflib sources to use.").
|
||||||
|
Default(strings.Join(ConfigDefaults.CollectorsEnabled, ",")).StringVar(&collectorsEnabled)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
c.config.CollectorsEnabled = strings.Split(collectorsEnabled, ",")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
// Perflib sources are dynamic, depending on the enabled child collectors
|
// Perflib sources are dynamic, depending on the enabled child collectors
|
||||||
expandedChildCollectors := utils.ExpandEnabledChildCollectors(*c.dfsrEnabledCollectors)
|
expandedChildCollectors := slices.Compact(c.config.CollectorsEnabled)
|
||||||
perflibDependencies := make([]string, 0, len(expandedChildCollectors))
|
perflibDependencies := make([]string, 0, len(expandedChildCollectors))
|
||||||
|
|
||||||
for _, source := range expandedChildCollectors {
|
for _, source := range expandedChildCollectors {
|
||||||
perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source))
|
perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source))
|
||||||
}
|
}
|
||||||
@@ -139,307 +155,313 @@ func (c *collector) GetPerfCounter() ([]string, error) {
|
|||||||
return perflibDependencies, nil
|
return perflibDependencies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
_ = level.Info(c.logger).Log("msg", "dfsr collector is in an experimental state! Metrics for this collector have not been tested.")
|
_ = level.Info(c.logger).Log("msg", "dfsr collector is in an experimental state! Metrics for this collector have not been tested.")
|
||||||
|
|
||||||
// Connection
|
// connection
|
||||||
c.ConnectionBandwidthSavingsUsingDFSReplicationTotal = prometheus.NewDesc(
|
c.connectionBandwidthSavingsUsingDFSReplicationTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_bandwidth_savings_using_dfs_replication_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_bandwidth_savings_using_dfs_replication_bytes_total"),
|
||||||
"Total bytes of bandwidth saved using DFS Replication for this connection",
|
"Total bytes of bandwidth saved using DFS Replication for this connection",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionBytesReceivedTotal = prometheus.NewDesc(
|
c.connectionBytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_bytes_received_total"),
|
||||||
"Total bytes received for connection",
|
"Total bytes received for connection",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.connectionCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_compressed_size_of_files_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_compressed_size_of_files_received_bytes_total"),
|
||||||
"Total compressed size of files received on the connection, in bytes",
|
"Total compressed size of files received on the connection, in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionFilesReceivedTotal = prometheus.NewDesc(
|
c.connectionFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_received_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_received_files_total"),
|
||||||
"Total number of files received for connection",
|
"Total number of files received for connection",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionRDCBytesReceivedTotal = prometheus.NewDesc(
|
c.connectionRDCBytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_received_bytes_total"),
|
||||||
"Total bytes received on the connection while replicating files using Remote Differential Compression",
|
"Total bytes received on the connection while replicating files using Remote Differential Compression",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionRDCCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.connectionRDCCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_compressed_size_of_received_files_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_compressed_size_of_received_files_bytes_total"),
|
||||||
"Total uncompressed size of files received with Remote Differential Compression for connection",
|
"Total uncompressed size of files received with Remote Differential Compression for connection",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionRDCNumberofFilesReceivedTotal = prometheus.NewDesc(
|
c.connectionRDCNumberofFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_received_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_received_files_total"),
|
||||||
"Total number of files received using remote differential compression",
|
"Total number of files received using remote differential compression",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionRDCSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.connectionRDCSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_size_of_received_files_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_rdc_size_of_received_files_bytes_total"),
|
||||||
"Total size of received Remote Differential Compression files, in bytes.",
|
"Total size of received Remote Differential Compression files, in bytes.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ConnectionSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.connectionSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_files_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_files_received_bytes_total"),
|
||||||
"Total size of files received, in bytes",
|
"Total size of files received, in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c. // Folder
|
// folder
|
||||||
FolderBandwidthSavingsUsingDFSReplicationTotal = prometheus.NewDesc(
|
c.folderBandwidthSavingsUsingDFSReplicationTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_bandwidth_savings_using_dfs_replication_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_bandwidth_savings_using_dfs_replication_bytes_total"),
|
||||||
"Total bytes of bandwidth saved using DFS Replication for this folder",
|
"Total bytes of bandwidth saved using DFS Replication for this folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.folderCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_compressed_size_of_received_files_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_compressed_size_of_received_files_bytes_total"),
|
||||||
"Total compressed size of files received on the folder, in bytes",
|
"Total compressed size of files received on the folder, in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderConflictBytesCleanedupTotal = prometheus.NewDesc(
|
c.folderConflictBytesCleanedupTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_cleaned_up_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_cleaned_up_bytes_total"),
|
||||||
"Total size of conflict loser files and folders deleted from the Conflict and Deleted folder, in bytes",
|
"Total size of conflict loser files and folders deleted from the Conflict and Deleted folder, in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderConflictBytesGeneratedTotal = prometheus.NewDesc(
|
c.folderConflictBytesGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_generated_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_generated_bytes_total"),
|
||||||
"Total size of conflict loser files and folders moved to the Conflict and Deleted folder, in bytes",
|
"Total size of conflict loser files and folders moved to the Conflict and Deleted folder, in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderConflictFilesCleanedUpTotal = prometheus.NewDesc(
|
c.folderConflictFilesCleanedUpTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_cleaned_up_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_cleaned_up_files_total"),
|
||||||
"Number of conflict loser files deleted from the Conflict and Deleted folder",
|
"Number of conflict loser files deleted from the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderConflictFilesGeneratedTotal = prometheus.NewDesc(
|
c.folderConflictFilesGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_generated_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_generated_files_total"),
|
||||||
"Number of files and folders moved to the Conflict and Deleted folder",
|
"Number of files and folders moved to the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderConflictFolderCleanupsCompletedTotal = prometheus.NewDesc(
|
c.folderConflictfolderCleanupsCompletedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_folder_cleanups_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_folder_cleanups_total"),
|
||||||
"Number of deletions of conflict loser files and folders in the Conflict and Deleted",
|
"Number of deletions of conflict loser files and folders in the Conflict and Deleted",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderConflictSpaceInUse = prometheus.NewDesc(
|
c.folderConflictSpaceInUse = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_space_in_use_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_conflict_space_in_use_bytes"),
|
||||||
"Total size of the conflict loser files and folders currently in the Conflict and Deleted folder",
|
"Total size of the conflict loser files and folders currently in the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderDeletedSpaceInUse = prometheus.NewDesc(
|
c.folderDeletedSpaceInUse = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_space_in_use_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_space_in_use_bytes"),
|
||||||
"Total size (in bytes) of the deleted files and folders currently in the Conflict and Deleted folder",
|
"Total size (in bytes) of the deleted files and folders currently in the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderDeletedBytesCleanedUpTotal = prometheus.NewDesc(
|
c.folderDeletedBytesCleanedUpTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_cleaned_up_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_cleaned_up_bytes_total"),
|
||||||
"Total size (in bytes) of replicating deleted files and folders that were cleaned up from the Conflict and Deleted folder",
|
"Total size (in bytes) of replicating deleted files and folders that were cleaned up from the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderDeletedBytesGeneratedTotal = prometheus.NewDesc(
|
c.folderDeletedBytesGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_generated_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_generated_bytes_total"),
|
||||||
"Total size (in bytes) of replicated deleted files and folders that were moved to the Conflict and Deleted folder after they were deleted from a replicated folder on a sending member",
|
"Total size (in bytes) of replicated deleted files and folders that were moved to the Conflict and Deleted folder after they were deleted from a replicated folder on a sending member",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderDeletedFilesCleanedUpTotal = prometheus.NewDesc(
|
c.folderDeletedFilesCleanedUpTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_cleaned_up_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_cleaned_up_files_total"),
|
||||||
"Number of files and folders that were cleaned up from the Conflict and Deleted folder",
|
"Number of files and folders that were cleaned up from the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderDeletedFilesGeneratedTotal = prometheus.NewDesc(
|
c.folderDeletedFilesGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_generated_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_deleted_generated_files_total"),
|
||||||
"Number of deleted files and folders that were moved to the Conflict and Deleted folder",
|
"Number of deleted files and folders that were moved to the Conflict and Deleted folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderFileInstallsRetriedTotal = prometheus.NewDesc(
|
c.folderFileInstallsRetriedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_file_installs_retried_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_file_installs_retried_total"),
|
||||||
"Total number of file installs that are being retried due to sharing violations or other errors encountered when installing the files",
|
"Total number of file installs that are being retried due to sharing violations or other errors encountered when installing the files",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderFileInstallsSucceededTotal = prometheus.NewDesc(
|
c.folderFileInstallsSucceededTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_file_installs_succeeded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_file_installs_succeeded_total"),
|
||||||
"Total number of files that were successfully received from sending members and installed locally on this server",
|
"Total number of files that were successfully received from sending members and installed locally on this server",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderFilesReceivedTotal = prometheus.NewDesc(
|
c.folderFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_received_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_received_files_total"),
|
||||||
"Total number of files received",
|
"Total number of files received",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderRDCBytesReceivedTotal = prometheus.NewDesc(
|
c.folderRDCBytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_received_bytes_total"),
|
||||||
"Total number of bytes received in replicating files using Remote Differential Compression",
|
"Total number of bytes received in replicating files using Remote Differential Compression",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderRDCCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.folderRDCCompressedSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_compressed_size_of_received_files_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_compressed_size_of_received_files_bytes_total"),
|
||||||
"Total compressed size (in bytes) of the files received with Remote Differential Compression",
|
"Total compressed size (in bytes) of the files received with Remote Differential Compression",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderRDCNumberofFilesReceivedTotal = prometheus.NewDesc(
|
c.folderRDCNumberofFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_received_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_received_files_total"),
|
||||||
"Total number of files received with Remote Differential Compression",
|
"Total number of files received with Remote Differential Compression",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderRDCSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.folderRDCSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_files_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_rdc_files_received_bytes_total"),
|
||||||
"Total uncompressed size (in bytes) of the files received with Remote Differential Compression",
|
"Total uncompressed size (in bytes) of the files received with Remote Differential Compression",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
c.folderSizeOfFilesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_files_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_files_received_bytes_total"),
|
||||||
"Total uncompressed size (in bytes) of the files received",
|
"Total uncompressed size (in bytes) of the files received",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderStagingSpaceInUse = prometheus.NewDesc(
|
c.folderStagingSpaceInUse = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_space_in_use_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_space_in_use_bytes"),
|
||||||
"Total size of files and folders currently in the staging folder.",
|
"Total size of files and folders currently in the staging folder.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderStagingBytesCleanedUpTotal = prometheus.NewDesc(
|
c.folderStagingBytesCleanedUpTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_cleaned_up_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_cleaned_up_bytes_total"),
|
||||||
"Total size (in bytes) of the files and folders that have been cleaned up from the staging folder",
|
"Total size (in bytes) of the files and folders that have been cleaned up from the staging folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderStagingBytesGeneratedTotal = prometheus.NewDesc(
|
c.folderStagingBytesGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_generated_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_generated_bytes_total"),
|
||||||
"Total size (in bytes) of replicated files and folders in the staging folder created by the DFS Replication service since last restart",
|
"Total size (in bytes) of replicated files and folders in the staging folder created by the DFS Replication service since last restart",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderStagingFilesCleanedUpTotal = prometheus.NewDesc(
|
c.folderStagingFilesCleanedUpTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_cleaned_up_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_cleaned_up_files_total"),
|
||||||
"Total number of files and folders that have been cleaned up from the staging folder",
|
"Total number of files and folders that have been cleaned up from the staging folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderStagingFilesGeneratedTotal = prometheus.NewDesc(
|
c.folderStagingFilesGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_generated_files_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_staging_generated_files_total"),
|
||||||
"Total number of times replicated files and folders have been staged by the DFS Replication service",
|
"Total number of times replicated files and folders have been staged by the DFS Replication service",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FolderUpdatesDroppedTotal = prometheus.NewDesc(
|
c.folderUpdatesDroppedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "folder_dropped_updates_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "folder_dropped_updates_total"),
|
||||||
"Total number of redundant file replication update records that have been ignored by the DFS Replication service because they did not change the replicated file or folder",
|
"Total number of redundant file replication update records that have been ignored by the DFS Replication service because they did not change the replicated file or folder",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c. // Volume
|
// volume
|
||||||
VolumeDatabaseCommitsTotal = prometheus.NewDesc(
|
c.volumeDatabaseCommitsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "volume_database_commits_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "volume_database_commits_total"),
|
||||||
"Total number of DFSR Volume database commits",
|
"Total number of DFSR volume database commits",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.VolumeDatabaseLookupsTotal = prometheus.NewDesc(
|
c.volumeDatabaseLookupsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "volume_database_lookups_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "volume_database_lookups_total"),
|
||||||
"Total number of DFSR Volume database lookups",
|
"Total number of DFSR volume database lookups",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.VolumeUSNJournalUnreadPercentage = prometheus.NewDesc(
|
c.volumeUSNJournalUnreadPercentage = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "volume_usn_journal_unread_percentage"),
|
prometheus.BuildFQName(types.Namespace, Name, "volume_usn_journal_unread_percentage"),
|
||||||
"Percentage of DFSR Volume USN journal records that are unread",
|
"Percentage of DFSR volume USN journal records that are unread",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.VolumeUSNJournalRecordsAcceptedTotal = prometheus.NewDesc(
|
c.volumeUSNJournalRecordsAcceptedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "volume_usn_journal_accepted_records_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "volume_usn_journal_accepted_records_total"),
|
||||||
"Total number of USN journal records accepted",
|
"Total number of USN journal records accepted",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.VolumeUSNJournalRecordsReadTotal = prometheus.NewDesc(
|
c.volumeUSNJournalRecordsReadTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "volume_usn_journal_read_records_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "volume_usn_journal_read_records_total"),
|
||||||
"Total number of DFSR Volume USN journal records read",
|
"Total number of DFSR volume USN journal records read",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.dfsrChildCollectors = c.getDFSRChildCollectors(utils.ExpandEnabledChildCollectors(*c.dfsrEnabledCollectors))
|
// Perflib sources are dynamic, depending on the enabled child collectors
|
||||||
|
expandedChildCollectors := slices.Compact(c.config.CollectorsEnabled)
|
||||||
|
c.dfsrChildCollectors = c.getDFSRChildCollectors(expandedChildCollectors)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maps enabled child collectors names to their relevant collection function,
|
// Maps enabled child collectors names to their relevant collection function,
|
||||||
// for use in collector.Collect()
|
// for use in Collector.Collect().
|
||||||
func (c *collector) getDFSRChildCollectors(enabledCollectors []string) []dfsrCollectorFunc {
|
func (c *Collector) getDFSRChildCollectors(enabledCollectors []string) []dfsrCollectorFunc {
|
||||||
var dfsrCollectors []dfsrCollectorFunc
|
var dfsrCollectors []dfsrCollectorFunc
|
||||||
for _, collector := range enabledCollectors {
|
for _, collector := range enabledCollectors {
|
||||||
switch collector {
|
switch collector {
|
||||||
@@ -457,7 +479,7 @@ func (c *collector) getDFSRChildCollectors(enabledCollectors []string) []dfsrCol
|
|||||||
|
|
||||||
// Collect implements the Collector interface.
|
// Collect implements the Collector interface.
|
||||||
// Sends metric values for each metric to the provided prometheus Metric channel.
|
// Sends metric values for each metric to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
for _, fn := range c.dfsrChildCollectors {
|
for _, fn := range c.dfsrChildCollectors {
|
||||||
err := fn(ctx, ch)
|
err := fn(ctx, ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -467,7 +489,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerflibDFSRConnection Perflib: "DFS Replication Service Connections"
|
// PerflibDFSRConnection Perflib: "DFS Replication Service Connections".
|
||||||
type PerflibDFSRConnection struct {
|
type PerflibDFSRConnection struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -482,7 +504,7 @@ type PerflibDFSRConnection struct {
|
|||||||
SizeOfFilesReceivedTotal float64 `perflib:"Size of Files Received"`
|
SizeOfFilesReceivedTotal float64 `perflib:"Size of Files Received"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectConnection(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectConnection(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []PerflibDFSRConnection
|
var dst []PerflibDFSRConnection
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["DFS Replication Connections"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["DFS Replication Connections"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -490,74 +512,73 @@ func (c *collector) collectConnection(ctx *types.ScrapeContext, ch chan<- promet
|
|||||||
|
|
||||||
for _, connection := range dst {
|
for _, connection := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionBandwidthSavingsUsingDFSReplicationTotal,
|
c.connectionBandwidthSavingsUsingDFSReplicationTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.BandwidthSavingsUsingDFSReplicationTotal,
|
connection.BandwidthSavingsUsingDFSReplicationTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionBytesReceivedTotal,
|
c.connectionBytesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.BytesReceivedTotal,
|
connection.BytesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionCompressedSizeOfFilesReceivedTotal,
|
c.connectionCompressedSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.CompressedSizeOfFilesReceivedTotal,
|
connection.CompressedSizeOfFilesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionFilesReceivedTotal,
|
c.connectionFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.FilesReceivedTotal,
|
connection.FilesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionRDCBytesReceivedTotal,
|
c.connectionRDCBytesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.RDCBytesReceivedTotal,
|
connection.RDCBytesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionRDCCompressedSizeOfFilesReceivedTotal,
|
c.connectionRDCCompressedSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.RDCCompressedSizeOfFilesReceivedTotal,
|
connection.RDCCompressedSizeOfFilesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionRDCSizeOfFilesReceivedTotal,
|
c.connectionRDCSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.RDCSizeOfFilesReceivedTotal,
|
connection.RDCSizeOfFilesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionRDCNumberofFilesReceivedTotal,
|
c.connectionRDCNumberofFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.RDCNumberofFilesReceivedTotal,
|
connection.RDCNumberofFilesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionSizeOfFilesReceivedTotal,
|
c.connectionSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
connection.SizeOfFilesReceivedTotal,
|
connection.SizeOfFilesReceivedTotal,
|
||||||
connection.Name,
|
connection.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerflibDFSRFolder Perflib: "DFS Replicated Folder"
|
// perflibDFSRFolder Perflib: "DFS Replicated Folder".
|
||||||
type PerflibDFSRFolder struct {
|
type perflibDFSRFolder struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
BandwidthSavingsUsingDFSReplicationTotal float64 `perflib:"Bandwidth Savings Using DFS Replication"`
|
BandwidthSavingsUsingDFSReplicationTotal float64 `perflib:"Bandwidth Savings Using DFS Replication"`
|
||||||
@@ -566,7 +587,7 @@ type PerflibDFSRFolder struct {
|
|||||||
ConflictBytesGeneratedTotal float64 `perflib:"Conflict Bytes Generated"`
|
ConflictBytesGeneratedTotal float64 `perflib:"Conflict Bytes Generated"`
|
||||||
ConflictFilesCleanedUpTotal float64 `perflib:"Conflict Files Cleaned Up"`
|
ConflictFilesCleanedUpTotal float64 `perflib:"Conflict Files Cleaned Up"`
|
||||||
ConflictFilesGeneratedTotal float64 `perflib:"Conflict Files Generated"`
|
ConflictFilesGeneratedTotal float64 `perflib:"Conflict Files Generated"`
|
||||||
ConflictFolderCleanupsCompletedTotal float64 `perflib:"Conflict Folder Cleanups Completed"`
|
ConflictFolderCleanupsCompletedTotal float64 `perflib:"Conflict folder Cleanups Completed"`
|
||||||
ConflictSpaceInUse float64 `perflib:"Conflict Space In Use"`
|
ConflictSpaceInUse float64 `perflib:"Conflict Space In Use"`
|
||||||
DeletedSpaceInUse float64 `perflib:"Deleted Space In Use"`
|
DeletedSpaceInUse float64 `perflib:"Deleted Space In Use"`
|
||||||
DeletedBytesCleanedUpTotal float64 `perflib:"Deleted Bytes Cleaned Up"`
|
DeletedBytesCleanedUpTotal float64 `perflib:"Deleted Bytes Cleaned Up"`
|
||||||
@@ -589,197 +610,197 @@ type PerflibDFSRFolder struct {
|
|||||||
UpdatesDroppedTotal float64 `perflib:"Updates Dropped"`
|
UpdatesDroppedTotal float64 `perflib:"Updates Dropped"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectFolder(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectFolder(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []PerflibDFSRFolder
|
var dst []perflibDFSRFolder
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["DFS Replicated Folders"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["DFS Replicated Folders"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, folder := range dst {
|
for _, folder := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderBandwidthSavingsUsingDFSReplicationTotal,
|
c.folderBandwidthSavingsUsingDFSReplicationTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.BandwidthSavingsUsingDFSReplicationTotal,
|
folder.BandwidthSavingsUsingDFSReplicationTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderCompressedSizeOfFilesReceivedTotal,
|
c.folderCompressedSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.CompressedSizeOfFilesReceivedTotal,
|
folder.CompressedSizeOfFilesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderConflictBytesCleanedupTotal,
|
c.folderConflictBytesCleanedupTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.ConflictBytesCleanedupTotal,
|
folder.ConflictBytesCleanedupTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderConflictBytesGeneratedTotal,
|
c.folderConflictBytesGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.ConflictBytesGeneratedTotal,
|
folder.ConflictBytesGeneratedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderConflictFilesCleanedUpTotal,
|
c.folderConflictFilesCleanedUpTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.ConflictFilesCleanedUpTotal,
|
folder.ConflictFilesCleanedUpTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderConflictFilesGeneratedTotal,
|
c.folderConflictFilesGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.ConflictFilesGeneratedTotal,
|
folder.ConflictFilesGeneratedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderConflictFolderCleanupsCompletedTotal,
|
c.folderConflictfolderCleanupsCompletedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.ConflictFolderCleanupsCompletedTotal,
|
folder.ConflictFolderCleanupsCompletedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderConflictSpaceInUse,
|
c.folderConflictSpaceInUse,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
folder.ConflictSpaceInUse,
|
folder.ConflictSpaceInUse,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderDeletedSpaceInUse,
|
c.folderDeletedSpaceInUse,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
folder.DeletedSpaceInUse,
|
folder.DeletedSpaceInUse,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderDeletedBytesCleanedUpTotal,
|
c.folderDeletedBytesCleanedUpTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.DeletedBytesCleanedUpTotal,
|
folder.DeletedBytesCleanedUpTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderDeletedBytesGeneratedTotal,
|
c.folderDeletedBytesGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.DeletedBytesGeneratedTotal,
|
folder.DeletedBytesGeneratedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderDeletedFilesCleanedUpTotal,
|
c.folderDeletedFilesCleanedUpTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.DeletedFilesCleanedUpTotal,
|
folder.DeletedFilesCleanedUpTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderDeletedFilesGeneratedTotal,
|
c.folderDeletedFilesGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.DeletedFilesGeneratedTotal,
|
folder.DeletedFilesGeneratedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderFileInstallsRetriedTotal,
|
c.folderFileInstallsRetriedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.FileInstallsRetriedTotal,
|
folder.FileInstallsRetriedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderFileInstallsSucceededTotal,
|
c.folderFileInstallsSucceededTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.FileInstallsSucceededTotal,
|
folder.FileInstallsSucceededTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderFilesReceivedTotal,
|
c.folderFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.FilesReceivedTotal,
|
folder.FilesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderRDCBytesReceivedTotal,
|
c.folderRDCBytesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.RDCBytesReceivedTotal,
|
folder.RDCBytesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderRDCCompressedSizeOfFilesReceivedTotal,
|
c.folderRDCCompressedSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.RDCCompressedSizeOfFilesReceivedTotal,
|
folder.RDCCompressedSizeOfFilesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderRDCNumberofFilesReceivedTotal,
|
c.folderRDCNumberofFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.RDCNumberofFilesReceivedTotal,
|
folder.RDCNumberofFilesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderRDCSizeOfFilesReceivedTotal,
|
c.folderRDCSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.RDCSizeOfFilesReceivedTotal,
|
folder.RDCSizeOfFilesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderSizeOfFilesReceivedTotal,
|
c.folderSizeOfFilesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.SizeOfFilesReceivedTotal,
|
folder.SizeOfFilesReceivedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderStagingSpaceInUse,
|
c.folderStagingSpaceInUse,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
folder.StagingSpaceInUse,
|
folder.StagingSpaceInUse,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderStagingBytesCleanedUpTotal,
|
c.folderStagingBytesCleanedUpTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.StagingBytesCleanedUpTotal,
|
folder.StagingBytesCleanedUpTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderStagingBytesGeneratedTotal,
|
c.folderStagingBytesGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.StagingBytesGeneratedTotal,
|
folder.StagingBytesGeneratedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderStagingFilesCleanedUpTotal,
|
c.folderStagingFilesCleanedUpTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.StagingFilesCleanedUpTotal,
|
folder.StagingFilesCleanedUpTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderStagingFilesGeneratedTotal,
|
c.folderStagingFilesGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.StagingFilesGeneratedTotal,
|
folder.StagingFilesGeneratedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FolderUpdatesDroppedTotal,
|
c.folderUpdatesDroppedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
folder.UpdatesDroppedTotal,
|
folder.UpdatesDroppedTotal,
|
||||||
folder.Name,
|
folder.Name,
|
||||||
@@ -788,8 +809,8 @@ func (c *collector) collectFolder(ctx *types.ScrapeContext, ch chan<- prometheus
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerflibDFSRVolume Perflib: "DFS Replication Service Volumes"
|
// perflibDFSRVolume Perflib: "DFS Replication Service Volumes".
|
||||||
type PerflibDFSRVolume struct {
|
type perflibDFSRVolume struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
DatabaseCommitsTotal float64 `perflib:"Database Commits"`
|
DatabaseCommitsTotal float64 `perflib:"Database Commits"`
|
||||||
@@ -799,48 +820,47 @@ type PerflibDFSRVolume struct {
|
|||||||
USNJournalUnreadPercentage float64 `perflib:"USN Journal Records Unread Percentage"`
|
USNJournalUnreadPercentage float64 `perflib:"USN Journal Records Unread Percentage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectVolume(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVolume(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []PerflibDFSRVolume
|
var dst []perflibDFSRVolume
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["DFS Replication Service Volumes"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["DFS Replication Service volumes"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, volume := range dst {
|
for _, volume := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VolumeDatabaseLookupsTotal,
|
c.volumeDatabaseLookupsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.DatabaseLookupsTotal,
|
volume.DatabaseLookupsTotal,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VolumeDatabaseCommitsTotal,
|
c.volumeDatabaseCommitsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.DatabaseCommitsTotal,
|
volume.DatabaseCommitsTotal,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VolumeUSNJournalRecordsAcceptedTotal,
|
c.volumeUSNJournalRecordsAcceptedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.USNJournalRecordsAcceptedTotal,
|
volume.USNJournalRecordsAcceptedTotal,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VolumeUSNJournalRecordsReadTotal,
|
c.volumeUSNJournalRecordsReadTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.USNJournalRecordsReadTotal,
|
volume.USNJournalRecordsReadTotal,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VolumeUSNJournalUnreadPercentage,
|
c.volumeUSNJournalUnreadPercentage,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
volume.USNJournalUnreadPercentage,
|
volume.USNJournalUnreadPercentage,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,205 +16,218 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector perflib DHCP metrics
|
// A Collector is a Prometheus Collector perflib DHCP metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
PacketsReceivedTotal *prometheus.Desc
|
acksTotal *prometheus.Desc
|
||||||
DuplicatesDroppedTotal *prometheus.Desc
|
activeQueueLength *prometheus.Desc
|
||||||
PacketsExpiredTotal *prometheus.Desc
|
conflictCheckQueueLength *prometheus.Desc
|
||||||
ActiveQueueLength *prometheus.Desc
|
declinesTotal *prometheus.Desc
|
||||||
ConflictCheckQueueLength *prometheus.Desc
|
deniedDueToMatch *prometheus.Desc
|
||||||
DiscoversTotal *prometheus.Desc
|
deniedDueToNonMatch *prometheus.Desc
|
||||||
OffersTotal *prometheus.Desc
|
discoversTotal *prometheus.Desc
|
||||||
RequestsTotal *prometheus.Desc
|
duplicatesDroppedTotal *prometheus.Desc
|
||||||
InformsTotal *prometheus.Desc
|
failoverBndackReceivedTotal *prometheus.Desc
|
||||||
AcksTotal *prometheus.Desc
|
failoverBndackSentTotal *prometheus.Desc
|
||||||
NacksTotal *prometheus.Desc
|
failoverBndupdDropped *prometheus.Desc
|
||||||
DeclinesTotal *prometheus.Desc
|
failoverBndupdPendingOutboundQueue *prometheus.Desc
|
||||||
ReleasesTotal *prometheus.Desc
|
failoverBndupdReceivedTotal *prometheus.Desc
|
||||||
OfferQueueLength *prometheus.Desc
|
failoverBndupdSentTotal *prometheus.Desc
|
||||||
DeniedDueToMatch *prometheus.Desc
|
failoverTransitionsCommunicationInterruptedState *prometheus.Desc
|
||||||
DeniedDueToNonMatch *prometheus.Desc
|
failoverTransitionsPartnerDownState *prometheus.Desc
|
||||||
FailoverBndupdSentTotal *prometheus.Desc
|
failoverTransitionsRecoverState *prometheus.Desc
|
||||||
FailoverBndupdReceivedTotal *prometheus.Desc
|
informsTotal *prometheus.Desc
|
||||||
FailoverBndackSentTotal *prometheus.Desc
|
nACKsTotal *prometheus.Desc
|
||||||
FailoverBndackReceivedTotal *prometheus.Desc
|
offerQueueLength *prometheus.Desc
|
||||||
FailoverBndupdPendingOutboundQueue *prometheus.Desc
|
offersTotal *prometheus.Desc
|
||||||
FailoverTransitionsCommunicationinterruptedState *prometheus.Desc
|
packetsExpiredTotal *prometheus.Desc
|
||||||
FailoverTransitionsPartnerdownState *prometheus.Desc
|
packetsReceivedTotal *prometheus.Desc
|
||||||
FailoverTransitionsRecoverState *prometheus.Desc
|
releasesTotal *prometheus.Desc
|
||||||
FailoverBndupdDropped *prometheus.Desc
|
requestsTotal *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"DHCP Server"}, nil
|
return []string{"DHCP Server"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.PacketsReceivedTotal = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.packetsReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
||||||
"Total number of packets received by the DHCP server (PacketsReceivedTotal)",
|
"Total number of packets received by the DHCP server (PacketsReceivedTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DuplicatesDroppedTotal = prometheus.NewDesc(
|
c.duplicatesDroppedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "duplicates_dropped_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "duplicates_dropped_total"),
|
||||||
"Total number of duplicate packets received by the DHCP server (DuplicatesDroppedTotal)",
|
"Total number of duplicate packets received by the DHCP server (DuplicatesDroppedTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsExpiredTotal = prometheus.NewDesc(
|
c.packetsExpiredTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_expired_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_expired_total"),
|
||||||
"Total number of packets expired in the DHCP server message queue (PacketsExpiredTotal)",
|
"Total number of packets expired in the DHCP server message queue (PacketsExpiredTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ActiveQueueLength = prometheus.NewDesc(
|
c.activeQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "active_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "active_queue_length"),
|
||||||
"Number of packets in the processing queue of the DHCP server (ActiveQueueLength)",
|
"Number of packets in the processing queue of the DHCP server (ActiveQueueLength)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConflictCheckQueueLength = prometheus.NewDesc(
|
c.conflictCheckQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "conflict_check_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "conflict_check_queue_length"),
|
||||||
"Number of packets in the DHCP server queue waiting on conflict detection (ping). (ConflictCheckQueueLength)",
|
"Number of packets in the DHCP server queue waiting on conflict detection (ping). (ConflictCheckQueueLength)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DiscoversTotal = prometheus.NewDesc(
|
c.discoversTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "discovers_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "discovers_total"),
|
||||||
"Total DHCP Discovers received by the DHCP server (DiscoversTotal)",
|
"Total DHCP Discovers received by the DHCP server (DiscoversTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OffersTotal = prometheus.NewDesc(
|
c.offersTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "offers_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "offers_total"),
|
||||||
"Total DHCP Offers sent by the DHCP server (OffersTotal)",
|
"Total DHCP Offers sent by the DHCP server (OffersTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RequestsTotal = prometheus.NewDesc(
|
c.requestsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
||||||
"Total DHCP Requests received by the DHCP server (RequestsTotal)",
|
"Total DHCP Requests received by the DHCP server (RequestsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.InformsTotal = prometheus.NewDesc(
|
c.informsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "informs_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "informs_total"),
|
||||||
"Total DHCP Informs received by the DHCP server (InformsTotal)",
|
"Total DHCP Informs received by the DHCP server (InformsTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AcksTotal = prometheus.NewDesc(
|
c.acksTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "acks_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "acks_total"),
|
||||||
"Total DHCP Acks sent by the DHCP server (AcksTotal)",
|
"Total DHCP Acks sent by the DHCP server (AcksTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NacksTotal = prometheus.NewDesc(
|
c.nACKsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "nacks_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "nacks_total"),
|
||||||
"Total DHCP Nacks sent by the DHCP server (NacksTotal)",
|
"Total DHCP Nacks sent by the DHCP server (NacksTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DeclinesTotal = prometheus.NewDesc(
|
c.declinesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "declines_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "declines_total"),
|
||||||
"Total DHCP Declines received by the DHCP server (DeclinesTotal)",
|
"Total DHCP Declines received by the DHCP server (DeclinesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ReleasesTotal = prometheus.NewDesc(
|
c.releasesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "releases_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "releases_total"),
|
||||||
"Total DHCP Releases received by the DHCP server (ReleasesTotal)",
|
"Total DHCP Releases received by the DHCP server (ReleasesTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OfferQueueLength = prometheus.NewDesc(
|
c.offerQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "offer_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "offer_queue_length"),
|
||||||
"Number of packets in the offer queue of the DHCP server (OfferQueueLength)",
|
"Number of packets in the offer queue of the DHCP server (OfferQueueLength)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DeniedDueToMatch = prometheus.NewDesc(
|
c.deniedDueToMatch = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "denied_due_to_match_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "denied_due_to_match_total"),
|
||||||
"Total number of DHCP requests denied, based on matches from the Deny list (DeniedDueToMatch)",
|
"Total number of DHCP requests denied, based on matches from the Deny list (DeniedDueToMatch)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DeniedDueToNonMatch = prometheus.NewDesc(
|
c.deniedDueToNonMatch = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "denied_due_to_nonmatch_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "denied_due_to_nonmatch_total"),
|
||||||
"Total number of DHCP requests denied, based on non-matches from the Allow list (DeniedDueToNonMatch)",
|
"Total number of DHCP requests denied, based on non-matches from the Allow list (DeniedDueToNonMatch)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverBndupdSentTotal = prometheus.NewDesc(
|
c.failoverBndupdSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_sent_total"),
|
||||||
"Number of DHCP fail over Binding Update messages sent (FailoverBndupdSentTotal)",
|
"Number of DHCP fail over Binding Update messages sent (FailoverBndupdSentTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverBndupdReceivedTotal = prometheus.NewDesc(
|
c.failoverBndupdReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_received_total"),
|
||||||
"Number of DHCP fail over Binding Update messages received (FailoverBndupdReceivedTotal)",
|
"Number of DHCP fail over Binding Update messages received (FailoverBndupdReceivedTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverBndackSentTotal = prometheus.NewDesc(
|
c.failoverBndackSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_bndack_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_bndack_sent_total"),
|
||||||
"Number of DHCP fail over Binding Ack messages sent (FailoverBndackSentTotal)",
|
"Number of DHCP fail over Binding Ack messages sent (FailoverBndackSentTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverBndackReceivedTotal = prometheus.NewDesc(
|
c.failoverBndackReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_bndack_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_bndack_received_total"),
|
||||||
"Number of DHCP fail over Binding Ack messages received (FailoverBndackReceivedTotal)",
|
"Number of DHCP fail over Binding Ack messages received (FailoverBndackReceivedTotal)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverBndupdPendingOutboundQueue = prometheus.NewDesc(
|
c.failoverBndupdPendingOutboundQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_pending_in_outbound_queue"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_pending_in_outbound_queue"),
|
||||||
"Number of pending outbound DHCP fail over Binding Update messages (FailoverBndupdPendingOutboundQueue)",
|
"Number of pending outbound DHCP fail over Binding Update messages (FailoverBndupdPendingOutboundQueue)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverTransitionsCommunicationinterruptedState = prometheus.NewDesc(
|
c.failoverTransitionsCommunicationInterruptedState = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_transitions_communicationinterrupted_state_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_transitions_communicationinterrupted_state_total"),
|
||||||
"Total number of transitions into COMMUNICATION INTERRUPTED state (FailoverTransitionsCommunicationinterruptedState)",
|
"Total number of transitions into COMMUNICATION INTERRUPTED state (FailoverTransitionsCommunicationinterruptedState)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverTransitionsPartnerdownState = prometheus.NewDesc(
|
c.failoverTransitionsPartnerDownState = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_transitions_partnerdown_state_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_transitions_partnerdown_state_total"),
|
||||||
"Total number of transitions into PARTNER DOWN state (FailoverTransitionsPartnerdownState)",
|
"Total number of transitions into PARTNER DOWN state (FailoverTransitionsPartnerdownState)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverTransitionsRecoverState = prometheus.NewDesc(
|
c.failoverTransitionsRecoverState = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_transitions_recover_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_transitions_recover_total"),
|
||||||
"Total number of transitions into RECOVER state (FailoverTransitionsRecoverState)",
|
"Total number of transitions into RECOVER state (FailoverTransitionsRecoverState)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverBndupdDropped = prometheus.NewDesc(
|
c.failoverBndupdDropped = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_dropped_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_bndupd_dropped_total"),
|
||||||
"Total number of DHCP fail over Binding Updates dropped (FailoverBndupdDropped)",
|
"Total number of DHCP fail over Binding Updates dropped (FailoverBndupdDropped)",
|
||||||
nil,
|
nil,
|
||||||
@@ -254,158 +267,158 @@ type dhcpPerf struct {
|
|||||||
FailoverBndupdDropped float64 `perflib:"Failover: BndUpd Dropped."`
|
FailoverBndupdDropped float64 `perflib:"Failover: BndUpd Dropped."`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dhcpPerfs []dhcpPerf
|
var dhcpPerfs []dhcpPerf
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["DHCP Server"], &dhcpPerfs, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["DHCP Server"], &dhcpPerfs, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceivedTotal,
|
c.packetsReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].PacketsReceivedTotal,
|
dhcpPerfs[0].PacketsReceivedTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DuplicatesDroppedTotal,
|
c.duplicatesDroppedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].DuplicatesDroppedTotal,
|
dhcpPerfs[0].DuplicatesDroppedTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsExpiredTotal,
|
c.packetsExpiredTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].PacketsExpiredTotal,
|
dhcpPerfs[0].PacketsExpiredTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ActiveQueueLength,
|
c.activeQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dhcpPerfs[0].ActiveQueueLength,
|
dhcpPerfs[0].ActiveQueueLength,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConflictCheckQueueLength,
|
c.conflictCheckQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dhcpPerfs[0].ConflictCheckQueueLength,
|
dhcpPerfs[0].ConflictCheckQueueLength,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DiscoversTotal,
|
c.discoversTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].DiscoversTotal,
|
dhcpPerfs[0].DiscoversTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OffersTotal,
|
c.offersTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].OffersTotal,
|
dhcpPerfs[0].OffersTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestsTotal,
|
c.requestsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].RequestsTotal,
|
dhcpPerfs[0].RequestsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InformsTotal,
|
c.informsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].InformsTotal,
|
dhcpPerfs[0].InformsTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AcksTotal,
|
c.acksTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].AcksTotal,
|
dhcpPerfs[0].AcksTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NacksTotal,
|
c.nACKsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].NacksTotal,
|
dhcpPerfs[0].NacksTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DeclinesTotal,
|
c.declinesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].DeclinesTotal,
|
dhcpPerfs[0].DeclinesTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReleasesTotal,
|
c.releasesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].ReleasesTotal,
|
dhcpPerfs[0].ReleasesTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OfferQueueLength,
|
c.offerQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dhcpPerfs[0].OfferQueueLength,
|
dhcpPerfs[0].OfferQueueLength,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DeniedDueToMatch,
|
c.deniedDueToMatch,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].DeniedDueToMatch,
|
dhcpPerfs[0].DeniedDueToMatch,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DeniedDueToNonMatch,
|
c.deniedDueToNonMatch,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].DeniedDueToNonMatch,
|
dhcpPerfs[0].DeniedDueToNonMatch,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverBndupdSentTotal,
|
c.failoverBndupdSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverBndupdSentTotal,
|
dhcpPerfs[0].FailoverBndupdSentTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverBndupdReceivedTotal,
|
c.failoverBndupdReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverBndupdReceivedTotal,
|
dhcpPerfs[0].FailoverBndupdReceivedTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverBndackSentTotal,
|
c.failoverBndackSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverBndackSentTotal,
|
dhcpPerfs[0].FailoverBndackSentTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverBndackReceivedTotal,
|
c.failoverBndackReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverBndackReceivedTotal,
|
dhcpPerfs[0].FailoverBndackReceivedTotal,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverBndupdPendingOutboundQueue,
|
c.failoverBndupdPendingOutboundQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dhcpPerfs[0].FailoverBndupdPendingOutboundQueue,
|
dhcpPerfs[0].FailoverBndupdPendingOutboundQueue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverTransitionsCommunicationinterruptedState,
|
c.failoverTransitionsCommunicationInterruptedState,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverTransitionsCommunicationinterruptedState,
|
dhcpPerfs[0].FailoverTransitionsCommunicationinterruptedState,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverTransitionsPartnerdownState,
|
c.failoverTransitionsPartnerDownState,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverTransitionsPartnerdownState,
|
dhcpPerfs[0].FailoverTransitionsPartnerdownState,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverTransitionsRecoverState,
|
c.failoverTransitionsRecoverState,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverTransitionsRecoverState,
|
dhcpPerfs[0].FailoverTransitionsRecoverState,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverBndupdDropped,
|
c.failoverBndupdDropped,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dhcpPerfs[0].FailoverBndupdDropped,
|
dhcpPerfs[0].FailoverBndupdDropped,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,41 +23,54 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for a few WMI metrics in Win32_DiskDrive
|
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_DiskDrive.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
DiskInfo *prometheus.Desc
|
availability *prometheus.Desc
|
||||||
Status *prometheus.Desc
|
diskInfo *prometheus.Desc
|
||||||
Size *prometheus.Desc
|
partitions *prometheus.Desc
|
||||||
Partitions *prometheus.Desc
|
size *prometheus.Desc
|
||||||
Availability *prometheus.Desc
|
status *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.DiskInfo = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.diskInfo = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||||
"General drive information",
|
"General drive information",
|
||||||
[]string{
|
[]string{
|
||||||
@@ -68,25 +81,25 @@ func (c *collector) Build() error {
|
|||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Status = prometheus.NewDesc(
|
c.status = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
||||||
"Status of the drive",
|
"Status of the drive",
|
||||||
[]string{"name", "status"},
|
[]string{"name", "status"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Size = prometheus.NewDesc(
|
c.size = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "size"),
|
prometheus.BuildFQName(types.Namespace, Name, "size"),
|
||||||
"Size of the disk drive. It is calculated by multiplying the total number of cylinders, tracks in each cylinder, sectors in each track, and bytes in each sector.",
|
"Size of the disk drive. It is calculated by multiplying the total number of cylinders, tracks in each cylinder, sectors in each track, and bytes in each sector.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Partitions = prometheus.NewDesc(
|
c.partitions = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "partitions"),
|
prometheus.BuildFQName(types.Namespace, Name, "partitions"),
|
||||||
"Number of partitions",
|
"Number of partitions",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Availability = prometheus.NewDesc(
|
c.availability = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "availability"),
|
prometheus.BuildFQName(types.Namespace, Name, "availability"),
|
||||||
"Availability Status",
|
"Availability Status",
|
||||||
[]string{"name", "availability"},
|
[]string{"name", "availability"},
|
||||||
@@ -96,7 +109,7 @@ func (c *collector) Build() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Win32_DiskDrive struct {
|
type win32_DiskDrive struct {
|
||||||
DeviceID string
|
DeviceID string
|
||||||
Model string
|
Model string
|
||||||
Size uint64
|
Size uint64
|
||||||
@@ -149,7 +162,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Collect sends the metric values for each metric to the provided prometheus Metric channel.
|
// Collect sends the metric values for each metric to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting disk_drive_info metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting disk_drive_info metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -157,8 +170,8 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_DiskDrive
|
var dst []win32_DiskDrive
|
||||||
|
|
||||||
if err := wmi.Query(win32DiskQuery, &dst); err != nil {
|
if err := wmi.Query(win32DiskQuery, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -169,13 +182,13 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
|
|
||||||
for _, disk := range dst {
|
for _, disk := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DiskInfo,
|
c.diskInfo,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1.0,
|
1.0,
|
||||||
strings.Trim(disk.DeviceID, "\\.\\"),
|
strings.Trim(disk.DeviceID, "\\.\\"), //nolint:staticcheck
|
||||||
strings.TrimRight(disk.Model, " "),
|
strings.TrimRight(disk.Model, " "),
|
||||||
strings.TrimRight(disk.Caption, " "),
|
strings.TrimRight(disk.Caption, " "),
|
||||||
strings.TrimRight(disk.Name, "\\.\\"),
|
strings.TrimRight(disk.Name, "\\.\\"), //nolint:staticcheck
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, status := range allDiskStatus {
|
for _, status := range allDiskStatus {
|
||||||
@@ -185,26 +198,26 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Status,
|
c.status,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
isCurrentState,
|
isCurrentState,
|
||||||
strings.Trim(disk.Name, "\\.\\"),
|
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
|
||||||
status,
|
status,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Size,
|
c.size,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(disk.Size),
|
float64(disk.Size),
|
||||||
strings.Trim(disk.Name, "\\.\\"),
|
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Partitions,
|
c.partitions,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(disk.Partitions),
|
float64(disk.Partitions),
|
||||||
strings.Trim(disk.Name, "\\.\\"),
|
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
|
||||||
)
|
)
|
||||||
|
|
||||||
for availNum, val := range availMap {
|
for availNum, val := range availMap {
|
||||||
@@ -213,10 +226,10 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
isCurrentState = 1.0
|
isCurrentState = 1.0
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Availability,
|
c.availability,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
isCurrentState,
|
isCurrentState,
|
||||||
strings.Trim(disk.Name, "\\.\\"),
|
strings.Trim(disk.Name, "\\.\\"), //nolint:staticcheck
|
||||||
val,
|
val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,184 +19,197 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_DNS_DNS metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
ZoneTransferRequestsReceived *prometheus.Desc
|
dynamicUpdatesFailures *prometheus.Desc
|
||||||
ZoneTransferRequestsSent *prometheus.Desc
|
dynamicUpdatesQueued *prometheus.Desc
|
||||||
ZoneTransferResponsesReceived *prometheus.Desc
|
dynamicUpdatesReceived *prometheus.Desc
|
||||||
ZoneTransferSuccessReceived *prometheus.Desc
|
memoryUsedBytes *prometheus.Desc
|
||||||
ZoneTransferSuccessSent *prometheus.Desc
|
notifyReceived *prometheus.Desc
|
||||||
ZoneTransferFailures *prometheus.Desc
|
notifySent *prometheus.Desc
|
||||||
MemoryUsedBytes *prometheus.Desc
|
queries *prometheus.Desc
|
||||||
DynamicUpdatesQueued *prometheus.Desc
|
recursiveQueries *prometheus.Desc
|
||||||
DynamicUpdatesReceived *prometheus.Desc
|
recursiveQueryFailures *prometheus.Desc
|
||||||
DynamicUpdatesFailures *prometheus.Desc
|
recursiveQuerySendTimeouts *prometheus.Desc
|
||||||
NotifyReceived *prometheus.Desc
|
responses *prometheus.Desc
|
||||||
NotifySent *prometheus.Desc
|
secureUpdateFailures *prometheus.Desc
|
||||||
SecureUpdateFailures *prometheus.Desc
|
secureUpdateReceived *prometheus.Desc
|
||||||
SecureUpdateReceived *prometheus.Desc
|
unmatchedResponsesReceived *prometheus.Desc
|
||||||
Queries *prometheus.Desc
|
winsQueries *prometheus.Desc
|
||||||
Responses *prometheus.Desc
|
winsResponses *prometheus.Desc
|
||||||
RecursiveQueries *prometheus.Desc
|
zoneTransferFailures *prometheus.Desc
|
||||||
RecursiveQueryFailures *prometheus.Desc
|
zoneTransferRequestsReceived *prometheus.Desc
|
||||||
RecursiveQuerySendTimeouts *prometheus.Desc
|
zoneTransferRequestsSent *prometheus.Desc
|
||||||
WinsQueries *prometheus.Desc
|
zoneTransferResponsesReceived *prometheus.Desc
|
||||||
WinsResponses *prometheus.Desc
|
zoneTransferSuccessReceived *prometheus.Desc
|
||||||
UnmatchedResponsesReceived *prometheus.Desc
|
zoneTransferSuccessSent *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.ZoneTransferRequestsReceived = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.zoneTransferRequestsReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_requests_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_requests_received_total"),
|
||||||
"Number of zone transfer requests (AXFR/IXFR) received by the master DNS server",
|
"Number of zone transfer requests (AXFR/IXFR) received by the master DNS server",
|
||||||
[]string{"qtype"},
|
[]string{"qtype"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ZoneTransferRequestsSent = prometheus.NewDesc(
|
c.zoneTransferRequestsSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_requests_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_requests_sent_total"),
|
||||||
"Number of zone transfer requests (AXFR/IXFR) sent by the secondary DNS server",
|
"Number of zone transfer requests (AXFR/IXFR) sent by the secondary DNS server",
|
||||||
[]string{"qtype"},
|
[]string{"qtype"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ZoneTransferResponsesReceived = prometheus.NewDesc(
|
c.zoneTransferResponsesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_response_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_response_received_total"),
|
||||||
"Number of zone transfer responses (AXFR/IXFR) received by the secondary DNS server",
|
"Number of zone transfer responses (AXFR/IXFR) received by the secondary DNS server",
|
||||||
[]string{"qtype"},
|
[]string{"qtype"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ZoneTransferSuccessReceived = prometheus.NewDesc(
|
c.zoneTransferSuccessReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_success_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_success_received_total"),
|
||||||
"Number of successful zone transfers (AXFR/IXFR) received by the secondary DNS server",
|
"Number of successful zone transfers (AXFR/IXFR) received by the secondary DNS server",
|
||||||
[]string{"qtype", "protocol"},
|
[]string{"qtype", "protocol"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ZoneTransferSuccessSent = prometheus.NewDesc(
|
c.zoneTransferSuccessSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_success_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_success_sent_total"),
|
||||||
"Number of successful zone transfers (AXFR/IXFR) of the master DNS server",
|
"Number of successful zone transfers (AXFR/IXFR) of the master DNS server",
|
||||||
[]string{"qtype"},
|
[]string{"qtype"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ZoneTransferFailures = prometheus.NewDesc(
|
c.zoneTransferFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_failures_total"),
|
||||||
"Number of failed zone transfers of the master DNS server",
|
"Number of failed zone transfers of the master DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemoryUsedBytes = prometheus.NewDesc(
|
c.memoryUsedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "memory_used_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "memory_used_bytes"),
|
||||||
"Current memory used by DNS server",
|
"Current memory used by DNS server",
|
||||||
[]string{"area"},
|
[]string{"area"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DynamicUpdatesQueued = prometheus.NewDesc(
|
c.dynamicUpdatesQueued = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dynamic_updates_queued"),
|
prometheus.BuildFQName(types.Namespace, Name, "dynamic_updates_queued"),
|
||||||
"Number of dynamic updates queued by the DNS server",
|
"Number of dynamic updates queued by the DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DynamicUpdatesReceived = prometheus.NewDesc(
|
c.dynamicUpdatesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dynamic_updates_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "dynamic_updates_received_total"),
|
||||||
"Number of secure update requests received by the DNS server",
|
"Number of secure update requests received by the DNS server",
|
||||||
[]string{"operation"},
|
[]string{"operation"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DynamicUpdatesFailures = prometheus.NewDesc(
|
c.dynamicUpdatesFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dynamic_updates_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "dynamic_updates_failures_total"),
|
||||||
"Number of dynamic updates which timed out or were rejected by the DNS server",
|
"Number of dynamic updates which timed out or were rejected by the DNS server",
|
||||||
[]string{"reason"},
|
[]string{"reason"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NotifyReceived = prometheus.NewDesc(
|
c.notifyReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "notify_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "notify_received_total"),
|
||||||
"Number of notifies received by the secondary DNS server",
|
"Number of notifies received by the secondary DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NotifySent = prometheus.NewDesc(
|
c.notifySent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "notify_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "notify_sent_total"),
|
||||||
"Number of notifies sent by the master DNS server",
|
"Number of notifies sent by the master DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SecureUpdateFailures = prometheus.NewDesc(
|
c.secureUpdateFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "secure_update_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "secure_update_failures_total"),
|
||||||
"Number of secure updates that failed on the DNS server",
|
"Number of secure updates that failed on the DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SecureUpdateReceived = prometheus.NewDesc(
|
c.secureUpdateReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "secure_update_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "secure_update_received_total"),
|
||||||
"Number of secure update requests received by the DNS server",
|
"Number of secure update requests received by the DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Queries = prometheus.NewDesc(
|
c.queries = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "queries_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "queries_total"),
|
||||||
"Number of queries received by DNS server",
|
"Number of queries received by DNS server",
|
||||||
[]string{"protocol"},
|
[]string{"protocol"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Responses = prometheus.NewDesc(
|
c.responses = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "responses_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "responses_total"),
|
||||||
"Number of responses sent by DNS server",
|
"Number of responses sent by DNS server",
|
||||||
[]string{"protocol"},
|
[]string{"protocol"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RecursiveQueries = prometheus.NewDesc(
|
c.recursiveQueries = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "recursive_queries_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "recursive_queries_total"),
|
||||||
"Number of recursive queries received by DNS server",
|
"Number of recursive queries received by DNS server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RecursiveQueryFailures = prometheus.NewDesc(
|
c.recursiveQueryFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "recursive_query_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "recursive_query_failures_total"),
|
||||||
"Number of recursive query failures",
|
"Number of recursive query failures",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RecursiveQuerySendTimeouts = prometheus.NewDesc(
|
c.recursiveQuerySendTimeouts = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "recursive_query_send_timeouts_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "recursive_query_send_timeouts_total"),
|
||||||
"Number of recursive query sending timeouts",
|
"Number of recursive query sending timeouts",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WinsQueries = prometheus.NewDesc(
|
c.winsQueries = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "wins_queries_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "wins_queries_total"),
|
||||||
"Number of WINS lookup requests received by the server",
|
"Number of WINS lookup requests received by the server",
|
||||||
[]string{"direction"},
|
[]string{"direction"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WinsResponses = prometheus.NewDesc(
|
c.winsResponses = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "wins_responses_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "wins_responses_total"),
|
||||||
"Number of WINS lookup responses sent by the server",
|
"Number of WINS lookup responses sent by the server",
|
||||||
[]string{"direction"},
|
[]string{"direction"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.UnmatchedResponsesReceived = prometheus.NewDesc(
|
c.unmatchedResponsesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "unmatched_responses_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "unmatched_responses_total"),
|
||||||
"Number of response packets received by the DNS server that do not match any outstanding remote query",
|
"Number of response packets received by the DNS server that do not match any outstanding remote query",
|
||||||
nil,
|
nil,
|
||||||
@@ -207,7 +220,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting dns metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting dns metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -261,7 +274,7 @@ type Win32_PerfRawData_DNS_DNS struct {
|
|||||||
ZoneTransferSOARequestSent uint32
|
ZoneTransferSOARequestSent uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_DNS_DNS
|
var dst []Win32_PerfRawData_DNS_DNS
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -272,66 +285,66 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferRequestsReceived,
|
c.zoneTransferRequestsReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AXFRRequestReceived),
|
float64(dst[0].AXFRRequestReceived),
|
||||||
"full",
|
"full",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferRequestsReceived,
|
c.zoneTransferRequestsReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].IXFRRequestReceived),
|
float64(dst[0].IXFRRequestReceived),
|
||||||
"incremental",
|
"incremental",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferRequestsSent,
|
c.zoneTransferRequestsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AXFRRequestSent),
|
float64(dst[0].AXFRRequestSent),
|
||||||
"full",
|
"full",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferRequestsSent,
|
c.zoneTransferRequestsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].IXFRRequestSent),
|
float64(dst[0].IXFRRequestSent),
|
||||||
"incremental",
|
"incremental",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferRequestsSent,
|
c.zoneTransferRequestsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ZoneTransferSOARequestSent),
|
float64(dst[0].ZoneTransferSOARequestSent),
|
||||||
"soa",
|
"soa",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferResponsesReceived,
|
c.zoneTransferResponsesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AXFRResponseReceived),
|
float64(dst[0].AXFRResponseReceived),
|
||||||
"full",
|
"full",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferResponsesReceived,
|
c.zoneTransferResponsesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].IXFRResponseReceived),
|
float64(dst[0].IXFRResponseReceived),
|
||||||
"incremental",
|
"incremental",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferSuccessReceived,
|
c.zoneTransferSuccessReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AXFRSuccessReceived),
|
float64(dst[0].AXFRSuccessReceived),
|
||||||
"full",
|
"full",
|
||||||
"tcp",
|
"tcp",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferSuccessReceived,
|
c.zoneTransferSuccessReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].IXFRTCPSuccessReceived),
|
float64(dst[0].IXFRTCPSuccessReceived),
|
||||||
"incremental",
|
"incremental",
|
||||||
"tcp",
|
"tcp",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferSuccessReceived,
|
c.zoneTransferSuccessReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].IXFRTCPSuccessReceived),
|
float64(dst[0].IXFRTCPSuccessReceived),
|
||||||
"incremental",
|
"incremental",
|
||||||
@@ -339,183 +352,183 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferSuccessSent,
|
c.zoneTransferSuccessSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AXFRSuccessSent),
|
float64(dst[0].AXFRSuccessSent),
|
||||||
"full",
|
"full",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferSuccessSent,
|
c.zoneTransferSuccessSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].IXFRSuccessSent),
|
float64(dst[0].IXFRSuccessSent),
|
||||||
"incremental",
|
"incremental",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ZoneTransferFailures,
|
c.zoneTransferFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ZoneTransferFailure),
|
float64(dst[0].ZoneTransferFailure),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemoryUsedBytes,
|
c.memoryUsedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].CachingMemory),
|
float64(dst[0].CachingMemory),
|
||||||
"caching",
|
"caching",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemoryUsedBytes,
|
c.memoryUsedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].DatabaseNodeMemory),
|
float64(dst[0].DatabaseNodeMemory),
|
||||||
"database_node",
|
"database_node",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemoryUsedBytes,
|
c.memoryUsedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].NbstatMemory),
|
float64(dst[0].NbstatMemory),
|
||||||
"nbstat",
|
"nbstat",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemoryUsedBytes,
|
c.memoryUsedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].RecordFlowMemory),
|
float64(dst[0].RecordFlowMemory),
|
||||||
"record_flow",
|
"record_flow",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemoryUsedBytes,
|
c.memoryUsedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TCPMessageMemory),
|
float64(dst[0].TCPMessageMemory),
|
||||||
"tcp_message",
|
"tcp_message",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemoryUsedBytes,
|
c.memoryUsedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].UDPMessageMemory),
|
float64(dst[0].UDPMessageMemory),
|
||||||
"udp_message",
|
"udp_message",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DynamicUpdatesReceived,
|
c.dynamicUpdatesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].DynamicUpdateNoOperation),
|
float64(dst[0].DynamicUpdateNoOperation),
|
||||||
"noop",
|
"noop",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DynamicUpdatesReceived,
|
c.dynamicUpdatesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].DynamicUpdateWrittentoDatabase),
|
float64(dst[0].DynamicUpdateWrittentoDatabase),
|
||||||
"written",
|
"written",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DynamicUpdatesQueued,
|
c.dynamicUpdatesQueued,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].DynamicUpdateQueued),
|
float64(dst[0].DynamicUpdateQueued),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DynamicUpdatesFailures,
|
c.dynamicUpdatesFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].DynamicUpdateRejected),
|
float64(dst[0].DynamicUpdateRejected),
|
||||||
"rejected",
|
"rejected",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DynamicUpdatesFailures,
|
c.dynamicUpdatesFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].DynamicUpdateTimeOuts),
|
float64(dst[0].DynamicUpdateTimeOuts),
|
||||||
"timeout",
|
"timeout",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NotifyReceived,
|
c.notifyReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].NotifyReceived),
|
float64(dst[0].NotifyReceived),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NotifySent,
|
c.notifySent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].NotifySent),
|
float64(dst[0].NotifySent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RecursiveQueries,
|
c.recursiveQueries,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].RecursiveQueries),
|
float64(dst[0].RecursiveQueries),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RecursiveQueryFailures,
|
c.recursiveQueryFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].RecursiveQueryFailure),
|
float64(dst[0].RecursiveQueryFailure),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RecursiveQuerySendTimeouts,
|
c.recursiveQuerySendTimeouts,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].RecursiveSendTimeOuts),
|
float64(dst[0].RecursiveSendTimeOuts),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Queries,
|
c.queries,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].TCPQueryReceived),
|
float64(dst[0].TCPQueryReceived),
|
||||||
"tcp",
|
"tcp",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Queries,
|
c.queries,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].UDPQueryReceived),
|
float64(dst[0].UDPQueryReceived),
|
||||||
"udp",
|
"udp",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Responses,
|
c.responses,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].TCPResponseSent),
|
float64(dst[0].TCPResponseSent),
|
||||||
"tcp",
|
"tcp",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Responses,
|
c.responses,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].UDPResponseSent),
|
float64(dst[0].UDPResponseSent),
|
||||||
"udp",
|
"udp",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UnmatchedResponsesReceived,
|
c.unmatchedResponsesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].UnmatchedResponsesReceived),
|
float64(dst[0].UnmatchedResponsesReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WinsQueries,
|
c.winsQueries,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].WINSLookupReceived),
|
float64(dst[0].WINSLookupReceived),
|
||||||
"forward",
|
"forward",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WinsQueries,
|
c.winsQueries,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].WINSReverseLookupReceived),
|
float64(dst[0].WINSReverseLookupReceived),
|
||||||
"reverse",
|
"reverse",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WinsResponses,
|
c.winsResponses,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].WINSResponseSent),
|
float64(dst[0].WINSResponseSent),
|
||||||
"forward",
|
"forward",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WinsResponses,
|
c.winsResponses,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].WINSReverseResponseSent),
|
float64(dst[0].WINSReverseResponseSent),
|
||||||
"reverse",
|
"reverse",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SecureUpdateFailures,
|
c.secureUpdateFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].SecureUpdateFailure),
|
float64(dst[0].SecureUpdateFailure),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SecureUpdateReceived,
|
c.secureUpdateReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].SecureUpdateReceived),
|
float64(dst[0].SecureUpdateReceived),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,123 +13,161 @@ import (
|
|||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "exchange"
|
||||||
Name = "exchange"
|
|
||||||
FlagExchangeListAllCollectors = "collectors.exchange.list"
|
|
||||||
FlagExchangeCollectorsEnabled = "collectors.exchange.enabled"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CollectorsEnabled string `yaml:"collectors_enabled"`
|
CollectorsEnabled []string `yaml:"collectors_enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
CollectorsEnabled: "",
|
CollectorsEnabled: []string{
|
||||||
|
"ADAccessProcesses",
|
||||||
|
"TransportQueues",
|
||||||
|
"HttpProxy",
|
||||||
|
"ActiveSync",
|
||||||
|
"AvailabilityService",
|
||||||
|
"OutlookWebAccess",
|
||||||
|
"Autodiscover",
|
||||||
|
"WorkloadManagement",
|
||||||
|
"RpcClientAccess",
|
||||||
|
"MapiHttpEmsmdb",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
exchangeListAllCollectors *bool
|
activeMailboxDeliveryQueueLength *prometheus.Desc
|
||||||
exchangeCollectorsEnabled *string
|
activeSyncRequestsPerSec *prometheus.Desc
|
||||||
|
activeTasks *prometheus.Desc
|
||||||
LDAPReadTime *prometheus.Desc
|
activeUserCount *prometheus.Desc
|
||||||
LDAPSearchTime *prometheus.Desc
|
activeUserCountMapiHttpEmsMDB *prometheus.Desc
|
||||||
LDAPWriteTime *prometheus.Desc
|
autoDiscoverRequestsPerSec *prometheus.Desc
|
||||||
LDAPTimeoutErrorsPerSec *prometheus.Desc
|
availabilityRequestsSec *prometheus.Desc
|
||||||
LongRunningLDAPOperationsPerMin *prometheus.Desc
|
averageAuthenticationLatency *prometheus.Desc
|
||||||
ExternalActiveRemoteDeliveryQueueLength *prometheus.Desc
|
averageCASProcessingLatency *prometheus.Desc
|
||||||
InternalActiveRemoteDeliveryQueueLength *prometheus.Desc
|
completedTasks *prometheus.Desc
|
||||||
ActiveMailboxDeliveryQueueLength *prometheus.Desc
|
connectionCount *prometheus.Desc
|
||||||
RetryMailboxDeliveryQueueLength *prometheus.Desc
|
currentUniqueUsers *prometheus.Desc
|
||||||
UnreachableQueueLength *prometheus.Desc
|
externalActiveRemoteDeliveryQueueLength *prometheus.Desc
|
||||||
ExternalLargestDeliveryQueueLength *prometheus.Desc
|
externalLargestDeliveryQueueLength *prometheus.Desc
|
||||||
InternalLargestDeliveryQueueLength *prometheus.Desc
|
internalActiveRemoteDeliveryQueueLength *prometheus.Desc
|
||||||
PoisonQueueLength *prometheus.Desc
|
internalLargestDeliveryQueueLength *prometheus.Desc
|
||||||
MailboxServerLocatorAverageLatency *prometheus.Desc
|
isActive *prometheus.Desc
|
||||||
AverageAuthenticationLatency *prometheus.Desc
|
ldapReadTime *prometheus.Desc
|
||||||
AverageCASProcessingLatency *prometheus.Desc
|
ldapSearchTime *prometheus.Desc
|
||||||
MailboxServerProxyFailureRate *prometheus.Desc
|
ldapTimeoutErrorsPerSec *prometheus.Desc
|
||||||
OutstandingProxyRequests *prometheus.Desc
|
ldapWriteTime *prometheus.Desc
|
||||||
ProxyRequestsPerSec *prometheus.Desc
|
longRunningLDAPOperationsPerMin *prometheus.Desc
|
||||||
ActiveSyncRequestsPerSec *prometheus.Desc
|
mailboxServerLocatorAverageLatency *prometheus.Desc
|
||||||
PingCommandsPending *prometheus.Desc
|
mailboxServerProxyFailureRate *prometheus.Desc
|
||||||
SyncCommandsPerSec *prometheus.Desc
|
outstandingProxyRequests *prometheus.Desc
|
||||||
AvailabilityRequestsSec *prometheus.Desc
|
owaRequestsPerSec *prometheus.Desc
|
||||||
CurrentUniqueUsers *prometheus.Desc
|
pingCommandsPending *prometheus.Desc
|
||||||
OWARequestsPerSec *prometheus.Desc
|
poisonQueueLength *prometheus.Desc
|
||||||
AutodiscoverRequestsPerSec *prometheus.Desc
|
proxyRequestsPerSec *prometheus.Desc
|
||||||
ActiveTasks *prometheus.Desc
|
queuedTasks *prometheus.Desc
|
||||||
CompletedTasks *prometheus.Desc
|
retryMailboxDeliveryQueueLength *prometheus.Desc
|
||||||
QueuedTasks *prometheus.Desc
|
rpcAveragedLatency *prometheus.Desc
|
||||||
YieldedTasks *prometheus.Desc
|
rpcOperationsPerSec *prometheus.Desc
|
||||||
IsActive *prometheus.Desc
|
rpcRequests *prometheus.Desc
|
||||||
RPCAveragedLatency *prometheus.Desc
|
syncCommandsPerSec *prometheus.Desc
|
||||||
RPCRequests *prometheus.Desc
|
unreachableQueueLength *prometheus.Desc
|
||||||
ActiveUserCount *prometheus.Desc
|
userCount *prometheus.Desc
|
||||||
ConnectionCount *prometheus.Desc
|
yieldedTasks *prometheus.Desc
|
||||||
RPCOperationsPerSec *prometheus.Desc
|
|
||||||
UserCount *prometheus.Desc
|
|
||||||
ActiveUserCountMapiHttpEmsmdb *prometheus.Desc
|
|
||||||
|
|
||||||
enabledCollectors []string
|
enabledCollectors []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// All available collector functions
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
var exchangeAllCollectorNames = []string{
|
|
||||||
"ADAccessProcesses",
|
|
||||||
"TransportQueues",
|
|
||||||
"HttpProxy",
|
|
||||||
"ActiveSync",
|
|
||||||
"AvailabilityService",
|
|
||||||
"OutlookWebAccess",
|
|
||||||
"Autodiscover",
|
|
||||||
"WorkloadManagement",
|
|
||||||
"RpcClientAccess",
|
|
||||||
"MapiHttpEmsmdb",
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeListAllCollectors := false
|
if config.CollectorsEnabled == nil {
|
||||||
c := &collector{
|
config.CollectorsEnabled = ConfigDefaults.CollectorsEnabled
|
||||||
exchangeCollectorsEnabled: &config.CollectorsEnabled,
|
|
||||||
exchangeListAllCollectors: &exchangeListAllCollectors,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
return &collector{
|
c := &Collector{
|
||||||
exchangeListAllCollectors: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagExchangeListAllCollectors,
|
|
||||||
"List the collectors along with their perflib object name/ids",
|
|
||||||
).Bool(),
|
|
||||||
|
|
||||||
exchangeCollectorsEnabled: app.Flag(
|
|
||||||
FlagExchangeCollectorsEnabled,
|
|
||||||
"Comma-separated list of collectors to use. Defaults to all, if not specified.",
|
|
||||||
).Default(ConfigDefaults.CollectorsEnabled).String(),
|
|
||||||
}
|
}
|
||||||
|
c.config.CollectorsEnabled = make([]string, 0)
|
||||||
|
|
||||||
|
var listAllCollectors bool
|
||||||
|
var collectorsEnabled string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collectors.exchange.list",
|
||||||
|
"List the collectors along with their perflib object name/ids",
|
||||||
|
).BoolVar(&listAllCollectors)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collectors.exchange.enabled",
|
||||||
|
"Comma-separated list of collectors to use. Defaults to all, if not specified.",
|
||||||
|
).Default(strings.Join(ConfigDefaults.CollectorsEnabled, ",")).StringVar(&collectorsEnabled)
|
||||||
|
|
||||||
|
app.PreAction(func(*kingpin.ParseContext) error {
|
||||||
|
if listAllCollectors {
|
||||||
|
collectorDesc := map[string]string{
|
||||||
|
"ADAccessProcesses": "[19108] MSExchange ADAccess Processes",
|
||||||
|
"TransportQueues": "[20524] MSExchangeTransport Queues",
|
||||||
|
"HttpProxy": "[36934] MSExchange HttpProxy",
|
||||||
|
"ActiveSync": "[25138] MSExchange ActiveSync",
|
||||||
|
"AvailabilityService": "[24914] MSExchange Availability Service",
|
||||||
|
"OutlookWebAccess": "[24618] MSExchange OWA",
|
||||||
|
"Autodiscover": "[29240] MSExchange Autodiscover",
|
||||||
|
"WorkloadManagement": "[19430] MSExchange WorkloadManagement Workloads",
|
||||||
|
"RpcClientAccess": "[29336] MSExchange RpcClientAccess",
|
||||||
|
"MapiHttpEmsmdb": "[26463] MSExchange MapiHttp Emsmdb",
|
||||||
|
}
|
||||||
|
|
||||||
|
sb := strings.Builder{}
|
||||||
|
sb.WriteString(fmt.Sprintf("%-32s %-32s\n", "Collector Name", "[PerfID] Perflib Object"))
|
||||||
|
|
||||||
|
for _, cname := range ConfigDefaults.CollectorsEnabled {
|
||||||
|
sb.WriteString(fmt.Sprintf("%-32s %-32s\n", cname, collectorDesc[cname]))
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UsageTemplate(sb.String()).Usage(nil)
|
||||||
|
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
c.config.CollectorsEnabled = strings.Split(collectorsEnabled, ",")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{
|
return []string{
|
||||||
"MSExchange ADAccess Processes",
|
"MSExchange ADAccess Processes",
|
||||||
"MSExchangeTransport Queues",
|
"MSExchangeTransport Queues",
|
||||||
@@ -144,7 +182,11 @@ func (c *collector) GetPerfCounter() ([]string, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
// desc creates a new prometheus description
|
// desc creates a new prometheus description
|
||||||
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
||||||
return prometheus.NewDesc(
|
return prometheus.NewDesc(
|
||||||
@@ -155,87 +197,62 @@ func (c *collector) Build() error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.RPCAveragedLatency = desc("rpc_avg_latency_sec", "The latency (sec) averaged for the past 1024 packets")
|
c.rpcAveragedLatency = desc("rpc_avg_latency_sec", "The latency (sec) averaged for the past 1024 packets")
|
||||||
c.RPCRequests = desc("rpc_requests", "Number of client requests currently being processed by the RPC Client Access service")
|
c.rpcRequests = desc("rpc_requests", "Number of client requests currently being processed by the RPC Client Access service")
|
||||||
c.ActiveUserCount = desc("rpc_active_user_count", "Number of unique users that have shown some kind of activity in the last 2 minutes")
|
c.activeUserCount = desc("rpc_active_user_count", "Number of unique users that have shown some kind of activity in the last 2 minutes")
|
||||||
c.ConnectionCount = desc("rpc_connection_count", "Total number of client connections maintained")
|
c.connectionCount = desc("rpc_connection_count", "Total number of client connections maintained")
|
||||||
c.RPCOperationsPerSec = desc("rpc_operations_total", "The rate at which RPC operations occur")
|
c.rpcOperationsPerSec = desc("rpc_operations_total", "The rate at which RPC operations occur")
|
||||||
c.UserCount = desc("rpc_user_count", "Number of users")
|
c.userCount = desc("rpc_user_count", "Number of users")
|
||||||
c.LDAPReadTime = desc("ldap_read_time_sec", "Time (sec) to send an LDAP read request and receive a response", "name")
|
c.ldapReadTime = desc("ldap_read_time_sec", "Time (sec) to send an LDAP read request and receive a response", "name")
|
||||||
c.LDAPSearchTime = desc("ldap_search_time_sec", "Time (sec) to send an LDAP search request and receive a response", "name")
|
c.ldapSearchTime = desc("ldap_search_time_sec", "Time (sec) to send an LDAP search request and receive a response", "name")
|
||||||
c.LDAPWriteTime = desc("ldap_write_time_sec", "Time (sec) to send an LDAP Add/Modify/Delete request and receive a response", "name")
|
c.ldapWriteTime = desc("ldap_write_time_sec", "Time (sec) to send an LDAP Add/Modify/Delete request and receive a response", "name")
|
||||||
c.LDAPTimeoutErrorsPerSec = desc("ldap_timeout_errors_total", "Total number of LDAP timeout errors", "name")
|
c.ldapTimeoutErrorsPerSec = desc("ldap_timeout_errors_total", "Total number of LDAP timeout errors", "name")
|
||||||
c.LongRunningLDAPOperationsPerMin = desc("ldap_long_running_ops_per_sec", "Long Running LDAP operations per second", "name")
|
c.longRunningLDAPOperationsPerMin = desc("ldap_long_running_ops_per_sec", "Long Running LDAP operations per second", "name")
|
||||||
c.ExternalActiveRemoteDeliveryQueueLength = desc("transport_queues_external_active_remote_delivery", "External Active Remote Delivery Queue length", "name")
|
c.externalActiveRemoteDeliveryQueueLength = desc("transport_queues_external_active_remote_delivery", "External Active Remote Delivery Queue length", "name")
|
||||||
c.InternalActiveRemoteDeliveryQueueLength = desc("transport_queues_internal_active_remote_delivery", "Internal Active Remote Delivery Queue length", "name")
|
c.internalActiveRemoteDeliveryQueueLength = desc("transport_queues_internal_active_remote_delivery", "Internal Active Remote Delivery Queue length", "name")
|
||||||
c.ActiveMailboxDeliveryQueueLength = desc("transport_queues_active_mailbox_delivery", "Active Mailbox Delivery Queue length", "name")
|
c.activeMailboxDeliveryQueueLength = desc("transport_queues_active_mailbox_delivery", "Active Mailbox Delivery Queue length", "name")
|
||||||
c.RetryMailboxDeliveryQueueLength = desc("transport_queues_retry_mailbox_delivery", "Retry Mailbox Delivery Queue length", "name")
|
c.retryMailboxDeliveryQueueLength = desc("transport_queues_retry_mailbox_delivery", "Retry Mailbox Delivery Queue length", "name")
|
||||||
c.UnreachableQueueLength = desc("transport_queues_unreachable", "Unreachable Queue length", "name")
|
c.unreachableQueueLength = desc("transport_queues_unreachable", "Unreachable Queue length", "name")
|
||||||
c.ExternalLargestDeliveryQueueLength = desc("transport_queues_external_largest_delivery", "External Largest Delivery Queue length", "name")
|
c.externalLargestDeliveryQueueLength = desc("transport_queues_external_largest_delivery", "External Largest Delivery Queue length", "name")
|
||||||
c.InternalLargestDeliveryQueueLength = desc("transport_queues_internal_largest_delivery", "Internal Largest Delivery Queue length", "name")
|
c.internalLargestDeliveryQueueLength = desc("transport_queues_internal_largest_delivery", "Internal Largest Delivery Queue length", "name")
|
||||||
c.PoisonQueueLength = desc("transport_queues_poison", "Poison Queue length", "name")
|
c.poisonQueueLength = desc("transport_queues_poison", "Poison Queue length", "name")
|
||||||
c.MailboxServerLocatorAverageLatency = desc("http_proxy_mailbox_server_locator_avg_latency_sec", "Average latency (sec) of MailboxServerLocator web service calls", "name")
|
c.mailboxServerLocatorAverageLatency = desc("http_proxy_mailbox_server_locator_avg_latency_sec", "Average latency (sec) of MailboxServerLocator web service calls", "name")
|
||||||
c.AverageAuthenticationLatency = desc("http_proxy_avg_auth_latency", "Average time spent authenticating CAS requests over the last 200 samples", "name")
|
c.averageAuthenticationLatency = desc("http_proxy_avg_auth_latency", "Average time spent authenticating CAS requests over the last 200 samples", "name")
|
||||||
c.OutstandingProxyRequests = desc("http_proxy_outstanding_proxy_requests", "Number of concurrent outstanding proxy requests", "name")
|
c.outstandingProxyRequests = desc("http_proxy_outstanding_proxy_requests", "Number of concurrent outstanding proxy requests", "name")
|
||||||
c.ProxyRequestsPerSec = desc("http_proxy_requests_total", "Number of proxy requests processed each second", "name")
|
c.proxyRequestsPerSec = desc("http_proxy_requests_total", "Number of proxy requests processed each second", "name")
|
||||||
c.AvailabilityRequestsSec = desc("avail_service_requests_per_sec", "Number of requests serviced per second")
|
c.availabilityRequestsSec = desc("avail_service_requests_per_sec", "Number of requests serviced per second")
|
||||||
c.CurrentUniqueUsers = desc("owa_current_unique_users", "Number of unique users currently logged on to Outlook Web App")
|
c.currentUniqueUsers = desc("owa_current_unique_users", "Number of unique users currently logged on to Outlook Web App")
|
||||||
c.OWARequestsPerSec = desc("owa_requests_total", "Number of requests handled by Outlook Web App per second")
|
c.owaRequestsPerSec = desc("owa_requests_total", "Number of requests handled by Outlook Web App per second")
|
||||||
c.AutodiscoverRequestsPerSec = desc("autodiscover_requests_total", "Number of autodiscover service requests processed each second")
|
c.autoDiscoverRequestsPerSec = desc("autodiscover_requests_total", "Number of autodiscover service requests processed each second")
|
||||||
c.ActiveTasks = desc("workload_active_tasks", "Number of active tasks currently running in the background for workload management", "name")
|
c.activeTasks = desc("workload_active_tasks", "Number of active tasks currently running in the background for workload management", "name")
|
||||||
c.CompletedTasks = desc("workload_completed_tasks", "Number of workload management tasks that have been completed", "name")
|
c.completedTasks = desc("workload_completed_tasks", "Number of workload management tasks that have been completed", "name")
|
||||||
c.QueuedTasks = desc("workload_queued_tasks", "Number of workload management tasks that are currently queued up waiting to be processed", "name")
|
c.queuedTasks = desc("workload_queued_tasks", "Number of workload management tasks that are currently queued up waiting to be processed", "name")
|
||||||
c.YieldedTasks = desc("workload_yielded_tasks", "The total number of tasks that have been yielded by a workload", "name")
|
c.yieldedTasks = desc("workload_yielded_tasks", "The total number of tasks that have been yielded by a workload", "name")
|
||||||
c.IsActive = desc("workload_is_active", "Active indicates whether the workload is in an active (1) or paused (0) state", "name")
|
c.isActive = desc("workload_is_active", "Active indicates whether the workload is in an active (1) or paused (0) state", "name")
|
||||||
c.ActiveSyncRequestsPerSec = desc("activesync_requests_total", "Num HTTP requests received from the client via ASP.NET per sec. Shows Current user load")
|
c.activeSyncRequestsPerSec = desc("activesync_requests_total", "Num HTTP requests received from the client via ASP.NET per sec. Shows Current user load")
|
||||||
c.AverageCASProcessingLatency = desc("http_proxy_avg_cas_proccessing_latency_sec", "Average latency (sec) of CAS processing time over the last 200 reqs", "name")
|
c.averageCASProcessingLatency = desc("http_proxy_avg_cas_processing_latency_sec", "Average latency (sec) of CAS processing time over the last 200 reqs", "name")
|
||||||
c.MailboxServerProxyFailureRate = desc("http_proxy_mailbox_proxy_failure_rate", "% of failures between this CAS and MBX servers over the last 200 samples", "name")
|
c.mailboxServerProxyFailureRate = desc("http_proxy_mailbox_proxy_failure_rate", "% of failures between this CAS and MBX servers over the last 200 samples", "name")
|
||||||
c.PingCommandsPending = desc("activesync_ping_cmds_pending", "Number of ping commands currently pending in the queue")
|
c.pingCommandsPending = desc("activesync_ping_cmds_pending", "Number of ping commands currently pending in the queue")
|
||||||
c.SyncCommandsPerSec = desc("activesync_sync_cmds_total", "Number of sync commands processed per second. Clients use this command to synchronize items within a folder")
|
c.syncCommandsPerSec = desc("activesync_sync_cmds_total", "Number of sync commands processed per second. Clients use this command to synchronize items within a folder")
|
||||||
c.ActiveUserCountMapiHttpEmsmdb = desc("mapihttp_emsmdb_active_user_count", "Number of unique outlook users that have shown some kind of activity in the last 2 minutes")
|
c.activeUserCountMapiHttpEmsMDB = desc("mapihttp_emsmdb_active_user_count", "Number of unique outlook users that have shown some kind of activity in the last 2 minutes")
|
||||||
|
|
||||||
c.enabledCollectors = make([]string, 0, len(exchangeAllCollectorNames))
|
c.enabledCollectors = make([]string, 0, len(ConfigDefaults.CollectorsEnabled))
|
||||||
|
|
||||||
collectorDesc := map[string]string{
|
for _, collectorName := range c.config.CollectorsEnabled {
|
||||||
"ADAccessProcesses": "[19108] MSExchange ADAccess Processes",
|
if !slices.Contains(ConfigDefaults.CollectorsEnabled, collectorName) {
|
||||||
"TransportQueues": "[20524] MSExchangeTransport Queues",
|
return fmt.Errorf("unknown exchange collector: %s", collectorName)
|
||||||
"HttpProxy": "[36934] MSExchange HttpProxy",
|
}
|
||||||
"ActiveSync": "[25138] MSExchange ActiveSync",
|
|
||||||
"AvailabilityService": "[24914] MSExchange Availability Service",
|
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
||||||
"OutlookWebAccess": "[24618] MSExchange OWA",
|
|
||||||
"Autodiscover": "[29240] MSExchange Autodiscover",
|
|
||||||
"WorkloadManagement": "[19430] MSExchange WorkloadManagement Workloads",
|
|
||||||
"RpcClientAccess": "[29336] MSExchange RpcClientAccess",
|
|
||||||
"MapiHttpEmsmdb": "[26463] MSExchange MapiHttp Emsmdb",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if *c.exchangeListAllCollectors {
|
c.enabledCollectors = slices.Clip(c.enabledCollectors)
|
||||||
fmt.Printf("%-32s %-32s\n", "Collector Name", "[PerfID] Perflib Object")
|
|
||||||
for _, cname := range exchangeAllCollectorNames {
|
|
||||||
fmt.Printf("%-32s %-32s\n", cname, collectorDesc[cname])
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if utils.IsEmpty(c.exchangeCollectorsEnabled) {
|
|
||||||
for _, collectorName := range exchangeAllCollectorNames {
|
|
||||||
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, collectorName := range strings.Split(*c.exchangeCollectorsEnabled, ",") {
|
|
||||||
if slices.Contains(exchangeAllCollectorNames, collectorName) {
|
|
||||||
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("unknown exchange collector: %s", collectorName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect collects exchange metrics and sends them to prometheus
|
// Collect collects exchange metrics and sends them to prometheus.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
|
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
|
||||||
"ADAccessProcesses": c.collectADAccessProcesses,
|
"ADAccessProcesses": c.collectADAccessProcesses,
|
||||||
"TransportQueues": c.collectTransportQueues,
|
"TransportQueues": c.collectTransportQueues,
|
||||||
@@ -258,7 +275,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [19108] MSExchange ADAccess Processes
|
// Perflib: [19108] MSExchange ADAccess Processes.
|
||||||
type perflibADAccessProcesses struct {
|
type perflibADAccessProcesses struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -269,7 +286,7 @@ type perflibADAccessProcesses struct {
|
|||||||
LongRunningLDAPOperationsPerMin float64 `perflib:"Long Running LDAP Operations/min"`
|
LongRunningLDAPOperationsPerMin float64 `perflib:"Long Running LDAP Operations/min"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectADAccessProcesses(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectADAccessProcesses(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibADAccessProcesses
|
var data []perflibADAccessProcesses
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange ADAccess Processes"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange ADAccess Processes"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -289,31 +306,31 @@ func (c *collector) collectADAccessProcesses(ctx *types.ScrapeContext, ch chan<-
|
|||||||
labelName = fmt.Sprintf("%s_%d", labelName, labelUseCount[labelName])
|
labelName = fmt.Sprintf("%s_%d", labelName, labelUseCount[labelName])
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LDAPReadTime,
|
c.ldapReadTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
c.msToSec(proc.LDAPReadTime),
|
c.msToSec(proc.LDAPReadTime),
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LDAPSearchTime,
|
c.ldapSearchTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
c.msToSec(proc.LDAPSearchTime),
|
c.msToSec(proc.LDAPSearchTime),
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LDAPWriteTime,
|
c.ldapWriteTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
c.msToSec(proc.LDAPWriteTime),
|
c.msToSec(proc.LDAPWriteTime),
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LDAPTimeoutErrorsPerSec,
|
c.ldapTimeoutErrorsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
proc.LDAPTimeoutErrorsPerSec,
|
proc.LDAPTimeoutErrorsPerSec,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LongRunningLDAPOperationsPerMin,
|
c.longRunningLDAPOperationsPerMin,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
proc.LongRunningLDAPOperationsPerMin*60,
|
proc.LongRunningLDAPOperationsPerMin*60,
|
||||||
labelName,
|
labelName,
|
||||||
@@ -322,12 +339,12 @@ func (c *collector) collectADAccessProcesses(ctx *types.ScrapeContext, ch chan<-
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [24914] MSExchange Availability Service
|
// Perflib: [24914] MSExchange Availability Service.
|
||||||
type perflibAvailabilityService struct {
|
type perflibAvailabilityService struct {
|
||||||
RequestsSec float64 `perflib:"Availability Requests (sec)"`
|
RequestsSec float64 `perflib:"Availability Requests (sec)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectAvailabilityService(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAvailabilityService(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibAvailabilityService
|
var data []perflibAvailabilityService
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange Availability Service"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange Availability Service"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -335,7 +352,7 @@ func (c *collector) collectAvailabilityService(ctx *types.ScrapeContext, ch chan
|
|||||||
|
|
||||||
for _, availservice := range data {
|
for _, availservice := range data {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AvailabilityRequestsSec,
|
c.availabilityRequestsSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
availservice.RequestsSec,
|
availservice.RequestsSec,
|
||||||
)
|
)
|
||||||
@@ -343,7 +360,7 @@ func (c *collector) collectAvailabilityService(ctx *types.ScrapeContext, ch chan
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [36934] MSExchange HttpProxy
|
// Perflib: [36934] MSExchange HttpProxy.
|
||||||
type perflibHTTPProxy struct {
|
type perflibHTTPProxy struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -355,7 +372,7 @@ type perflibHTTPProxy struct {
|
|||||||
ProxyRequestsPerSec float64 `perflib:"Proxy Requests/Sec"`
|
ProxyRequestsPerSec float64 `perflib:"Proxy Requests/Sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectHTTPProxy(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectHTTPProxy(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibHTTPProxy
|
var data []perflibHTTPProxy
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange HttpProxy"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange HttpProxy"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -364,37 +381,37 @@ func (c *collector) collectHTTPProxy(ctx *types.ScrapeContext, ch chan<- prometh
|
|||||||
for _, instance := range data {
|
for _, instance := range data {
|
||||||
labelName := c.toLabelName(instance.Name)
|
labelName := c.toLabelName(instance.Name)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MailboxServerLocatorAverageLatency,
|
c.mailboxServerLocatorAverageLatency,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
c.msToSec(instance.MailboxServerLocatorAverageLatency),
|
c.msToSec(instance.MailboxServerLocatorAverageLatency),
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AverageAuthenticationLatency,
|
c.averageAuthenticationLatency,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.AverageAuthenticationLatency,
|
instance.AverageAuthenticationLatency,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AverageCASProcessingLatency,
|
c.averageCASProcessingLatency,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
c.msToSec(instance.AverageCASProcessingLatency),
|
c.msToSec(instance.AverageCASProcessingLatency),
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MailboxServerProxyFailureRate,
|
c.mailboxServerProxyFailureRate,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.MailboxServerProxyFailureRate,
|
instance.MailboxServerProxyFailureRate,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OutstandingProxyRequests,
|
c.outstandingProxyRequests,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.OutstandingProxyRequests,
|
instance.OutstandingProxyRequests,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProxyRequestsPerSec,
|
c.proxyRequestsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.ProxyRequestsPerSec,
|
instance.ProxyRequestsPerSec,
|
||||||
labelName,
|
labelName,
|
||||||
@@ -403,13 +420,13 @@ func (c *collector) collectHTTPProxy(ctx *types.ScrapeContext, ch chan<- prometh
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [24618] MSExchange OWA
|
// Perflib: [24618] MSExchange OWA.
|
||||||
type perflibOWA struct {
|
type perflibOWA struct {
|
||||||
CurrentUniqueUsers float64 `perflib:"Current Unique Users"`
|
CurrentUniqueUsers float64 `perflib:"Current Unique Users"`
|
||||||
RequestsPerSec float64 `perflib:"Requests/sec"`
|
RequestsPerSec float64 `perflib:"Requests/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectOWA(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectOWA(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibOWA
|
var data []perflibOWA
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange OWA"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange OWA"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -417,12 +434,12 @@ func (c *collector) collectOWA(ctx *types.ScrapeContext, ch chan<- prometheus.Me
|
|||||||
|
|
||||||
for _, owa := range data {
|
for _, owa := range data {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentUniqueUsers,
|
c.currentUniqueUsers,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
owa.CurrentUniqueUsers,
|
owa.CurrentUniqueUsers,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OWARequestsPerSec,
|
c.owaRequestsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
owa.RequestsPerSec,
|
owa.RequestsPerSec,
|
||||||
)
|
)
|
||||||
@@ -430,14 +447,14 @@ func (c *collector) collectOWA(ctx *types.ScrapeContext, ch chan<- prometheus.Me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [25138] MSExchange ActiveSync
|
// Perflib: [25138] MSExchange ActiveSync.
|
||||||
type perflibActiveSync struct {
|
type perflibActiveSync struct {
|
||||||
RequestsPerSec float64 `perflib:"Requests/sec"`
|
RequestsPerSec float64 `perflib:"Requests/sec"`
|
||||||
PingCommandsPending float64 `perflib:"Ping Commands Pending"`
|
PingCommandsPending float64 `perflib:"Ping Commands Pending"`
|
||||||
SyncCommandsPerSec float64 `perflib:"Sync Commands/sec"`
|
SyncCommandsPerSec float64 `perflib:"Sync Commands/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectActiveSync(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectActiveSync(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibActiveSync
|
var data []perflibActiveSync
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange ActiveSync"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange ActiveSync"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -445,17 +462,17 @@ func (c *collector) collectActiveSync(ctx *types.ScrapeContext, ch chan<- promet
|
|||||||
|
|
||||||
for _, instance := range data {
|
for _, instance := range data {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ActiveSyncRequestsPerSec,
|
c.activeSyncRequestsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.RequestsPerSec,
|
instance.RequestsPerSec,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PingCommandsPending,
|
c.pingCommandsPending,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.PingCommandsPending,
|
instance.PingCommandsPending,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SyncCommandsPerSec,
|
c.syncCommandsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.SyncCommandsPerSec,
|
instance.SyncCommandsPerSec,
|
||||||
)
|
)
|
||||||
@@ -463,7 +480,7 @@ func (c *collector) collectActiveSync(ctx *types.ScrapeContext, ch chan<- promet
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [29366] MSExchange RpcClientAccess
|
// Perflib: [29366] MSExchange RpcClientAccess.
|
||||||
type perflibRPCClientAccess struct {
|
type perflibRPCClientAccess struct {
|
||||||
RPCAveragedLatency float64 `perflib:"RPC Averaged Latency"`
|
RPCAveragedLatency float64 `perflib:"RPC Averaged Latency"`
|
||||||
RPCRequests float64 `perflib:"RPC Requests"`
|
RPCRequests float64 `perflib:"RPC Requests"`
|
||||||
@@ -473,7 +490,7 @@ type perflibRPCClientAccess struct {
|
|||||||
UserCount float64 `perflib:"User Count"`
|
UserCount float64 `perflib:"User Count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectRPC(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectRPC(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibRPCClientAccess
|
var data []perflibRPCClientAccess
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange RpcClientAccess"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange RpcClientAccess"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -481,32 +498,32 @@ func (c *collector) collectRPC(ctx *types.ScrapeContext, ch chan<- prometheus.Me
|
|||||||
|
|
||||||
for _, rpc := range data {
|
for _, rpc := range data {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RPCAveragedLatency,
|
c.rpcAveragedLatency,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
c.msToSec(rpc.RPCAveragedLatency),
|
c.msToSec(rpc.RPCAveragedLatency),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RPCRequests,
|
c.rpcRequests,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
rpc.RPCRequests,
|
rpc.RPCRequests,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ActiveUserCount,
|
c.activeUserCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
rpc.ActiveUserCount,
|
rpc.ActiveUserCount,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionCount,
|
c.connectionCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
rpc.ConnectionCount,
|
rpc.ConnectionCount,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RPCOperationsPerSec,
|
c.rpcOperationsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
rpc.RPCOperationsPerSec,
|
rpc.RPCOperationsPerSec,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UserCount,
|
c.userCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
rpc.UserCount,
|
rpc.UserCount,
|
||||||
)
|
)
|
||||||
@@ -515,7 +532,7 @@ func (c *collector) collectRPC(ctx *types.ScrapeContext, ch chan<- prometheus.Me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [20524] MSExchangeTransport Queues
|
// Perflib: [20524] MSExchangeTransport Queues.
|
||||||
type perflibTransportQueues struct {
|
type perflibTransportQueues struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -529,7 +546,7 @@ type perflibTransportQueues struct {
|
|||||||
PoisonQueueLength float64 `perflib:"Poison Queue Length"`
|
PoisonQueueLength float64 `perflib:"Poison Queue Length"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectTransportQueues(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectTransportQueues(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibTransportQueues
|
var data []perflibTransportQueues
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchangeTransport Queues"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchangeTransport Queues"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -541,49 +558,49 @@ func (c *collector) collectTransportQueues(ctx *types.ScrapeContext, ch chan<- p
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ExternalActiveRemoteDeliveryQueueLength,
|
c.externalActiveRemoteDeliveryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.ExternalActiveRemoteDeliveryQueueLength,
|
queue.ExternalActiveRemoteDeliveryQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InternalActiveRemoteDeliveryQueueLength,
|
c.internalActiveRemoteDeliveryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.InternalActiveRemoteDeliveryQueueLength,
|
queue.InternalActiveRemoteDeliveryQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ActiveMailboxDeliveryQueueLength,
|
c.activeMailboxDeliveryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.ActiveMailboxDeliveryQueueLength,
|
queue.ActiveMailboxDeliveryQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RetryMailboxDeliveryQueueLength,
|
c.retryMailboxDeliveryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.RetryMailboxDeliveryQueueLength,
|
queue.RetryMailboxDeliveryQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UnreachableQueueLength,
|
c.unreachableQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.UnreachableQueueLength,
|
queue.UnreachableQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ExternalLargestDeliveryQueueLength,
|
c.externalLargestDeliveryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.ExternalLargestDeliveryQueueLength,
|
queue.ExternalLargestDeliveryQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InternalLargestDeliveryQueueLength,
|
c.internalLargestDeliveryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.InternalLargestDeliveryQueueLength,
|
queue.InternalLargestDeliveryQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoisonQueueLength,
|
c.poisonQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
queue.PoisonQueueLength,
|
queue.PoisonQueueLength,
|
||||||
labelName,
|
labelName,
|
||||||
@@ -592,7 +609,7 @@ func (c *collector) collectTransportQueues(ctx *types.ScrapeContext, ch chan<- p
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib: [19430] MSExchange WorkloadManagement Workloads
|
// Perflib: [19430] MSExchange WorkloadManagement Workloads.
|
||||||
type perflibWorkloadManagementWorkloads struct {
|
type perflibWorkloadManagementWorkloads struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -603,7 +620,7 @@ type perflibWorkloadManagementWorkloads struct {
|
|||||||
IsActive float64 `perflib:"Active"`
|
IsActive float64 `perflib:"Active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectWorkloadManagementWorkloads(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectWorkloadManagementWorkloads(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibWorkloadManagementWorkloads
|
var data []perflibWorkloadManagementWorkloads
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange WorkloadManagement Workloads"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange WorkloadManagement Workloads"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -615,31 +632,31 @@ func (c *collector) collectWorkloadManagementWorkloads(ctx *types.ScrapeContext,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ActiveTasks,
|
c.activeTasks,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.ActiveTasks,
|
instance.ActiveTasks,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CompletedTasks,
|
c.completedTasks,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.CompletedTasks,
|
instance.CompletedTasks,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.QueuedTasks,
|
c.queuedTasks,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.QueuedTasks,
|
instance.QueuedTasks,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.YieldedTasks,
|
c.yieldedTasks,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.YieldedTasks,
|
instance.YieldedTasks,
|
||||||
labelName,
|
labelName,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IsActive,
|
c.isActive,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.IsActive,
|
instance.IsActive,
|
||||||
labelName,
|
labelName,
|
||||||
@@ -649,19 +666,19 @@ func (c *collector) collectWorkloadManagementWorkloads(ctx *types.ScrapeContext,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// [29240] MSExchangeAutodiscover
|
// [29240] MSExchangeAutodiscover.
|
||||||
type perflibAutodiscover struct {
|
type perflibAutodiscover struct {
|
||||||
RequestsPerSec float64 `perflib:"Requests/sec"`
|
RequestsPerSec float64 `perflib:"Requests/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectAutoDiscover(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAutoDiscover(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibAutodiscover
|
var data []perflibAutodiscover
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchangeAutodiscover"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchangeAutodiscover"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, autodisc := range data {
|
for _, autodisc := range data {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AutodiscoverRequestsPerSec,
|
c.autoDiscoverRequestsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
autodisc.RequestsPerSec,
|
autodisc.RequestsPerSec,
|
||||||
)
|
)
|
||||||
@@ -669,12 +686,12 @@ func (c *collector) collectAutoDiscover(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// perflib [26463] MSExchange MapiHttp Emsmdb
|
// perflib [26463] MSExchange MapiHttp Emsmdb.
|
||||||
type perflibMapiHttpEmsmdb struct {
|
type perflibMapiHttpEmsmdb struct {
|
||||||
ActiveUserCount float64 `perflib:"Active User Count"`
|
ActiveUserCount float64 `perflib:"Active User Count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectMapiHttpEmsmdb(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectMapiHttpEmsmdb(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibMapiHttpEmsmdb
|
var data []perflibMapiHttpEmsmdb
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange MapiHttp Emsmdb"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["MSExchange MapiHttp Emsmdb"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -682,7 +699,7 @@ func (c *collector) collectMapiHttpEmsmdb(ctx *types.ScrapeContext, ch chan<- pr
|
|||||||
|
|
||||||
for _, mapihttp := range data {
|
for _, mapihttp := range data {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ActiveUserCountMapiHttpEmsmdb,
|
c.activeUserCountMapiHttpEmsMDB,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mapihttp.ActiveUserCount,
|
mapihttp.ActiveUserCount,
|
||||||
)
|
)
|
||||||
@@ -691,14 +708,14 @@ func (c *collector) collectMapiHttpEmsmdb(ctx *types.ScrapeContext, ch chan<- pr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores
|
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores.
|
||||||
func (c *collector) toLabelName(name string) string {
|
func (c *Collector) toLabelName(name string) string {
|
||||||
s := strings.ReplaceAll(strings.Join(strings.Fields(strings.ToLower(name)), "_"), ".", "_")
|
s := strings.ReplaceAll(strings.Join(strings.Fields(strings.ToLower(name)), "_"), ".", "_")
|
||||||
s = strings.ReplaceAll(s, "__", "_")
|
s = strings.ReplaceAll(s, "__", "_")
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// msToSec converts from ms to seconds
|
// msToSec converts from ms to seconds.
|
||||||
func (c *collector) msToSec(t float64) float64 {
|
func (c *Collector) msToSec(t float64) float64 {
|
||||||
return t / 1000
|
return t / 1000
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
package fsrmquota
|
package fsrmquota
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,94 +18,106 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
QuotasCount *prometheus.Desc
|
quotasCount *prometheus.Desc
|
||||||
Path *prometheus.Desc
|
peakUsage *prometheus.Desc
|
||||||
PeakUsage *prometheus.Desc
|
size *prometheus.Desc
|
||||||
Size *prometheus.Desc
|
usage *prometheus.Desc
|
||||||
Usage *prometheus.Desc
|
|
||||||
|
|
||||||
Description *prometheus.Desc
|
description *prometheus.Desc
|
||||||
Disabled *prometheus.Desc
|
disabled *prometheus.Desc
|
||||||
MatchesTemplate *prometheus.Desc
|
matchesTemplate *prometheus.Desc
|
||||||
SoftLimit *prometheus.Desc
|
softLimit *prometheus.Desc
|
||||||
Template *prometheus.Desc
|
template *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.QuotasCount = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.quotasCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
||||||
"Number of Quotas",
|
"Number of Quotas",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PeakUsage = prometheus.NewDesc(
|
c.peakUsage = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "peak_usage_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "peak_usage_bytes"),
|
||||||
"The highest amount of disk space usage charged to this quota. (PeakUsage)",
|
"The highest amount of disk space usage charged to this quota. (PeakUsage)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Size = prometheus.NewDesc(
|
c.size = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "size_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "size_bytes"),
|
||||||
"The size of the quota. (Size)",
|
"The size of the quota. (Size)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Usage = prometheus.NewDesc(
|
c.usage = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "usage_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "usage_bytes"),
|
||||||
"The current amount of disk space usage charged to this quota. (Usage)",
|
"The current amount of disk space usage charged to this quota. (Usage)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Description = prometheus.NewDesc(
|
c.description = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "description"),
|
prometheus.BuildFQName(types.Namespace, Name, "description"),
|
||||||
"Description of the quota (Description)",
|
"Description of the quota (Description)",
|
||||||
[]string{"path", "template", "description"},
|
[]string{"path", "template", "description"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Disabled = prometheus.NewDesc(
|
c.disabled = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "disabled"),
|
prometheus.BuildFQName(types.Namespace, Name, "disabled"),
|
||||||
"If 1, the quota is disabled. The default value is 0. (Disabled)",
|
"If 1, the quota is disabled. The default value is 0. (Disabled)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SoftLimit = prometheus.NewDesc(
|
c.softLimit = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "softlimit"),
|
prometheus.BuildFQName(types.Namespace, Name, "softlimit"),
|
||||||
"If 1, the quota is a soft limit. If 0, the quota is a hard limit. The default value is 0. Optional (SoftLimit)",
|
"If 1, the quota is a soft limit. If 0, the quota is a hard limit. The default value is 0. Optional (SoftLimit)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Template = prometheus.NewDesc(
|
c.template = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "template"),
|
prometheus.BuildFQName(types.Namespace, Name, "template"),
|
||||||
"Quota template name. (Template)",
|
"Quota template name. (Template)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MatchesTemplate = prometheus.NewDesc(
|
c.matchesTemplate = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "matchestemplate"),
|
prometheus.BuildFQName(types.Namespace, Name, "matchestemplate"),
|
||||||
"If 1, the property values of this quota match those values of the template from which it was derived. (MatchesTemplate)",
|
"If 1, the property values of this quota match those values of the template from which it was derived. (MatchesTemplate)",
|
||||||
[]string{"path", "template"},
|
[]string{"path", "template"},
|
||||||
@@ -117,7 +128,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting fsrmquota metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting fsrmquota metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -142,7 +153,7 @@ type MSFT_FSRMQuota struct {
|
|||||||
SoftLimit bool
|
SoftLimit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []MSFT_FSRMQuota
|
var dst []MSFT_FSRMQuota
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
|
|
||||||
@@ -153,55 +164,54 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, quota := range dst {
|
for _, quota := range dst {
|
||||||
|
|
||||||
count++
|
count++
|
||||||
path := quota.Path
|
path := quota.Path
|
||||||
template := quota.Template
|
template := quota.Template
|
||||||
Description := quota.Description
|
Description := quota.Description
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PeakUsage,
|
c.peakUsage,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(quota.PeakUsage),
|
float64(quota.PeakUsage),
|
||||||
path,
|
path,
|
||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Size,
|
c.size,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(quota.Size),
|
float64(quota.Size),
|
||||||
path,
|
path,
|
||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Usage,
|
c.usage,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(quota.Usage),
|
float64(quota.Usage),
|
||||||
path,
|
path,
|
||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Description,
|
c.description,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1.0,
|
1.0,
|
||||||
path, template, Description,
|
path, template, Description,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Disabled,
|
c.disabled,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.BoolToFloat(quota.Disabled),
|
utils.BoolToFloat(quota.Disabled),
|
||||||
path,
|
path,
|
||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MatchesTemplate,
|
c.matchesTemplate,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.BoolToFloat(quota.MatchesTemplate),
|
utils.BoolToFloat(quota.MatchesTemplate),
|
||||||
path,
|
path,
|
||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SoftLimit,
|
c.softLimit,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.BoolToFloat(quota.SoftLimit),
|
utils.BoolToFloat(quota.SoftLimit),
|
||||||
path,
|
path,
|
||||||
@@ -210,7 +220,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.QuotasCount,
|
c.quotasCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(count),
|
float64(count),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors/version"
|
"github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||||
@@ -20,7 +19,7 @@ import (
|
|||||||
|
|
||||||
func (c *Collectors) BuildServeHTTP(disableExporterMetrics bool, timeoutMargin float64) http.HandlerFunc {
|
func (c *Collectors) BuildServeHTTP(disableExporterMetrics bool, timeoutMargin float64) http.HandlerFunc {
|
||||||
collectorFactory := func(timeout time.Duration, requestedCollectors []string) (error, *Prometheus) {
|
collectorFactory := func(timeout time.Duration, requestedCollectors []string) (error, *Prometheus) {
|
||||||
filteredCollectors := make(map[string]types.Collector)
|
filteredCollectors := make(map[string]Collector)
|
||||||
// scrape all enabled collectors if no collector is requested
|
// scrape all enabled collectors if no collector is requested
|
||||||
if len(requestedCollectors) == 0 {
|
if len(requestedCollectors) == 0 {
|
||||||
filteredCollectors = c.collectors
|
filteredCollectors = c.collectors
|
||||||
@@ -56,7 +55,7 @@ func (c *Collectors) BuildServeHTTP(disableExporterMetrics bool, timeoutMargin f
|
|||||||
if timeoutSeconds == 0 {
|
if timeoutSeconds == 0 {
|
||||||
timeoutSeconds = defaultTimeout
|
timeoutSeconds = defaultTimeout
|
||||||
}
|
}
|
||||||
timeoutSeconds = timeoutSeconds - timeoutMargin
|
timeoutSeconds -= timeoutMargin
|
||||||
|
|
||||||
reg := prometheus.NewRegistry()
|
reg := prometheus.NewRegistry()
|
||||||
err, wc := collectorFactory(time.Duration(timeoutSeconds*float64(time.Second)), r.URL.Query()["collect[]"])
|
err, wc := collectorFactory(time.Duration(timeoutSeconds*float64(time.Second)), r.URL.Query()["collect[]"])
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestIISDeduplication(t *testing.T) {
|
func TestIISDeduplication(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
start := []perflibAPP_POOL_WAS{
|
start := []perflibAPP_POOL_WAS{
|
||||||
{
|
{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import (
|
|||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/slc"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/slc"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "license"
|
const Name = "license"
|
||||||
@@ -26,37 +25,50 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_DNS_DNS metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
LicenseStatus *prometheus.Desc
|
licenseStatus *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.LicenseStatus = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.licenseStatus = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
||||||
"Status of windows license",
|
"Status of windows license",
|
||||||
[]string{"state"},
|
[]string{"state"},
|
||||||
@@ -68,7 +80,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting license metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting license metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -76,7 +88,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
status, err := slc.SLIsWindowsGenuineLocal()
|
status, err := slc.SLIsWindowsGenuineLocal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -88,7 +100,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
val = 1.0
|
val = 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(c.LicenseStatus, prometheus.GaugeValue, val, v)
|
ch <- prometheus.MustNewConstMetric(c.licenseStatus, prometheus.GaugeValue, val, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -10,61 +10,50 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "logical_disk"
|
||||||
Name = "logical_disk"
|
|
||||||
|
|
||||||
FlagLogicalDiskVolumeExclude = "collector.logical_disk.volume-exclude"
|
|
||||||
FlagLogicalDiskVolumeInclude = "collector.logical_disk.volume-include"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
VolumeInclude string `yaml:"volume_include"`
|
VolumeInclude *regexp.Regexp `yaml:"volume_include"`
|
||||||
VolumeExclude string `yaml:"volume_exclude"`
|
VolumeExclude *regexp.Regexp `yaml:"volume_exclude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
VolumeInclude: ".+",
|
VolumeInclude: types.RegExpAny,
|
||||||
VolumeExclude: "",
|
VolumeExclude: types.RegExpEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for perflib logicalDisk metrics
|
// A Collector is a Prometheus Collector for perflib logicalDisk metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
volumeInclude *string
|
avgReadQueue *prometheus.Desc
|
||||||
volumeExclude *string
|
avgWriteQueue *prometheus.Desc
|
||||||
|
freeSpace *prometheus.Desc
|
||||||
Information *prometheus.Desc
|
idleTime *prometheus.Desc
|
||||||
ReadOnly *prometheus.Desc
|
information *prometheus.Desc
|
||||||
RequestsQueued *prometheus.Desc
|
readBytesTotal *prometheus.Desc
|
||||||
AvgReadQueue *prometheus.Desc
|
readLatency *prometheus.Desc
|
||||||
AvgWriteQueue *prometheus.Desc
|
readOnly *prometheus.Desc
|
||||||
ReadBytesTotal *prometheus.Desc
|
readsTotal *prometheus.Desc
|
||||||
ReadsTotal *prometheus.Desc
|
readTime *prometheus.Desc
|
||||||
WriteBytesTotal *prometheus.Desc
|
readWriteLatency *prometheus.Desc
|
||||||
WritesTotal *prometheus.Desc
|
requestsQueued *prometheus.Desc
|
||||||
ReadTime *prometheus.Desc
|
splitIOs *prometheus.Desc
|
||||||
WriteTime *prometheus.Desc
|
totalSpace *prometheus.Desc
|
||||||
TotalSpace *prometheus.Desc
|
writeBytesTotal *prometheus.Desc
|
||||||
FreeSpace *prometheus.Desc
|
writeLatency *prometheus.Desc
|
||||||
IdleTime *prometheus.Desc
|
writesTotal *prometheus.Desc
|
||||||
SplitIOs *prometheus.Desc
|
writeTime *prometheus.Desc
|
||||||
ReadLatency *prometheus.Desc
|
|
||||||
WriteLatency *prometheus.Desc
|
|
||||||
ReadWriteLatency *prometheus.Desc
|
|
||||||
|
|
||||||
volumeIncludePattern *regexp.Regexp
|
|
||||||
volumeExcludePattern *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type volumeInfo struct {
|
type volumeInfo struct {
|
||||||
@@ -75,188 +64,211 @@ type volumeInfo struct {
|
|||||||
readonly float64
|
readonly float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.VolumeExclude == nil {
|
||||||
volumeExclude: &config.VolumeExclude,
|
config.VolumeExclude = ConfigDefaults.VolumeExclude
|
||||||
volumeInclude: &config.VolumeInclude,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.VolumeInclude == nil {
|
||||||
|
config.VolumeInclude = ConfigDefaults.VolumeInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
volumeInclude: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagLogicalDiskVolumeInclude,
|
|
||||||
"Regexp of volumes to include. Volume name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.VolumeInclude).String(),
|
|
||||||
volumeExclude: app.Flag(
|
|
||||||
FlagLogicalDiskVolumeExclude,
|
|
||||||
"Regexp of volumes to exclude. Volume name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.VolumeExclude).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var volumeExclude, volumeInclude string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.logical_disk.volume-exclude",
|
||||||
|
"Regexp of volumes to exclude. Volume name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.VolumeExclude.String()).StringVar(&volumeExclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.logical_disk.volume-include",
|
||||||
|
"Regexp of volumes to include. Volume name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.VolumeInclude.String()).StringVar(&volumeInclude)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.VolumeExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", volumeExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.logical_disk.volume-exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.VolumeInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", volumeInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.logical_disk.volume-include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"LogicalDisk"}, nil
|
return []string{"LogicalDisk"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.Information = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.information = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||||
"A metric with a constant '1' value labeled with logical disk information",
|
"A metric with a constant '1' value labeled with logical disk information",
|
||||||
[]string{"disk", "type", "volume", "volume_name", "filesystem", "serial_number"},
|
[]string{"disk", "type", "volume", "volume_name", "filesystem", "serial_number"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ReadOnly = prometheus.NewDesc(
|
c.readOnly = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "readonly"),
|
prometheus.BuildFQName(types.Namespace, Name, "readonly"),
|
||||||
"Whether the logical disk is read-only",
|
"Whether the logical disk is read-only",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RequestsQueued = prometheus.NewDesc(
|
c.requestsQueued = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
||||||
"The number of requests queued to the disk (LogicalDisk.CurrentDiskQueueLength)",
|
"The number of requests queued to the disk (LogicalDisk.CurrentDiskQueueLength)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.AvgReadQueue = prometheus.NewDesc(
|
c.avgReadQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "avg_read_requests_queued"),
|
prometheus.BuildFQName(types.Namespace, Name, "avg_read_requests_queued"),
|
||||||
"Average number of read requests that were queued for the selected disk during the sample interval (LogicalDisk.AvgDiskReadQueueLength)",
|
"Average number of read requests that were queued for the selected disk during the sample interval (LogicalDisk.AvgDiskReadQueueLength)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.AvgWriteQueue = prometheus.NewDesc(
|
c.avgWriteQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "avg_write_requests_queued"),
|
prometheus.BuildFQName(types.Namespace, Name, "avg_write_requests_queued"),
|
||||||
"Average number of write requests that were queued for the selected disk during the sample interval (LogicalDisk.AvgDiskWriteQueueLength)",
|
"Average number of write requests that were queued for the selected disk during the sample interval (LogicalDisk.AvgDiskWriteQueueLength)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadBytesTotal = prometheus.NewDesc(
|
c.readBytesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_bytes_total"),
|
||||||
"The number of bytes transferred from the disk during read operations (LogicalDisk.DiskReadBytesPerSec)",
|
"The number of bytes transferred from the disk during read operations (LogicalDisk.DiskReadBytesPerSec)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadsTotal = prometheus.NewDesc(
|
c.readsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "reads_total"),
|
||||||
"The number of read operations on the disk (LogicalDisk.DiskReadsPerSec)",
|
"The number of read operations on the disk (LogicalDisk.DiskReadsPerSec)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WriteBytesTotal = prometheus.NewDesc(
|
c.writeBytesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_bytes_total"),
|
||||||
"The number of bytes transferred to the disk during write operations (LogicalDisk.DiskWriteBytesPerSec)",
|
"The number of bytes transferred to the disk during write operations (LogicalDisk.DiskWriteBytesPerSec)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WritesTotal = prometheus.NewDesc(
|
c.writesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "writes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "writes_total"),
|
||||||
"The number of write operations on the disk (LogicalDisk.DiskWritesPerSec)",
|
"The number of write operations on the disk (LogicalDisk.DiskWritesPerSec)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadTime = prometheus.NewDesc(
|
c.readTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_seconds_total"),
|
||||||
"Seconds that the disk was busy servicing read requests (LogicalDisk.PercentDiskReadTime)",
|
"Seconds that the disk was busy servicing read requests (LogicalDisk.PercentDiskReadTime)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WriteTime = prometheus.NewDesc(
|
c.writeTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_seconds_total"),
|
||||||
"Seconds that the disk was busy servicing write requests (LogicalDisk.PercentDiskWriteTime)",
|
"Seconds that the disk was busy servicing write requests (LogicalDisk.PercentDiskWriteTime)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.FreeSpace = prometheus.NewDesc(
|
c.freeSpace = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "free_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "free_bytes"),
|
||||||
"Free space in bytes, updates every 10-15 min (LogicalDisk.PercentFreeSpace)",
|
"Free space in bytes, updates every 10-15 min (LogicalDisk.PercentFreeSpace)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.TotalSpace = prometheus.NewDesc(
|
c.totalSpace = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "size_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "size_bytes"),
|
||||||
"Total space in bytes, updates every 10-15 min (LogicalDisk.PercentFreeSpace_Base)",
|
"Total space in bytes, updates every 10-15 min (LogicalDisk.PercentFreeSpace_Base)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.IdleTime = prometheus.NewDesc(
|
c.idleTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "idle_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "idle_seconds_total"),
|
||||||
"Seconds that the disk was idle (LogicalDisk.PercentIdleTime)",
|
"Seconds that the disk was idle (LogicalDisk.PercentIdleTime)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.SplitIOs = prometheus.NewDesc(
|
c.splitIOs = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "split_ios_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "split_ios_total"),
|
||||||
"The number of I/Os to the disk were split into multiple I/Os (LogicalDisk.SplitIOPerSec)",
|
"The number of I/Os to the disk were split into multiple I/Os (LogicalDisk.SplitIOPerSec)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadLatency = prometheus.NewDesc(
|
c.readLatency = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_latency_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_latency_seconds_total"),
|
||||||
"Shows the average time, in seconds, of a read operation from the disk (LogicalDisk.AvgDiskSecPerRead)",
|
"Shows the average time, in seconds, of a read operation from the disk (LogicalDisk.AvgDiskSecPerRead)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WriteLatency = prometheus.NewDesc(
|
c.writeLatency = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_latency_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_latency_seconds_total"),
|
||||||
"Shows the average time, in seconds, of a write operation to the disk (LogicalDisk.AvgDiskSecPerWrite)",
|
"Shows the average time, in seconds, of a write operation to the disk (LogicalDisk.AvgDiskSecPerWrite)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadWriteLatency = prometheus.NewDesc(
|
c.readWriteLatency = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_write_latency_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_write_latency_seconds_total"),
|
||||||
"Shows the time, in seconds, of the average disk transfer (LogicalDisk.AvgDiskSecPerTransfer)",
|
"Shows the time, in seconds, of the average disk transfer (LogicalDisk.AvgDiskSecPerTransfer)",
|
||||||
[]string{"volume"},
|
[]string{"volume"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
|
||||||
c.volumeIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.volumeInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.volumeExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.volumeExclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting logical_disk metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting logical_disk metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -266,7 +278,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
// Win32_PerfRawData_PerfDisk_LogicalDisk docs:
|
// Win32_PerfRawData_PerfDisk_LogicalDisk docs:
|
||||||
// - https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71) - Win32_PerfRawData_PerfDisk_LogicalDisk class
|
// - https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71) - Win32_PerfRawData_PerfDisk_LogicalDisk class
|
||||||
// - https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference
|
// - https://msdn.microsoft.com/en-us/library/ms803973.aspx - LogicalDisk object reference.
|
||||||
type logicalDisk struct {
|
type logicalDisk struct {
|
||||||
Name string
|
Name string
|
||||||
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
|
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
|
||||||
@@ -287,7 +299,7 @@ type logicalDisk struct {
|
|||||||
AvgDiskSecPerTransfer float64 `perflib:"Avg. Disk sec/Transfer"`
|
AvgDiskSecPerTransfer float64 `perflib:"Avg. Disk sec/Transfer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
diskID string
|
diskID string
|
||||||
@@ -301,8 +313,8 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
for _, volume := range dst {
|
for _, volume := range dst {
|
||||||
if volume.Name == "_Total" ||
|
if volume.Name == "_Total" ||
|
||||||
c.volumeExcludePattern.MatchString(volume.Name) ||
|
c.config.VolumeExclude.MatchString(volume.Name) ||
|
||||||
!c.volumeIncludePattern.MatchString(volume.Name) {
|
!c.config.VolumeInclude.MatchString(volume.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +329,7 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Information,
|
c.information,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1,
|
1,
|
||||||
diskID,
|
diskID,
|
||||||
@@ -329,112 +341,112 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestsQueued,
|
c.requestsQueued,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
volume.CurrentDiskQueueLength,
|
volume.CurrentDiskQueueLength,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AvgReadQueue,
|
c.avgReadQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
volume.AvgDiskReadQueueLength*perflib.TicksToSecondScaleFactor,
|
volume.AvgDiskReadQueueLength*perflib.TicksToSecondScaleFactor,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AvgWriteQueue,
|
c.avgWriteQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
volume.AvgDiskWriteQueueLength*perflib.TicksToSecondScaleFactor,
|
volume.AvgDiskWriteQueueLength*perflib.TicksToSecondScaleFactor,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadBytesTotal,
|
c.readBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.DiskReadBytesPerSec,
|
volume.DiskReadBytesPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadsTotal,
|
c.readsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.DiskReadsPerSec,
|
volume.DiskReadsPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteBytesTotal,
|
c.writeBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.DiskWriteBytesPerSec,
|
volume.DiskWriteBytesPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WritesTotal,
|
c.writesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.DiskWritesPerSec,
|
volume.DiskWritesPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadTime,
|
c.readTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.PercentDiskReadTime,
|
volume.PercentDiskReadTime,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteTime,
|
c.writeTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.PercentDiskWriteTime,
|
volume.PercentDiskWriteTime,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreeSpace,
|
c.freeSpace,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
volume.PercentFreeSpace_Base*1024*1024,
|
volume.PercentFreeSpace_Base*1024*1024,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalSpace,
|
c.totalSpace,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
volume.PercentFreeSpace*1024*1024,
|
volume.PercentFreeSpace*1024*1024,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IdleTime,
|
c.idleTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.PercentIdleTime,
|
volume.PercentIdleTime,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SplitIOs,
|
c.splitIOs,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.SplitIOPerSec,
|
volume.SplitIOPerSec,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadLatency,
|
c.readLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.AvgDiskSecPerRead*perflib.TicksToSecondScaleFactor,
|
volume.AvgDiskSecPerRead*perflib.TicksToSecondScaleFactor,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteLatency,
|
c.writeLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.AvgDiskSecPerWrite*perflib.TicksToSecondScaleFactor,
|
volume.AvgDiskSecPerWrite*perflib.TicksToSecondScaleFactor,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadWriteLatency,
|
c.readWriteLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
volume.AvgDiskSecPerTransfer*perflib.TicksToSecondScaleFactor,
|
volume.AvgDiskSecPerTransfer*perflib.TicksToSecondScaleFactor,
|
||||||
volume.Name,
|
volume.Name,
|
||||||
@@ -480,7 +492,6 @@ func getDiskIDByVolume(rootDrive string) (string, error) {
|
|||||||
f, err = windows.CreateFile(
|
f, err = windows.CreateFile(
|
||||||
windows.StringToUTF16Ptr(`\\.\`+rootDrive),
|
windows.StringToUTF16Ptr(`\\.\`+rootDrive),
|
||||||
0, mode, nil, windows.OPEN_EXISTING, uint32(windows.FILE_ATTRIBUTE_READONLY), 0)
|
0, mode, nil, windows.OPEN_EXISTING, uint32(windows.FILE_ATTRIBUTE_READONLY), 0)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -529,7 +540,6 @@ func getVolumeInfo(rootDrive string) (volumeInfo, error) {
|
|||||||
|
|
||||||
err := windows.GetVolumeInformation(volPath, &volBufLabel[0], uint32(len(volBufLabel)),
|
err := windows.GetVolumeInformation(volPath, &volBufLabel[0], uint32(len(volBufLabel)),
|
||||||
&volSerialNum, nil, &fsFlags, &volBufType[0], uint32(len(volBufType)))
|
&volSerialNum, nil, &fsFlags, &volBufType[0], uint32(len(volBufType)))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if driveType != windows.DRIVE_CDROM && driveType != windows.DRIVE_REMOVABLE {
|
if driveType != windows.DRIVE_CDROM && driveType != windows.DRIVE_REMOVABLE {
|
||||||
return volumeInfo{}, err
|
return volumeInfo{}, err
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all disks.
|
// Whitelist is not set in testing context (kingpin flags not parsed), causing the Collector to skip all disks.
|
||||||
localVolumeInclude := ".+"
|
localVolumeInclude := ".+"
|
||||||
kingpin.CommandLine.GetArg(logical_disk.FlagLogicalDiskVolumeInclude).StringVar(&localVolumeInclude)
|
kingpin.CommandLine.GetArg("collector.logical_disk.volume-include").StringVar(&localVolumeInclude)
|
||||||
testutils.FuncBenchmarkCollector(b, "logical_disk", logical_disk.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, "logical_disk", logical_disk.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ package logon
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,37 +19,50 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI metrics
|
// A Collector is a Prometheus Collector for WMI metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
LogonType *prometheus.Desc
|
logonType *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.LogonType = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.logonType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "logon_type"),
|
prometheus.BuildFQName(types.Namespace, Name, "logon_type"),
|
||||||
"Number of active logon sessions (LogonSession.LogonType)",
|
"Number of active logon sessions (LogonSession.LogonType)",
|
||||||
[]string{"status"},
|
[]string{"status"},
|
||||||
@@ -61,7 +73,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting user metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting user metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -75,7 +87,7 @@ type Win32_LogonSession struct {
|
|||||||
LogonType uint32
|
LogonType uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_LogonSession
|
var dst []Win32_LogonSession
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -132,91 +144,91 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(system),
|
float64(system),
|
||||||
"system",
|
"system",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(interactive),
|
float64(interactive),
|
||||||
"interactive",
|
"interactive",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(network),
|
float64(network),
|
||||||
"network",
|
"network",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(batch),
|
float64(batch),
|
||||||
"batch",
|
"batch",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(service),
|
float64(service),
|
||||||
"service",
|
"service",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(proxy),
|
float64(proxy),
|
||||||
"proxy",
|
"proxy",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(unlock),
|
float64(unlock),
|
||||||
"unlock",
|
"unlock",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(networkcleartext),
|
float64(networkcleartext),
|
||||||
"network_clear_text",
|
"network_clear_text",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(newcredentials),
|
float64(newcredentials),
|
||||||
"new_credentials",
|
"new_credentials",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(remoteinteractive),
|
float64(remoteinteractive),
|
||||||
"remote_interactive",
|
"remote_interactive",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(cachedinteractive),
|
float64(cachedinteractive),
|
||||||
"cached_interactive",
|
"cached_interactive",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(remoteinteractive),
|
float64(remoteinteractive),
|
||||||
"cached_remote_interactive",
|
"cached_remote_interactive",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LogonType,
|
c.logonType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(cachedunlock),
|
float64(cachedunlock),
|
||||||
"cached_unlock",
|
"cached_unlock",
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
// No context name required as collector source is WMI
|
// No context name required as Collector source is WMI
|
||||||
testutils.FuncBenchmarkCollector(b, logon.Name, logon.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, logon.Name, logon.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,70 +57,68 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/time"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/time"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/vmware"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/vmware"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/vmware_blast"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/vmware_blast"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Map = map[string]types.CollectorBuilderWithFlags{
|
var BuildersWithFlags = map[string]BuilderWithFlags[Collector]{
|
||||||
ad.Name: ad.NewWithFlags,
|
ad.Name: NewBuilderWithFlags(ad.NewWithFlags),
|
||||||
adcs.Name: adcs.NewWithFlags,
|
adcs.Name: NewBuilderWithFlags(adcs.NewWithFlags),
|
||||||
adfs.Name: adfs.NewWithFlags,
|
adfs.Name: NewBuilderWithFlags(adfs.NewWithFlags),
|
||||||
cache.Name: cache.NewWithFlags,
|
cache.Name: NewBuilderWithFlags(cache.NewWithFlags),
|
||||||
container.Name: container.NewWithFlags,
|
container.Name: NewBuilderWithFlags(container.NewWithFlags),
|
||||||
cpu.Name: cpu.NewWithFlags,
|
cpu.Name: NewBuilderWithFlags(cpu.NewWithFlags),
|
||||||
cpu_info.Name: cpu_info.NewWithFlags,
|
cpu_info.Name: NewBuilderWithFlags(cpu_info.NewWithFlags),
|
||||||
cs.Name: cs.NewWithFlags,
|
cs.Name: NewBuilderWithFlags(cs.NewWithFlags),
|
||||||
dfsr.Name: dfsr.NewWithFlags,
|
dfsr.Name: NewBuilderWithFlags(dfsr.NewWithFlags),
|
||||||
dhcp.Name: dhcp.NewWithFlags,
|
dhcp.Name: NewBuilderWithFlags(dhcp.NewWithFlags),
|
||||||
diskdrive.Name: diskdrive.NewWithFlags,
|
diskdrive.Name: NewBuilderWithFlags(diskdrive.NewWithFlags),
|
||||||
dns.Name: dns.NewWithFlags,
|
dns.Name: NewBuilderWithFlags(dns.NewWithFlags),
|
||||||
exchange.Name: exchange.NewWithFlags,
|
exchange.Name: NewBuilderWithFlags(exchange.NewWithFlags),
|
||||||
fsrmquota.Name: fsrmquota.NewWithFlags,
|
fsrmquota.Name: NewBuilderWithFlags(fsrmquota.NewWithFlags),
|
||||||
hyperv.Name: hyperv.NewWithFlags,
|
hyperv.Name: NewBuilderWithFlags(hyperv.NewWithFlags),
|
||||||
iis.Name: iis.NewWithFlags,
|
iis.Name: NewBuilderWithFlags(iis.NewWithFlags),
|
||||||
license.Name: license.NewWithFlags,
|
license.Name: NewBuilderWithFlags(license.NewWithFlags),
|
||||||
logical_disk.Name: logical_disk.NewWithFlags,
|
logical_disk.Name: NewBuilderWithFlags(logical_disk.NewWithFlags),
|
||||||
logon.Name: logon.NewWithFlags,
|
logon.Name: NewBuilderWithFlags(logon.NewWithFlags),
|
||||||
memory.Name: memory.NewWithFlags,
|
memory.Name: NewBuilderWithFlags(memory.NewWithFlags),
|
||||||
mscluster_cluster.Name: mscluster_cluster.NewWithFlags,
|
mscluster_cluster.Name: NewBuilderWithFlags(mscluster_cluster.NewWithFlags),
|
||||||
mscluster_network.Name: mscluster_network.NewWithFlags,
|
mscluster_network.Name: NewBuilderWithFlags(mscluster_network.NewWithFlags),
|
||||||
mscluster_node.Name: mscluster_node.NewWithFlags,
|
mscluster_node.Name: NewBuilderWithFlags(mscluster_node.NewWithFlags),
|
||||||
mscluster_resource.Name: mscluster_resource.NewWithFlags,
|
mscluster_resource.Name: NewBuilderWithFlags(mscluster_resource.NewWithFlags),
|
||||||
mscluster_resourcegroup.Name: mscluster_resourcegroup.NewWithFlags,
|
mscluster_resourcegroup.Name: NewBuilderWithFlags(mscluster_resourcegroup.NewWithFlags),
|
||||||
msmq.Name: msmq.NewWithFlags,
|
msmq.Name: NewBuilderWithFlags(msmq.NewWithFlags),
|
||||||
mssql.Name: mssql.NewWithFlags,
|
mssql.Name: NewBuilderWithFlags(mssql.NewWithFlags),
|
||||||
net.Name: net.NewWithFlags,
|
net.Name: NewBuilderWithFlags(net.NewWithFlags),
|
||||||
netframework_clrexceptions.Name: netframework_clrexceptions.NewWithFlags,
|
netframework_clrexceptions.Name: NewBuilderWithFlags(netframework_clrexceptions.NewWithFlags),
|
||||||
netframework_clrinterop.Name: netframework_clrinterop.NewWithFlags,
|
netframework_clrinterop.Name: NewBuilderWithFlags(netframework_clrinterop.NewWithFlags),
|
||||||
netframework_clrjit.Name: netframework_clrjit.NewWithFlags,
|
netframework_clrjit.Name: NewBuilderWithFlags(netframework_clrjit.NewWithFlags),
|
||||||
netframework_clrloading.Name: netframework_clrloading.NewWithFlags,
|
netframework_clrloading.Name: NewBuilderWithFlags(netframework_clrloading.NewWithFlags),
|
||||||
netframework_clrlocksandthreads.Name: netframework_clrlocksandthreads.NewWithFlags,
|
netframework_clrlocksandthreads.Name: NewBuilderWithFlags(netframework_clrlocksandthreads.NewWithFlags),
|
||||||
netframework_clrmemory.Name: netframework_clrmemory.NewWithFlags,
|
netframework_clrmemory.Name: NewBuilderWithFlags(netframework_clrmemory.NewWithFlags),
|
||||||
netframework_clrremoting.Name: netframework_clrremoting.NewWithFlags,
|
netframework_clrremoting.Name: NewBuilderWithFlags(netframework_clrremoting.NewWithFlags),
|
||||||
netframework_clrsecurity.Name: netframework_clrsecurity.NewWithFlags,
|
netframework_clrsecurity.Name: NewBuilderWithFlags(netframework_clrsecurity.NewWithFlags),
|
||||||
nps.Name: nps.NewWithFlags,
|
nps.Name: NewBuilderWithFlags(nps.NewWithFlags),
|
||||||
os.Name: os.NewWithFlags,
|
os.Name: NewBuilderWithFlags(os.NewWithFlags),
|
||||||
physical_disk.Name: physical_disk.NewWithFlags,
|
physical_disk.Name: NewBuilderWithFlags(physical_disk.NewWithFlags),
|
||||||
printer.Name: printer.NewWithFlags,
|
printer.Name: NewBuilderWithFlags(printer.NewWithFlags),
|
||||||
process.Name: process.NewWithFlags,
|
process.Name: NewBuilderWithFlags(process.NewWithFlags),
|
||||||
remote_fx.Name: remote_fx.NewWithFlags,
|
remote_fx.Name: NewBuilderWithFlags(remote_fx.NewWithFlags),
|
||||||
scheduled_task.Name: scheduled_task.NewWithFlags,
|
scheduled_task.Name: NewBuilderWithFlags(scheduled_task.NewWithFlags),
|
||||||
service.Name: service.NewWithFlags,
|
service.Name: NewBuilderWithFlags(service.NewWithFlags),
|
||||||
smb.Name: smb.NewWithFlags,
|
smb.Name: NewBuilderWithFlags(smb.NewWithFlags),
|
||||||
smbclient.Name: smbclient.NewWithFlags,
|
smbclient.Name: NewBuilderWithFlags(smbclient.NewWithFlags),
|
||||||
smtp.Name: smtp.NewWithFlags,
|
smtp.Name: NewBuilderWithFlags(smtp.NewWithFlags),
|
||||||
system.Name: system.NewWithFlags,
|
system.Name: NewBuilderWithFlags(system.NewWithFlags),
|
||||||
teradici_pcoip.Name: teradici_pcoip.NewWithFlags,
|
teradici_pcoip.Name: NewBuilderWithFlags(teradici_pcoip.NewWithFlags),
|
||||||
tcp.Name: tcp.NewWithFlags,
|
tcp.Name: NewBuilderWithFlags(tcp.NewWithFlags),
|
||||||
terminal_services.Name: terminal_services.NewWithFlags,
|
terminal_services.Name: NewBuilderWithFlags(terminal_services.NewWithFlags),
|
||||||
textfile.Name: textfile.NewWithFlags,
|
textfile.Name: NewBuilderWithFlags(textfile.NewWithFlags),
|
||||||
thermalzone.Name: thermalzone.NewWithFlags,
|
thermalzone.Name: NewBuilderWithFlags(thermalzone.NewWithFlags),
|
||||||
time.Name: time.NewWithFlags,
|
time.Name: NewBuilderWithFlags(time.NewWithFlags),
|
||||||
vmware.Name: vmware.NewWithFlags,
|
vmware.Name: NewBuilderWithFlags(vmware.NewWithFlags),
|
||||||
vmware_blast.Name: vmware_blast.NewWithFlags,
|
vmware_blast.Name: NewBuilderWithFlags(vmware_blast.NewWithFlags),
|
||||||
}
|
}
|
||||||
|
|
||||||
func Available() []string {
|
func Available() []string {
|
||||||
return maps.Keys(Map)
|
return maps.Keys(BuildersWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,266 +20,279 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for perflib Memory metrics
|
// A Collector is a Prometheus Collector for perflib Memory metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
AvailableBytes *prometheus.Desc
|
availableBytes *prometheus.Desc
|
||||||
CacheBytes *prometheus.Desc
|
cacheBytes *prometheus.Desc
|
||||||
CacheBytesPeak *prometheus.Desc
|
cacheBytesPeak *prometheus.Desc
|
||||||
CacheFaultsTotal *prometheus.Desc
|
cacheFaultsTotal *prometheus.Desc
|
||||||
CommitLimit *prometheus.Desc
|
commitLimit *prometheus.Desc
|
||||||
CommittedBytes *prometheus.Desc
|
committedBytes *prometheus.Desc
|
||||||
DemandZeroFaultsTotal *prometheus.Desc
|
demandZeroFaultsTotal *prometheus.Desc
|
||||||
FreeAndZeroPageListBytes *prometheus.Desc
|
freeAndZeroPageListBytes *prometheus.Desc
|
||||||
FreeSystemPageTableEntries *prometheus.Desc
|
freeSystemPageTableEntries *prometheus.Desc
|
||||||
ModifiedPageListBytes *prometheus.Desc
|
modifiedPageListBytes *prometheus.Desc
|
||||||
PageFaultsTotal *prometheus.Desc
|
pageFaultsTotal *prometheus.Desc
|
||||||
SwapPageReadsTotal *prometheus.Desc
|
swapPageReadsTotal *prometheus.Desc
|
||||||
SwapPagesReadTotal *prometheus.Desc
|
swapPagesReadTotal *prometheus.Desc
|
||||||
SwapPagesWrittenTotal *prometheus.Desc
|
swapPagesWrittenTotal *prometheus.Desc
|
||||||
SwapPageOperationsTotal *prometheus.Desc
|
swapPageOperationsTotal *prometheus.Desc
|
||||||
SwapPageWritesTotal *prometheus.Desc
|
swapPageWritesTotal *prometheus.Desc
|
||||||
PoolNonpagedAllocsTotal *prometheus.Desc
|
poolNonPagedAllocationsTotal *prometheus.Desc
|
||||||
PoolNonpagedBytes *prometheus.Desc
|
poolNonPagedBytes *prometheus.Desc
|
||||||
PoolPagedAllocsTotal *prometheus.Desc
|
poolPagedAllocationsTotal *prometheus.Desc
|
||||||
PoolPagedBytes *prometheus.Desc
|
poolPagedBytes *prometheus.Desc
|
||||||
PoolPagedResidentBytes *prometheus.Desc
|
poolPagedResidentBytes *prometheus.Desc
|
||||||
StandbyCacheCoreBytes *prometheus.Desc
|
standbyCacheCoreBytes *prometheus.Desc
|
||||||
StandbyCacheNormalPriorityBytes *prometheus.Desc
|
standbyCacheNormalPriorityBytes *prometheus.Desc
|
||||||
StandbyCacheReserveBytes *prometheus.Desc
|
standbyCacheReserveBytes *prometheus.Desc
|
||||||
SystemCacheResidentBytes *prometheus.Desc
|
systemCacheResidentBytes *prometheus.Desc
|
||||||
SystemCodeResidentBytes *prometheus.Desc
|
systemCodeResidentBytes *prometheus.Desc
|
||||||
SystemCodeTotalBytes *prometheus.Desc
|
systemCodeTotalBytes *prometheus.Desc
|
||||||
SystemDriverResidentBytes *prometheus.Desc
|
systemDriverResidentBytes *prometheus.Desc
|
||||||
SystemDriverTotalBytes *prometheus.Desc
|
systemDriverTotalBytes *prometheus.Desc
|
||||||
TransitionFaultsTotal *prometheus.Desc
|
transitionFaultsTotal *prometheus.Desc
|
||||||
TransitionPagesRepurposedTotal *prometheus.Desc
|
transitionPagesRepurposedTotal *prometheus.Desc
|
||||||
WriteCopiesTotal *prometheus.Desc
|
writeCopiesTotal *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Memory"}, nil
|
return []string{"Memory"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.AvailableBytes = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.availableBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "available_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "available_bytes"),
|
||||||
"The amount of physical memory immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to"+
|
"The amount of physical memory immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to"+
|
||||||
" the standby (cached), free and zero page lists (AvailableBytes)",
|
" the standby (cached), free and zero page lists (AvailableBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CacheBytes = prometheus.NewDesc(
|
c.cacheBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cache_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "cache_bytes"),
|
||||||
"(CacheBytes)",
|
"(CacheBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CacheBytesPeak = prometheus.NewDesc(
|
c.cacheBytesPeak = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cache_bytes_peak"),
|
prometheus.BuildFQName(types.Namespace, Name, "cache_bytes_peak"),
|
||||||
"(CacheBytesPeak)",
|
"(CacheBytesPeak)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CacheFaultsTotal = prometheus.NewDesc(
|
c.cacheFaultsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cache_faults_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cache_faults_total"),
|
||||||
"Number of faults which occur when a page sought in the file system cache is not found there and must be retrieved from elsewhere in memory (soft fault) "+
|
"Number of faults which occur when a page sought in the file system cache is not found there and must be retrieved from elsewhere in memory (soft fault) "+
|
||||||
"or from disk (hard fault) (Cache Faults/sec)",
|
"or from disk (hard fault) (Cache Faults/sec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CommitLimit = prometheus.NewDesc(
|
c.commitLimit = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "commit_limit"),
|
prometheus.BuildFQName(types.Namespace, Name, "commit_limit"),
|
||||||
"(CommitLimit)",
|
"(CommitLimit)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CommittedBytes = prometheus.NewDesc(
|
c.committedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "committed_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "committed_bytes"),
|
||||||
"(CommittedBytes)",
|
"(CommittedBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DemandZeroFaultsTotal = prometheus.NewDesc(
|
c.demandZeroFaultsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "demand_zero_faults_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "demand_zero_faults_total"),
|
||||||
"The number of zeroed pages required to satisfy faults. Zeroed pages, pages emptied of previously stored data and filled with zeros, are a security"+
|
"The number of zeroed pages required to satisfy faults. Zeroed pages, pages emptied of previously stored data and filled with zeros, are a security"+
|
||||||
" feature of Windows that prevent processes from seeing data stored by earlier processes that used the memory space (Demand Zero Faults/sec)",
|
" feature of Windows that prevent processes from seeing data stored by earlier processes that used the memory space (Demand Zero Faults/sec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FreeAndZeroPageListBytes = prometheus.NewDesc(
|
c.freeAndZeroPageListBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "free_and_zero_page_list_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "free_and_zero_page_list_bytes"),
|
||||||
"The amount of physical memory, in bytes, that is assigned to the free and zero page lists. This memory does not contain cached data. It is immediately"+
|
"The amount of physical memory, in bytes, that is assigned to the free and zero page lists. This memory does not contain cached data. It is immediately"+
|
||||||
" available for allocation to a process or for system use (FreeAndZeroPageListBytes)",
|
" available for allocation to a process or for system use (FreeAndZeroPageListBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FreeSystemPageTableEntries = prometheus.NewDesc(
|
c.freeSystemPageTableEntries = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "free_system_page_table_entries"),
|
prometheus.BuildFQName(types.Namespace, Name, "free_system_page_table_entries"),
|
||||||
"(FreeSystemPageTableEntries)",
|
"(FreeSystemPageTableEntries)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ModifiedPageListBytes = prometheus.NewDesc(
|
c.modifiedPageListBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "modified_page_list_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "modified_page_list_bytes"),
|
||||||
"The amount of physical memory, in bytes, that is assigned to the modified page list. This memory contains cached data and code that is not actively in "+
|
"The amount of physical memory, in bytes, that is assigned to the modified page list. This memory contains cached data and code that is not actively in "+
|
||||||
"use by processes, the system and the system cache (ModifiedPageListBytes)",
|
"use by processes, the system and the system cache (ModifiedPageListBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PageFaultsTotal = prometheus.NewDesc(
|
c.pageFaultsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "page_faults_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "page_faults_total"),
|
||||||
"Overall rate at which faulted pages are handled by the processor (Page Faults/sec)",
|
"Overall rate at which faulted pages are handled by the processor (Page Faults/sec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SwapPageReadsTotal = prometheus.NewDesc(
|
c.swapPageReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "swap_page_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "swap_page_reads_total"),
|
||||||
"Number of disk page reads (a single read operation reading several pages is still only counted once) (PageReadsPersec)",
|
"Number of disk page reads (a single read operation reading several pages is still only counted once) (PageReadsPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SwapPagesReadTotal = prometheus.NewDesc(
|
c.swapPagesReadTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "swap_pages_read_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "swap_pages_read_total"),
|
||||||
"Number of pages read across all page reads (ie counting all pages read even if they are read in a single operation) (PagesInputPersec)",
|
"Number of pages read across all page reads (ie counting all pages read even if they are read in a single operation) (PagesInputPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SwapPagesWrittenTotal = prometheus.NewDesc(
|
c.swapPagesWrittenTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "swap_pages_written_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "swap_pages_written_total"),
|
||||||
"Number of pages written across all page writes (ie counting all pages written even if they are written in a single operation) (PagesOutputPersec)",
|
"Number of pages written across all page writes (ie counting all pages written even if they are written in a single operation) (PagesOutputPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SwapPageOperationsTotal = prometheus.NewDesc(
|
c.swapPageOperationsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "swap_page_operations_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "swap_page_operations_total"),
|
||||||
"Total number of swap page read and writes (PagesPersec)",
|
"Total number of swap page read and writes (PagesPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SwapPageWritesTotal = prometheus.NewDesc(
|
c.swapPageWritesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "swap_page_writes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "swap_page_writes_total"),
|
||||||
"Number of disk page writes (a single write operation writing several pages is still only counted once) (PageWritesPersec)",
|
"Number of disk page writes (a single write operation writing several pages is still only counted once) (PageWritesPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolNonpagedAllocsTotal = prometheus.NewDesc(
|
c.poolNonPagedAllocationsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_nonpaged_allocs_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_nonpaged_allocs_total"),
|
||||||
"The number of calls to allocate space in the nonpaged pool. The nonpaged pool is an area of system memory area for objects that cannot be written"+
|
"The number of calls to allocate space in the nonpaged pool. The nonpaged pool is an area of system memory area for objects that cannot be written"+
|
||||||
" to disk, and must remain in physical memory as long as they are allocated (PoolNonpagedAllocs)",
|
" to disk, and must remain in physical memory as long as they are allocated (PoolNonpagedAllocs)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolNonpagedBytes = prometheus.NewDesc(
|
c.poolNonPagedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_nonpaged_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_nonpaged_bytes"),
|
||||||
"Number of bytes in the non-paged pool, an area of the system virtual memory that is used for objects that cannot be written to disk, but must "+
|
"Number of bytes in the non-paged pool, an area of the system virtual memory that is used for objects that cannot be written to disk, but must "+
|
||||||
"remain in physical memory as long as they are allocated (PoolNonpagedBytes)",
|
"remain in physical memory as long as they are allocated (PoolNonpagedBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolPagedAllocsTotal = prometheus.NewDesc(
|
c.poolPagedAllocationsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_allocs_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_allocs_total"),
|
||||||
"Number of calls to allocate space in the paged pool, regardless of the amount of space allocated in each call (PoolPagedAllocs)",
|
"Number of calls to allocate space in the paged pool, regardless of the amount of space allocated in each call (PoolPagedAllocs)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolPagedBytes = prometheus.NewDesc(
|
c.poolPagedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_bytes"),
|
||||||
"(PoolPagedBytes)",
|
"(PoolPagedBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolPagedResidentBytes = prometheus.NewDesc(
|
c.poolPagedResidentBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_resident_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_resident_bytes"),
|
||||||
"The size, in bytes, of the portion of the paged pool that is currently resident and active in physical memory. The paged pool is an area of the "+
|
"The size, in bytes, of the portion of the paged pool that is currently resident and active in physical memory. The paged pool is an area of the "+
|
||||||
"system virtual memory that is used for objects that can be written to disk when they are not being used (PoolPagedResidentBytes)",
|
"system virtual memory that is used for objects that can be written to disk when they are not being used (PoolPagedResidentBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.StandbyCacheCoreBytes = prometheus.NewDesc(
|
c.standbyCacheCoreBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "standby_cache_core_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "standby_cache_core_bytes"),
|
||||||
"The amount of physical memory, in bytes, that is assigned to the core standby cache page lists. This memory contains cached data and code that is "+
|
"The amount of physical memory, in bytes, that is assigned to the core standby cache page lists. This memory contains cached data and code that is "+
|
||||||
"not actively in use by processes, the system and the system cache (StandbyCacheCoreBytes)",
|
"not actively in use by processes, the system and the system cache (StandbyCacheCoreBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.StandbyCacheNormalPriorityBytes = prometheus.NewDesc(
|
c.standbyCacheNormalPriorityBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "standby_cache_normal_priority_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "standby_cache_normal_priority_bytes"),
|
||||||
"The amount of physical memory, in bytes, that is assigned to the normal priority standby cache page lists. This memory contains cached data and "+
|
"The amount of physical memory, in bytes, that is assigned to the normal priority standby cache page lists. This memory contains cached data and "+
|
||||||
"code that is not actively in use by processes, the system and the system cache (StandbyCacheNormalPriorityBytes)",
|
"code that is not actively in use by processes, the system and the system cache (StandbyCacheNormalPriorityBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.StandbyCacheReserveBytes = prometheus.NewDesc(
|
c.standbyCacheReserveBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "standby_cache_reserve_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "standby_cache_reserve_bytes"),
|
||||||
"The amount of physical memory, in bytes, that is assigned to the reserve standby cache page lists. This memory contains cached data and code "+
|
"The amount of physical memory, in bytes, that is assigned to the reserve standby cache page lists. This memory contains cached data and code "+
|
||||||
"that is not actively in use by processes, the system and the system cache (StandbyCacheReserveBytes)",
|
"that is not actively in use by processes, the system and the system cache (StandbyCacheReserveBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemCacheResidentBytes = prometheus.NewDesc(
|
c.systemCacheResidentBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_cache_resident_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_cache_resident_bytes"),
|
||||||
"The size, in bytes, of the portion of the system file cache which is currently resident and active in physical memory (SystemCacheResidentBytes)",
|
"The size, in bytes, of the portion of the system file cache which is currently resident and active in physical memory (SystemCacheResidentBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemCodeResidentBytes = prometheus.NewDesc(
|
c.systemCodeResidentBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_code_resident_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_code_resident_bytes"),
|
||||||
"The size, in bytes, of the pageable operating system code that is currently resident and active in physical memory (SystemCodeResidentBytes)",
|
"The size, in bytes, of the pageable operating system code that is currently resident and active in physical memory (SystemCodeResidentBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemCodeTotalBytes = prometheus.NewDesc(
|
c.systemCodeTotalBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_code_total_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_code_total_bytes"),
|
||||||
"The size, in bytes, of the pageable operating system code currently mapped into the system virtual address space (SystemCodeTotalBytes)",
|
"The size, in bytes, of the pageable operating system code currently mapped into the system virtual address space (SystemCodeTotalBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemDriverResidentBytes = prometheus.NewDesc(
|
c.systemDriverResidentBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_driver_resident_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_driver_resident_bytes"),
|
||||||
"The size, in bytes, of the pageable physical memory being used by device drivers. It is the working set (physical memory area) of the drivers (SystemDriverResidentBytes)",
|
"The size, in bytes, of the pageable physical memory being used by device drivers. It is the working set (physical memory area) of the drivers (SystemDriverResidentBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemDriverTotalBytes = prometheus.NewDesc(
|
c.systemDriverTotalBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_driver_total_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_driver_total_bytes"),
|
||||||
"The size, in bytes, of the pageable virtual memory currently being used by device drivers. Pageable memory can be written to disk when it is not being used (SystemDriverTotalBytes)",
|
"The size, in bytes, of the pageable virtual memory currently being used by device drivers. Pageable memory can be written to disk when it is not being used (SystemDriverTotalBytes)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TransitionFaultsTotal = prometheus.NewDesc(
|
c.transitionFaultsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "transition_faults_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "transition_faults_total"),
|
||||||
"Number of faults rate at which page faults are resolved by recovering pages that were being used by another process sharing the page, or were on the "+
|
"Number of faults rate at which page faults are resolved by recovering pages that were being used by another process sharing the page, or were on the "+
|
||||||
"modified page list or the standby list, or were being written to disk at the time of the page fault (TransitionFaultsPersec)",
|
"modified page list or the standby list, or were being written to disk at the time of the page fault (TransitionFaultsPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TransitionPagesRepurposedTotal = prometheus.NewDesc(
|
c.transitionPagesRepurposedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "transition_pages_repurposed_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "transition_pages_repurposed_total"),
|
||||||
"Transition Pages RePurposed is the rate at which the number of transition cache pages were reused for a different purpose (TransitionPagesRePurposedPersec)",
|
"Transition Pages RePurposed is the rate at which the number of transition cache pages were reused for a different purpose (TransitionPagesRePurposedPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WriteCopiesTotal = prometheus.NewDesc(
|
c.writeCopiesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_copies_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_copies_total"),
|
||||||
"The number of page faults caused by attempting to write that were satisfied by copying the page from elsewhere in physical memory (WriteCopiesPersec)",
|
"The number of page faults caused by attempting to write that were satisfied by copying the page from elsewhere in physical memory (WriteCopiesPersec)",
|
||||||
nil,
|
nil,
|
||||||
@@ -290,7 +303,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting memory metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting memory metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -335,200 +348,200 @@ type memory struct {
|
|||||||
WriteCopiesPersec float64 `perflib:"Write Copies/sec"`
|
WriteCopiesPersec float64 `perflib:"Write Copies/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []memory
|
var dst []memory
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["Memory"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["Memory"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AvailableBytes,
|
c.availableBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].AvailableBytes,
|
dst[0].AvailableBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CacheBytes,
|
c.cacheBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].CacheBytes,
|
dst[0].CacheBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CacheBytesPeak,
|
c.cacheBytesPeak,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].CacheBytesPeak,
|
dst[0].CacheBytesPeak,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CacheFaultsTotal,
|
c.cacheFaultsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].CacheFaultsPersec,
|
dst[0].CacheFaultsPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CommitLimit,
|
c.commitLimit,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].CommitLimit,
|
dst[0].CommitLimit,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CommittedBytes,
|
c.committedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].CommittedBytes,
|
dst[0].CommittedBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DemandZeroFaultsTotal,
|
c.demandZeroFaultsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].DemandZeroFaultsPersec,
|
dst[0].DemandZeroFaultsPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreeAndZeroPageListBytes,
|
c.freeAndZeroPageListBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].FreeAndZeroPageListBytes,
|
dst[0].FreeAndZeroPageListBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FreeSystemPageTableEntries,
|
c.freeSystemPageTableEntries,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].FreeSystemPageTableEntries,
|
dst[0].FreeSystemPageTableEntries,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ModifiedPageListBytes,
|
c.modifiedPageListBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].ModifiedPageListBytes,
|
dst[0].ModifiedPageListBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PageFaultsTotal,
|
c.pageFaultsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PageFaultsPersec,
|
dst[0].PageFaultsPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SwapPageReadsTotal,
|
c.swapPageReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PageReadsPersec,
|
dst[0].PageReadsPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SwapPagesReadTotal,
|
c.swapPagesReadTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PagesInputPersec,
|
dst[0].PagesInputPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SwapPagesWrittenTotal,
|
c.swapPagesWrittenTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PagesOutputPersec,
|
dst[0].PagesOutputPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SwapPageOperationsTotal,
|
c.swapPageOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PagesPersec,
|
dst[0].PagesPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SwapPageWritesTotal,
|
c.swapPageWritesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PageWritesPersec,
|
dst[0].PageWritesPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolNonpagedAllocsTotal,
|
c.poolNonPagedAllocationsTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].PoolNonpagedAllocs,
|
dst[0].PoolNonpagedAllocs,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolNonpagedBytes,
|
c.poolNonPagedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].PoolNonpagedBytes,
|
dst[0].PoolNonpagedBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolPagedAllocsTotal,
|
c.poolPagedAllocationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PoolPagedAllocs,
|
dst[0].PoolPagedAllocs,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolPagedBytes,
|
c.poolPagedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].PoolPagedBytes,
|
dst[0].PoolPagedBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolPagedResidentBytes,
|
c.poolPagedResidentBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].PoolPagedResidentBytes,
|
dst[0].PoolPagedResidentBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StandbyCacheCoreBytes,
|
c.standbyCacheCoreBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].StandbyCacheCoreBytes,
|
dst[0].StandbyCacheCoreBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StandbyCacheNormalPriorityBytes,
|
c.standbyCacheNormalPriorityBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].StandbyCacheNormalPriorityBytes,
|
dst[0].StandbyCacheNormalPriorityBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StandbyCacheReserveBytes,
|
c.standbyCacheReserveBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].StandbyCacheReserveBytes,
|
dst[0].StandbyCacheReserveBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemCacheResidentBytes,
|
c.systemCacheResidentBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].SystemCacheResidentBytes,
|
dst[0].SystemCacheResidentBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemCodeResidentBytes,
|
c.systemCodeResidentBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].SystemCodeResidentBytes,
|
dst[0].SystemCodeResidentBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemCodeTotalBytes,
|
c.systemCodeTotalBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].SystemCodeTotalBytes,
|
dst[0].SystemCodeTotalBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemDriverResidentBytes,
|
c.systemDriverResidentBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].SystemDriverResidentBytes,
|
dst[0].SystemDriverResidentBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemDriverTotalBytes,
|
c.systemDriverTotalBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].SystemDriverTotalBytes,
|
dst[0].SystemDriverTotalBytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TransitionFaultsTotal,
|
c.transitionFaultsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].TransitionFaultsPersec,
|
dst[0].TransitionFaultsPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TransitionPagesRepurposedTotal,
|
c.transitionPagesRepurposedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].TransitionPagesRePurposedPersec,
|
dst[0].TransitionPagesRePurposedPersec,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteCopiesTotal,
|
c.writeCopiesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].WriteCopiesPersec,
|
dst[0].WriteCopiesPersec,
|
||||||
)
|
)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,10 @@
|
|||||||
package mscluster_network
|
package mscluster_network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,65 +14,78 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI MSCluster_Network metrics
|
// A Collector is a Prometheus Collector for WMI MSCluster_Network metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
Characteristics *prometheus.Desc
|
characteristics *prometheus.Desc
|
||||||
Flags *prometheus.Desc
|
flags *prometheus.Desc
|
||||||
Metric *prometheus.Desc
|
metric *prometheus.Desc
|
||||||
Role *prometheus.Desc
|
role *prometheus.Desc
|
||||||
State *prometheus.Desc
|
state *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Memory"}, nil
|
return []string{"Memory"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.Characteristics = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.characteristics = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
||||||
"Provides the characteristics of the network.",
|
"Provides the characteristics of the network.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Flags = prometheus.NewDesc(
|
c.flags = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
||||||
"Provides access to the flags set for the node. ",
|
"Provides access to the flags set for the node. ",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Metric = prometheus.NewDesc(
|
c.metric = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "metric"),
|
prometheus.BuildFQName(types.Namespace, Name, "metric"),
|
||||||
"The metric of a cluster network (networks with lower values are used first). If this value is set, then the AutoMetric property is set to false.",
|
"The metric of a cluster network (networks with lower values are used first). If this value is set, then the AutoMetric property is set to false.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Role = prometheus.NewDesc(
|
c.role = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "role"),
|
prometheus.BuildFQName(types.Namespace, Name, "role"),
|
||||||
"Provides access to the network's Role property. The Role property describes the role of the network in the cluster. 0: None; 1: Cluster; 2: Client; 3: Both ",
|
"Provides access to the network's Role property. The Role property describes the role of the network in the cluster. 0: None; 1: Cluster; 2: Client; 3: Both ",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.State = prometheus.NewDesc(
|
c.state = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
||||||
"Provides the current state of the network. 1-1: Unknown; 0: Unavailable; 1: Down; 2: Partitioned; 3: Up",
|
"Provides the current state of the network. 1-1: Unknown; 0: Unavailable; 1: Down; 2: Partitioned; 3: Up",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
@@ -95,8 +107,8 @@ type MSCluster_Network struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []MSCluster_Network
|
var dst []MSCluster_Network
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
||||||
@@ -105,35 +117,35 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
|
|
||||||
for _, v := range dst {
|
for _, v := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Characteristics,
|
c.characteristics,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Characteristics),
|
float64(v.Characteristics),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Flags,
|
c.flags,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Flags),
|
float64(v.Flags),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Metric,
|
c.metric,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Metric),
|
float64(v.Metric),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Role,
|
c.role,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Role),
|
float64(v.Role),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.State,
|
c.state,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.State),
|
float64(v.State),
|
||||||
v.Name,
|
v.Name,
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package mscluster_node
|
package mscluster_node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,131 +14,144 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// Variable used by mscluster_resource and mscluster_resourcegroup
|
// Variable used by mscluster_resource and mscluster_resourcegroup.
|
||||||
var NodeName []string
|
var NodeName []string
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI MSCluster_Node metrics
|
// A Collector is a Prometheus Collector for WMI MSCluster_Node metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
BuildNumber *prometheus.Desc
|
buildNumber *prometheus.Desc
|
||||||
Characteristics *prometheus.Desc
|
characteristics *prometheus.Desc
|
||||||
DetectedCloudPlatform *prometheus.Desc
|
detectedCloudPlatform *prometheus.Desc
|
||||||
DynamicWeight *prometheus.Desc
|
dynamicWeight *prometheus.Desc
|
||||||
Flags *prometheus.Desc
|
flags *prometheus.Desc
|
||||||
MajorVersion *prometheus.Desc
|
majorVersion *prometheus.Desc
|
||||||
MinorVersion *prometheus.Desc
|
minorVersion *prometheus.Desc
|
||||||
NeedsPreventQuorum *prometheus.Desc
|
needsPreventQuorum *prometheus.Desc
|
||||||
NodeDrainStatus *prometheus.Desc
|
nodeDrainStatus *prometheus.Desc
|
||||||
NodeHighestVersion *prometheus.Desc
|
nodeHighestVersion *prometheus.Desc
|
||||||
NodeLowestVersion *prometheus.Desc
|
nodeLowestVersion *prometheus.Desc
|
||||||
NodeWeight *prometheus.Desc
|
nodeWeight *prometheus.Desc
|
||||||
State *prometheus.Desc
|
state *prometheus.Desc
|
||||||
StatusInformation *prometheus.Desc
|
statusInformation *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Memory"}, nil
|
return []string{"Memory"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.BuildNumber = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.buildNumber = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "build_number"),
|
prometheus.BuildFQName(types.Namespace, Name, "build_number"),
|
||||||
"Provides access to the node's BuildNumber property.",
|
"Provides access to the node's BuildNumber property.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Characteristics = prometheus.NewDesc(
|
c.characteristics = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
||||||
"Provides access to the characteristics set for the node.",
|
"Provides access to the characteristics set for the node.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DetectedCloudPlatform = prometheus.NewDesc(
|
c.detectedCloudPlatform = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "detected_cloud_platform"),
|
prometheus.BuildFQName(types.Namespace, Name, "detected_cloud_platform"),
|
||||||
"(DetectedCloudPlatform)",
|
"(DetectedCloudPlatform)",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DynamicWeight = prometheus.NewDesc(
|
c.dynamicWeight = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dynamic_weight"),
|
prometheus.BuildFQName(types.Namespace, Name, "dynamic_weight"),
|
||||||
"The dynamic vote weight of the node adjusted by dynamic quorum feature.",
|
"The dynamic vote weight of the node adjusted by dynamic quorum feature.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Flags = prometheus.NewDesc(
|
c.flags = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
||||||
"Provides access to the flags set for the node.",
|
"Provides access to the flags set for the node.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MajorVersion = prometheus.NewDesc(
|
c.majorVersion = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "major_version"),
|
prometheus.BuildFQName(types.Namespace, Name, "major_version"),
|
||||||
"Provides access to the node's MajorVersion property, which specifies the major portion of the Windows version installed.",
|
"Provides access to the node's MajorVersion property, which specifies the major portion of the Windows version installed.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MinorVersion = prometheus.NewDesc(
|
c.minorVersion = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "minor_version"),
|
prometheus.BuildFQName(types.Namespace, Name, "minor_version"),
|
||||||
"Provides access to the node's MinorVersion property, which specifies the minor portion of the Windows version installed.",
|
"Provides access to the node's MinorVersion property, which specifies the minor portion of the Windows version installed.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NeedsPreventQuorum = prometheus.NewDesc(
|
c.needsPreventQuorum = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "needs_prevent_quorum"),
|
prometheus.BuildFQName(types.Namespace, Name, "needs_prevent_quorum"),
|
||||||
"Whether the cluster service on that node should be started with prevent quorum flag.",
|
"Whether the cluster service on that node should be started with prevent quorum flag.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NodeDrainStatus = prometheus.NewDesc(
|
c.nodeDrainStatus = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "node_drain_status"),
|
prometheus.BuildFQName(types.Namespace, Name, "node_drain_status"),
|
||||||
"The current node drain status of a node. 0: Not Initiated; 1: In Progress; 2: Completed; 3: Failed",
|
"The current node drain status of a node. 0: Not Initiated; 1: In Progress; 2: Completed; 3: Failed",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NodeHighestVersion = prometheus.NewDesc(
|
c.nodeHighestVersion = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "node_highest_version"),
|
prometheus.BuildFQName(types.Namespace, Name, "node_highest_version"),
|
||||||
"Provides access to the node's NodeHighestVersion property, which specifies the highest possible version of the cluster service with which the node can join or communicate.",
|
"Provides access to the node's NodeHighestVersion property, which specifies the highest possible version of the cluster service with which the node can join or communicate.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NodeLowestVersion = prometheus.NewDesc(
|
c.nodeLowestVersion = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "node_lowest_version"),
|
prometheus.BuildFQName(types.Namespace, Name, "node_lowest_version"),
|
||||||
"Provides access to the node's NodeLowestVersion property, which specifies the lowest possible version of the cluster service with which the node can join or communicate.",
|
"Provides access to the node's NodeLowestVersion property, which specifies the lowest possible version of the cluster service with which the node can join or communicate.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NodeWeight = prometheus.NewDesc(
|
c.nodeWeight = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "node_weight"),
|
prometheus.BuildFQName(types.Namespace, Name, "node_weight"),
|
||||||
"The vote weight of the node.",
|
"The vote weight of the node.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.State = prometheus.NewDesc(
|
c.state = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
||||||
"Returns the current state of a node. -1: Unknown; 0: Up; 1: Down; 2: Paused; 3: Joining",
|
"Returns the current state of a node. -1: Unknown; 0: Up; 1: Down; 2: Paused; 3: Joining",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.StatusInformation = prometheus.NewDesc(
|
c.statusInformation = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "status_information"),
|
prometheus.BuildFQName(types.Namespace, Name, "status_information"),
|
||||||
"The isolation or quarantine status of the node.",
|
"The isolation or quarantine status of the node.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
@@ -171,7 +183,7 @@ type MSCluster_Node struct {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []MSCluster_Node
|
var dst []MSCluster_Node
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
||||||
@@ -181,100 +193,99 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
NodeName = []string{}
|
NodeName = []string{}
|
||||||
|
|
||||||
for _, v := range dst {
|
for _, v := range dst {
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BuildNumber,
|
c.buildNumber,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.BuildNumber),
|
float64(v.BuildNumber),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Characteristics,
|
c.characteristics,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Characteristics),
|
float64(v.Characteristics),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DetectedCloudPlatform,
|
c.detectedCloudPlatform,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.DetectedCloudPlatform),
|
float64(v.DetectedCloudPlatform),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DynamicWeight,
|
c.dynamicWeight,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.DynamicWeight),
|
float64(v.DynamicWeight),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Flags,
|
c.flags,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Flags),
|
float64(v.Flags),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MajorVersion,
|
c.majorVersion,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.MajorVersion),
|
float64(v.MajorVersion),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MinorVersion,
|
c.minorVersion,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.MinorVersion),
|
float64(v.MinorVersion),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NeedsPreventQuorum,
|
c.needsPreventQuorum,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.NeedsPreventQuorum),
|
float64(v.NeedsPreventQuorum),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NodeDrainStatus,
|
c.nodeDrainStatus,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.NodeDrainStatus),
|
float64(v.NodeDrainStatus),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NodeHighestVersion,
|
c.nodeHighestVersion,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.NodeHighestVersion),
|
float64(v.NodeHighestVersion),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NodeLowestVersion,
|
c.nodeLowestVersion,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.NodeLowestVersion),
|
float64(v.NodeLowestVersion),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NodeWeight,
|
c.nodeWeight,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.NodeWeight),
|
float64(v.NodeWeight),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.State,
|
c.state,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.State),
|
float64(v.State),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StatusInformation,
|
c.statusInformation,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.StatusInformation),
|
float64(v.StatusInformation),
|
||||||
v.Name,
|
v.Name,
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package mscluster_resource
|
package mscluster_resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/alecthomas/kingpin/v2"
|
||||||
|
"github.com/go-kit/log"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/mscluster_node"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/mscluster_node"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,155 +15,168 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI MSCluster_Resource metrics
|
// A Collector is a Prometheus Collector for WMI MSCluster_Resource metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
Characteristics *prometheus.Desc
|
characteristics *prometheus.Desc
|
||||||
DeadlockTimeout *prometheus.Desc
|
deadlockTimeout *prometheus.Desc
|
||||||
EmbeddedFailureAction *prometheus.Desc
|
embeddedFailureAction *prometheus.Desc
|
||||||
Flags *prometheus.Desc
|
flags *prometheus.Desc
|
||||||
IsAlivePollInterval *prometheus.Desc
|
isAlivePollInterval *prometheus.Desc
|
||||||
LooksAlivePollInterval *prometheus.Desc
|
looksAlivePollInterval *prometheus.Desc
|
||||||
MonitorProcessId *prometheus.Desc
|
monitorProcessId *prometheus.Desc
|
||||||
OwnerNode *prometheus.Desc
|
ownerNode *prometheus.Desc
|
||||||
PendingTimeout *prometheus.Desc
|
pendingTimeout *prometheus.Desc
|
||||||
ResourceClass *prometheus.Desc
|
resourceClass *prometheus.Desc
|
||||||
RestartAction *prometheus.Desc
|
restartAction *prometheus.Desc
|
||||||
RestartDelay *prometheus.Desc
|
restartDelay *prometheus.Desc
|
||||||
RestartPeriod *prometheus.Desc
|
restartPeriod *prometheus.Desc
|
||||||
RestartThreshold *prometheus.Desc
|
restartThreshold *prometheus.Desc
|
||||||
RetryPeriodOnFailure *prometheus.Desc
|
retryPeriodOnFailure *prometheus.Desc
|
||||||
State *prometheus.Desc
|
state *prometheus.Desc
|
||||||
Subclass *prometheus.Desc
|
subclass *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Memory"}, nil
|
return []string{"Memory"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.Characteristics = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.characteristics = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
||||||
"Provides the characteristics of the object.",
|
"Provides the characteristics of the object.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DeadlockTimeout = prometheus.NewDesc(
|
c.deadlockTimeout = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "deadlock_timeout"),
|
prometheus.BuildFQName(types.Namespace, Name, "deadlock_timeout"),
|
||||||
"Indicates the length of time to wait, in milliseconds, before declaring a deadlock in any call into a resource.",
|
"Indicates the length of time to wait, in milliseconds, before declaring a deadlock in any call into a resource.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.EmbeddedFailureAction = prometheus.NewDesc(
|
c.embeddedFailureAction = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "embedded_failure_action"),
|
prometheus.BuildFQName(types.Namespace, Name, "embedded_failure_action"),
|
||||||
"The time, in milliseconds, that a resource should remain in a failed state before the Cluster service attempts to restart it.",
|
"The time, in milliseconds, that a resource should remain in a failed state before the Cluster service attempts to restart it.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Flags = prometheus.NewDesc(
|
c.flags = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
||||||
"Provides access to the flags set for the object.",
|
"Provides access to the flags set for the object.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.IsAlivePollInterval = prometheus.NewDesc(
|
c.isAlivePollInterval = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "is_alive_poll_interval"),
|
prometheus.BuildFQName(types.Namespace, Name, "is_alive_poll_interval"),
|
||||||
"Provides access to the resource's IsAlivePollInterval property, which is the recommended interval in milliseconds at which the Cluster Service should poll the resource to determine whether it is operational. If the property is set to 0xFFFFFFFF, the Cluster Service uses the IsAlivePollInterval property for the resource type associated with the resource.",
|
"Provides access to the resource's IsAlivePollInterval property, which is the recommended interval in milliseconds at which the Cluster Service should poll the resource to determine whether it is operational. If the property is set to 0xFFFFFFFF, the Cluster Service uses the IsAlivePollInterval property for the resource type associated with the resource.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.LooksAlivePollInterval = prometheus.NewDesc(
|
c.looksAlivePollInterval = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "looks_alive_poll_interval"),
|
prometheus.BuildFQName(types.Namespace, Name, "looks_alive_poll_interval"),
|
||||||
"Provides access to the resource's LooksAlivePollInterval property, which is the recommended interval in milliseconds at which the Cluster Service should poll the resource to determine whether it appears operational. If the property is set to 0xFFFFFFFF, the Cluster Service uses the LooksAlivePollInterval property for the resource type associated with the resource.",
|
"Provides access to the resource's LooksAlivePollInterval property, which is the recommended interval in milliseconds at which the Cluster Service should poll the resource to determine whether it appears operational. If the property is set to 0xFFFFFFFF, the Cluster Service uses the LooksAlivePollInterval property for the resource type associated with the resource.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MonitorProcessId = prometheus.NewDesc(
|
c.monitorProcessId = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "monitor_process_id"),
|
prometheus.BuildFQName(types.Namespace, Name, "monitor_process_id"),
|
||||||
"Provides the process ID of the resource host service that is currently hosting the resource.",
|
"Provides the process ID of the resource host service that is currently hosting the resource.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OwnerNode = prometheus.NewDesc(
|
c.ownerNode = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
||||||
"The node hosting the resource. 0: Not hosted; 1: Hosted",
|
"The node hosting the resource. 0: Not hosted; 1: Hosted",
|
||||||
[]string{"type", "owner_group", "node_name", "name"},
|
[]string{"type", "owner_group", "node_name", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OwnerNode = prometheus.NewDesc(
|
c.ownerNode = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
||||||
"The node hosting the resource. 0: Not hosted; 1: Hosted",
|
"The node hosting the resource. 0: Not hosted; 1: Hosted",
|
||||||
[]string{"type", "owner_group", "node_name", "name"},
|
[]string{"type", "owner_group", "node_name", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PendingTimeout = prometheus.NewDesc(
|
c.pendingTimeout = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pending_timeout"),
|
prometheus.BuildFQName(types.Namespace, Name, "pending_timeout"),
|
||||||
"Provides access to the resource's PendingTimeout property. If a resource cannot be brought online or taken offline in the number of milliseconds specified by the PendingTimeout property, the resource is forcibly terminated.",
|
"Provides access to the resource's PendingTimeout property. If a resource cannot be brought online or taken offline in the number of milliseconds specified by the PendingTimeout property, the resource is forcibly terminated.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ResourceClass = prometheus.NewDesc(
|
c.resourceClass = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "resource_class"),
|
prometheus.BuildFQName(types.Namespace, Name, "resource_class"),
|
||||||
"Gets or sets the resource class of a resource. 0: Unknown; 1: Storage; 2: Network; 32768: Unknown ",
|
"Gets or sets the resource class of a resource. 0: Unknown; 1: Storage; 2: Network; 32768: Unknown ",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RestartAction = prometheus.NewDesc(
|
c.restartAction = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "restart_action"),
|
prometheus.BuildFQName(types.Namespace, Name, "restart_action"),
|
||||||
"Provides access to the resource's RestartAction property, which is the action to be taken by the Cluster Service if the resource fails.",
|
"Provides access to the resource's RestartAction property, which is the action to be taken by the Cluster Service if the resource fails.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RestartDelay = prometheus.NewDesc(
|
c.restartDelay = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "restart_delay"),
|
prometheus.BuildFQName(types.Namespace, Name, "restart_delay"),
|
||||||
"Indicates the time delay before a failed resource is restarted.",
|
"Indicates the time delay before a failed resource is restarted.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RestartPeriod = prometheus.NewDesc(
|
c.restartPeriod = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "restart_period"),
|
prometheus.BuildFQName(types.Namespace, Name, "restart_period"),
|
||||||
"Provides access to the resource's RestartPeriod property, which is interval of time, in milliseconds, during which a specified number of restart attempts can be made on a nonresponsive resource.",
|
"Provides access to the resource's RestartPeriod property, which is interval of time, in milliseconds, during which a specified number of restart attempts can be made on a nonresponsive resource.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RestartThreshold = prometheus.NewDesc(
|
c.restartThreshold = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "restart_threshold"),
|
prometheus.BuildFQName(types.Namespace, Name, "restart_threshold"),
|
||||||
"Provides access to the resource's RestartThreshold property which is the maximum number of restart attempts that can be made on a resource within an interval defined by the RestartPeriod property before the Cluster Service initiates the action specified by the RestartAction property.",
|
"Provides access to the resource's RestartThreshold property which is the maximum number of restart attempts that can be made on a resource within an interval defined by the RestartPeriod property before the Cluster Service initiates the action specified by the RestartAction property.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RetryPeriodOnFailure = prometheus.NewDesc(
|
c.retryPeriodOnFailure = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "retry_period_on_failure"),
|
prometheus.BuildFQName(types.Namespace, Name, "retry_period_on_failure"),
|
||||||
"Provides access to the resource's RetryPeriodOnFailure property, which is the interval of time (in milliseconds) that a resource should remain in a failed state before the Cluster service attempts to restart it.",
|
"Provides access to the resource's RetryPeriodOnFailure property, which is the interval of time (in milliseconds) that a resource should remain in a failed state before the Cluster service attempts to restart it.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.State = prometheus.NewDesc(
|
c.state = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
||||||
"The current state of the resource. -1: Unknown; 0: Inherited; 1: Initializing; 2: Online; 3: Offline; 4: Failed; 128: Pending; 129: Online Pending; 130: Offline Pending ",
|
"The current state of the resource. -1: Unknown; 0: Inherited; 1: Initializing; 2: Online; 3: Offline; 4: Failed; 128: Pending; 129: Online Pending; 130: Offline Pending ",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Subclass = prometheus.NewDesc(
|
c.subclass = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "subclass"),
|
prometheus.BuildFQName(types.Namespace, Name, "subclass"),
|
||||||
"Provides the list of references to nodes that can be the owner of this resource.",
|
"Provides the list of references to nodes that can be the owner of this resource.",
|
||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
@@ -201,7 +213,7 @@ type MSCluster_Resource struct {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []MSCluster_Resource
|
var dst []MSCluster_Resource
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
||||||
@@ -209,51 +221,50 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range dst {
|
for _, v := range dst {
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Characteristics,
|
c.characteristics,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Characteristics),
|
float64(v.Characteristics),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DeadlockTimeout,
|
c.deadlockTimeout,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.DeadlockTimeout),
|
float64(v.DeadlockTimeout),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.EmbeddedFailureAction,
|
c.embeddedFailureAction,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.EmbeddedFailureAction),
|
float64(v.EmbeddedFailureAction),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Flags,
|
c.flags,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Flags),
|
float64(v.Flags),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IsAlivePollInterval,
|
c.isAlivePollInterval,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.IsAlivePollInterval),
|
float64(v.IsAlivePollInterval),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LooksAlivePollInterval,
|
c.looksAlivePollInterval,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.LooksAlivePollInterval),
|
float64(v.LooksAlivePollInterval),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MonitorProcessId,
|
c.monitorProcessId,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.MonitorProcessId),
|
float64(v.MonitorProcessId),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
@@ -266,7 +277,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
isCurrentState = 1.0
|
isCurrentState = 1.0
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OwnerNode,
|
c.ownerNode,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
isCurrentState,
|
isCurrentState,
|
||||||
v.Type, v.OwnerGroup, node_name, v.Name,
|
v.Type, v.OwnerGroup, node_name, v.Name,
|
||||||
@@ -275,63 +286,63 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PendingTimeout,
|
c.pendingTimeout,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.PendingTimeout),
|
float64(v.PendingTimeout),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ResourceClass,
|
c.resourceClass,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.ResourceClass),
|
float64(v.ResourceClass),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RestartAction,
|
c.restartAction,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.RestartAction),
|
float64(v.RestartAction),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RestartDelay,
|
c.restartDelay,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.RestartDelay),
|
float64(v.RestartDelay),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RestartPeriod,
|
c.restartPeriod,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.RestartPeriod),
|
float64(v.RestartPeriod),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RestartThreshold,
|
c.restartThreshold,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.RestartThreshold),
|
float64(v.RestartThreshold),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RetryPeriodOnFailure,
|
c.retryPeriodOnFailure,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.RetryPeriodOnFailure),
|
float64(v.RetryPeriodOnFailure),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.State,
|
c.state,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.State),
|
float64(v.State),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Subclass,
|
c.subclass,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Subclass),
|
float64(v.Subclass),
|
||||||
v.Type, v.OwnerGroup, v.Name,
|
v.Type, v.OwnerGroup, v.Name,
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package mscluster_resourcegroup
|
package mscluster_resourcegroup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/alecthomas/kingpin/v2"
|
||||||
|
"github.com/go-kit/log"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/mscluster_node"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/mscluster_node"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,136 +15,147 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI MSCluster_ResourceGroup metrics
|
// A Collector is a Prometheus Collector for WMI MSCluster_ResourceGroup metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
AutoFailbackType *prometheus.Desc
|
autoFailbackType *prometheus.Desc
|
||||||
Characteristics *prometheus.Desc
|
characteristics *prometheus.Desc
|
||||||
ColdStartSetting *prometheus.Desc
|
coldStartSetting *prometheus.Desc
|
||||||
DefaultOwner *prometheus.Desc
|
defaultOwner *prometheus.Desc
|
||||||
FailbackWindowEnd *prometheus.Desc
|
failbackWindowEnd *prometheus.Desc
|
||||||
FailbackWindowStart *prometheus.Desc
|
failbackWindowStart *prometheus.Desc
|
||||||
FailoverPeriod *prometheus.Desc
|
failOverPeriod *prometheus.Desc
|
||||||
FailoverThreshold *prometheus.Desc
|
failOverThreshold *prometheus.Desc
|
||||||
FaultDomain *prometheus.Desc
|
flags *prometheus.Desc
|
||||||
Flags *prometheus.Desc
|
groupType *prometheus.Desc
|
||||||
GroupType *prometheus.Desc
|
ownerNode *prometheus.Desc
|
||||||
PlacementOptions *prometheus.Desc
|
priority *prometheus.Desc
|
||||||
OwnerNode *prometheus.Desc
|
resiliencyPeriod *prometheus.Desc
|
||||||
Priority *prometheus.Desc
|
state *prometheus.Desc
|
||||||
ResiliencyPeriod *prometheus.Desc
|
|
||||||
State *prometheus.Desc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Memory"}, nil
|
return []string{"Memory"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.AutoFailbackType = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.autoFailbackType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "auto_failback_type"),
|
prometheus.BuildFQName(types.Namespace, Name, "auto_failback_type"),
|
||||||
"Provides access to the group's AutoFailbackType property.",
|
"Provides access to the group's AutoFailbackType property.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Characteristics = prometheus.NewDesc(
|
c.characteristics = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
prometheus.BuildFQName(types.Namespace, Name, "characteristics"),
|
||||||
"Provides the characteristics of the group.",
|
"Provides the characteristics of the group.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ColdStartSetting = prometheus.NewDesc(
|
c.coldStartSetting = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cold_start_setting"),
|
prometheus.BuildFQName(types.Namespace, Name, "cold_start_setting"),
|
||||||
"Indicates whether a group can start after a cluster cold start.",
|
"Indicates whether a group can start after a cluster cold start.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DefaultOwner = prometheus.NewDesc(
|
c.defaultOwner = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "default_owner"),
|
prometheus.BuildFQName(types.Namespace, Name, "default_owner"),
|
||||||
"Number of the last node the resource group was activated on or explicitly moved to.",
|
"Number of the last node the resource group was activated on or explicitly moved to.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailbackWindowEnd = prometheus.NewDesc(
|
c.failbackWindowEnd = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failback_window_end"),
|
prometheus.BuildFQName(types.Namespace, Name, "failback_window_end"),
|
||||||
"The FailbackWindowEnd property provides the latest time that the group can be moved back to the node identified as its preferred node.",
|
"The FailbackWindowEnd property provides the latest time that the group can be moved back to the node identified as its preferred node.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailbackWindowStart = prometheus.NewDesc(
|
c.failbackWindowStart = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failback_window_start"),
|
prometheus.BuildFQName(types.Namespace, Name, "failback_window_start"),
|
||||||
"The FailbackWindowStart property provides the earliest time (that is, local time as kept by the cluster) that the group can be moved back to the node identified as its preferred node.",
|
"The FailbackWindowStart property provides the earliest time (that is, local time as kept by the cluster) that the group can be moved back to the node identified as its preferred node.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverPeriod = prometheus.NewDesc(
|
c.failOverPeriod = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_period"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_period"),
|
||||||
"The FailoverPeriod property specifies a number of hours during which a maximum number of failover attempts, specified by the FailoverThreshold property, can occur.",
|
"The FailoverPeriod property specifies a number of hours during which a maximum number of failover attempts, specified by the FailoverThreshold property, can occur.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FailoverThreshold = prometheus.NewDesc(
|
c.failOverThreshold = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "failover_threshold"),
|
prometheus.BuildFQName(types.Namespace, Name, "failover_threshold"),
|
||||||
"The FailoverThreshold property specifies the maximum number of failover attempts.",
|
"The FailoverThreshold property specifies the maximum number of failover attempts.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Flags = prometheus.NewDesc(
|
c.flags = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
prometheus.BuildFQName(types.Namespace, Name, "flags"),
|
||||||
"Provides access to the flags set for the group. ",
|
"Provides access to the flags set for the group. ",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.GroupType = prometheus.NewDesc(
|
c.groupType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "group_type"),
|
prometheus.BuildFQName(types.Namespace, Name, "group_type"),
|
||||||
"The Type of the resource group.",
|
"The Type of the resource group.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OwnerNode = prometheus.NewDesc(
|
c.ownerNode = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
||||||
"The node hosting the resource group. 0: Not hosted; 1: Hosted",
|
"The node hosting the resource group. 0: Not hosted; 1: Hosted",
|
||||||
[]string{"node_name", "name"},
|
[]string{"node_name", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OwnerNode = prometheus.NewDesc(
|
c.ownerNode = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
prometheus.BuildFQName(types.Namespace, Name, "owner_node"),
|
||||||
"The node hosting the resource group. 0: Not hosted; 1: Hosted",
|
"The node hosting the resource group. 0: Not hosted; 1: Hosted",
|
||||||
[]string{"node_name", "name"},
|
[]string{"node_name", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Priority = prometheus.NewDesc(
|
c.priority = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "priority"),
|
prometheus.BuildFQName(types.Namespace, Name, "priority"),
|
||||||
"Priority value of the resource group",
|
"Priority value of the resource group",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ResiliencyPeriod = prometheus.NewDesc(
|
c.resiliencyPeriod = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "resiliency_period"),
|
prometheus.BuildFQName(types.Namespace, Name, "resiliency_period"),
|
||||||
"The resiliency period for this group, in seconds.",
|
"The resiliency period for this group, in seconds.",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.State = prometheus.NewDesc(
|
c.state = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
||||||
"The current state of the resource group. -1: Unknown; 0: Online; 1: Offline; 2: Failed; 3: Partial Online; 4: Pending",
|
"The current state of the resource group. -1: Unknown; 0: Online; 1: Offline; 2: Failed; 3: Partial Online; 4: Pending",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
@@ -177,7 +187,7 @@ type MSCluster_ResourceGroup struct {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []MSCluster_ResourceGroup
|
var dst []MSCluster_ResourceGroup
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
||||||
@@ -185,72 +195,71 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range dst {
|
for _, v := range dst {
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AutoFailbackType,
|
c.autoFailbackType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.AutoFailbackType),
|
float64(v.AutoFailbackType),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Characteristics,
|
c.characteristics,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Characteristics),
|
float64(v.Characteristics),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ColdStartSetting,
|
c.coldStartSetting,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.ColdStartSetting),
|
float64(v.ColdStartSetting),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DefaultOwner,
|
c.defaultOwner,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.DefaultOwner),
|
float64(v.DefaultOwner),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailbackWindowEnd,
|
c.failbackWindowEnd,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.FailbackWindowEnd),
|
float64(v.FailbackWindowEnd),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailbackWindowStart,
|
c.failbackWindowStart,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.FailbackWindowStart),
|
float64(v.FailbackWindowStart),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverPeriod,
|
c.failOverPeriod,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.FailoverPeriod),
|
float64(v.FailoverPeriod),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FailoverThreshold,
|
c.failOverThreshold,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.FailoverThreshold),
|
float64(v.FailoverThreshold),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Flags,
|
c.flags,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Flags),
|
float64(v.Flags),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.GroupType,
|
c.groupType,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.GroupType),
|
float64(v.GroupType),
|
||||||
v.Name,
|
v.Name,
|
||||||
@@ -263,7 +272,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
isCurrentState = 1.0
|
isCurrentState = 1.0
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OwnerNode,
|
c.ownerNode,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
isCurrentState,
|
isCurrentState,
|
||||||
node_name, v.Name,
|
node_name, v.Name,
|
||||||
@@ -272,26 +281,25 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Priority,
|
c.priority,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.Priority),
|
float64(v.Priority),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ResiliencyPeriod,
|
c.resiliencyPeriod,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.ResiliencyPeriod),
|
float64(v.ResiliencyPeriod),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.State,
|
c.state,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(v.State),
|
float64(v.State),
|
||||||
v.Name,
|
v.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -14,87 +14,97 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "msmq"
|
||||||
Name = "msmq"
|
|
||||||
FlagMsmqWhereClause = "collector.msmq.msmq-where"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
QueryWhereClause string `yaml:"query_where_clause"`
|
QueryWhereClause *string `yaml:"query_where_clause"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
QueryWhereClause: "",
|
QueryWhereClause: utils.ToPTR(""),
|
||||||
}
|
}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
queryWhereClause *string
|
bytesInJournalQueue *prometheus.Desc
|
||||||
|
bytesInQueue *prometheus.Desc
|
||||||
BytesinJournalQueue *prometheus.Desc
|
messagesInJournalQueue *prometheus.Desc
|
||||||
BytesinQueue *prometheus.Desc
|
messagesInQueue *prometheus.Desc
|
||||||
MessagesinJournalQueue *prometheus.Desc
|
|
||||||
MessagesinQueue *prometheus.Desc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.QueryWhereClause == nil {
|
||||||
queryWhereClause: &config.QueryWhereClause,
|
config.QueryWhereClause = ConfigDefaults.QueryWhereClause
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
return &collector{
|
c := &Collector{
|
||||||
queryWhereClause: app.
|
config: ConfigDefaults,
|
||||||
Flag(FlagMsmqWhereClause, "WQL 'where' clause to use in WMI metrics query. Limits the response to the msmqs you specify and reduces the size of the response.").
|
|
||||||
Default(ConfigDefaults.QueryWhereClause).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.Flag("collector.msmq.msmq-where", "WQL 'where' clause to use in WMI metrics query. "+
|
||||||
|
"Limits the response to the msmqs you specify and reduces the size of the response.").
|
||||||
|
Default(*c.config.QueryWhereClause).StringVar(c.config.QueryWhereClause)
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
if utils.IsEmpty(c.queryWhereClause) {
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
if *c.config.QueryWhereClause == "" {
|
||||||
_ = level.Warn(c.logger).Log("msg", "No where-clause specified for msmq collector. This will generate a very large number of metrics!")
|
_ = level.Warn(c.logger).Log("msg", "No where-clause specified for msmq collector. This will generate a very large number of metrics!")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.BytesinJournalQueue = prometheus.NewDesc(
|
c.bytesInJournalQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_in_journal_queue"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_in_journal_queue"),
|
||||||
"Size of queue journal in bytes",
|
"Size of queue journal in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesinQueue = prometheus.NewDesc(
|
c.bytesInQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_in_queue"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_in_queue"),
|
||||||
"Size of queue in bytes",
|
"Size of queue in bytes",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesinJournalQueue = prometheus.NewDesc(
|
c.messagesInJournalQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_in_journal_queue"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_in_journal_queue"),
|
||||||
"Count messages in queue journal",
|
"Count messages in queue journal",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesinQueue = prometheus.NewDesc(
|
c.messagesInQueue = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_in_queue"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_in_queue"),
|
||||||
"Count messages in queue",
|
"Count messages in queue",
|
||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
@@ -105,7 +115,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting msmq metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting msmq metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -113,50 +123,52 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Win32_PerfRawData_MSMQ_MSMQQueue struct {
|
type msmqQueue struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
BytesinJournalQueue uint64
|
BytesInJournalQueue uint64
|
||||||
BytesinQueue uint64
|
BytesInQueue uint64
|
||||||
MessagesinJournalQueue uint64
|
MessagesInJournalQueue uint64
|
||||||
MessagesinQueue uint64
|
MessagesInQueue uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_MSMQ_MSMQQueue
|
var dst []msmqQueue
|
||||||
q := wmi.QueryAllWhere(&dst, *c.queryWhereClause, c.logger)
|
|
||||||
|
q := wmi.QueryAllForClassWhere(&dst, "Win32_PerfRawData_MSMQ_MSMQQueue", *c.config.QueryWhereClause, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msmq := range dst {
|
for _, msmq := range dst {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesinJournalQueue,
|
c.bytesInJournalQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(msmq.BytesinJournalQueue),
|
float64(msmq.BytesInJournalQueue),
|
||||||
strings.ToLower(msmq.Name),
|
strings.ToLower(msmq.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesinQueue,
|
c.bytesInQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(msmq.BytesinQueue),
|
float64(msmq.BytesInQueue),
|
||||||
strings.ToLower(msmq.Name),
|
strings.ToLower(msmq.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesinJournalQueue,
|
c.messagesInJournalQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(msmq.MessagesinJournalQueue),
|
float64(msmq.MessagesInJournalQueue),
|
||||||
strings.ToLower(msmq.Name),
|
strings.ToLower(msmq.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesinQueue,
|
c.messagesInQueue,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(msmq.MessagesinQueue),
|
float64(msmq.MessagesInQueue),
|
||||||
strings.ToLower(msmq.Name),
|
strings.ToLower(msmq.Name),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
// No context name required as collector source is WMI
|
// No context name required as Collector source is WMI
|
||||||
testutils.FuncBenchmarkCollector(b, msmq.Name, msmq.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, msmq.Name, msmq.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -14,188 +14,200 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "net"
|
||||||
Name = "net"
|
|
||||||
|
|
||||||
FlagNicExclude = "collector.net.nic-exclude"
|
|
||||||
FlagNicInclude = "collector.net.nic-include"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
NicInclude string `yaml:"nic_include"`
|
NicExclude *regexp.Regexp `yaml:"nic_exclude"`
|
||||||
NicExclude string `yaml:"nic_exclude"`
|
NicInclude *regexp.Regexp `yaml:"nic_include"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
NicInclude: ".+",
|
NicExclude: types.RegExpEmpty,
|
||||||
NicExclude: "",
|
NicInclude: types.RegExpAny,
|
||||||
}
|
}
|
||||||
|
|
||||||
var nicNameToUnderscore = regexp.MustCompile("[^a-zA-Z0-9]")
|
var nicNameToUnderscore = regexp.MustCompile("[^a-zA-Z0-9]")
|
||||||
|
|
||||||
// A collector is a Prometheus collector for Perflib Network Interface metrics
|
// A Collector is a Prometheus Collector for Perflib Network Interface metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
nicInclude *string
|
bytesReceivedTotal *prometheus.Desc
|
||||||
nicExclude *string
|
bytesSentTotal *prometheus.Desc
|
||||||
|
bytesTotal *prometheus.Desc
|
||||||
BytesReceivedTotal *prometheus.Desc
|
outputQueueLength *prometheus.Desc
|
||||||
BytesSentTotal *prometheus.Desc
|
packetsOutboundDiscarded *prometheus.Desc
|
||||||
BytesTotal *prometheus.Desc
|
packetsOutboundErrors *prometheus.Desc
|
||||||
OutputQueueLength *prometheus.Desc
|
packetsTotal *prometheus.Desc
|
||||||
PacketsOutboundDiscarded *prometheus.Desc
|
packetsReceivedDiscarded *prometheus.Desc
|
||||||
PacketsOutboundErrors *prometheus.Desc
|
packetsReceivedErrors *prometheus.Desc
|
||||||
PacketsTotal *prometheus.Desc
|
packetsReceivedTotal *prometheus.Desc
|
||||||
PacketsReceivedDiscarded *prometheus.Desc
|
packetsReceivedUnknown *prometheus.Desc
|
||||||
PacketsReceivedErrors *prometheus.Desc
|
packetsSentTotal *prometheus.Desc
|
||||||
PacketsReceivedTotal *prometheus.Desc
|
currentBandwidth *prometheus.Desc
|
||||||
PacketsReceivedUnknown *prometheus.Desc
|
|
||||||
PacketsSentTotal *prometheus.Desc
|
|
||||||
CurrentBandwidth *prometheus.Desc
|
|
||||||
|
|
||||||
nicIncludePattern *regexp.Regexp
|
|
||||||
nicExcludePattern *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.NicExclude == nil {
|
||||||
nicExclude: &config.NicExclude,
|
config.NicExclude = ConfigDefaults.NicExclude
|
||||||
nicInclude: &config.NicInclude,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.NicInclude == nil {
|
||||||
|
config.NicInclude = ConfigDefaults.NicInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
nicInclude: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagNicInclude,
|
|
||||||
"Regexp of NIC:s to include. NIC name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.NicInclude).String(),
|
|
||||||
|
|
||||||
nicExclude: app.Flag(
|
|
||||||
FlagNicExclude,
|
|
||||||
"Regexp of NIC:s to exclude. NIC name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.NicExclude).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nicExclude, nicInclude string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.net.nic-exclude",
|
||||||
|
"Regexp of NIC:s to exclude. NIC name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.NicExclude.String()).StringVar(&nicExclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.net.nic-include",
|
||||||
|
"Regexp of NIC:s to include. NIC name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.NicInclude.String()).StringVar(&nicInclude)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.NicExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", nicExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.net.nic-exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.NicInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", nicInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.net.nic-include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Network Interface"}, nil
|
return []string{"Network Interface"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.BytesReceivedTotal = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.bytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
||||||
"(Network.BytesReceivedPerSec)",
|
"(Network.BytesReceivedPerSec)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesSentTotal = prometheus.NewDesc(
|
c.bytesSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_sent_total"),
|
||||||
"(Network.BytesSentPerSec)",
|
"(Network.BytesSentPerSec)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesTotal = prometheus.NewDesc(
|
c.bytesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_total"),
|
||||||
"(Network.BytesTotalPerSec)",
|
"(Network.BytesTotalPerSec)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OutputQueueLength = prometheus.NewDesc(
|
c.outputQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "output_queue_length_packets"),
|
prometheus.BuildFQName(types.Namespace, Name, "output_queue_length_packets"),
|
||||||
"(Network.OutputQueueLength)",
|
"(Network.OutputQueueLength)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsOutboundDiscarded = prometheus.NewDesc(
|
c.packetsOutboundDiscarded = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_outbound_discarded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_outbound_discarded_total"),
|
||||||
"(Network.PacketsOutboundDiscarded)",
|
"(Network.PacketsOutboundDiscarded)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsOutboundErrors = prometheus.NewDesc(
|
c.packetsOutboundErrors = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_outbound_errors_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_outbound_errors_total"),
|
||||||
"(Network.PacketsOutboundErrors)",
|
"(Network.PacketsOutboundErrors)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsReceivedDiscarded = prometheus.NewDesc(
|
c.packetsReceivedDiscarded = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_discarded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_discarded_total"),
|
||||||
"(Network.PacketsReceivedDiscarded)",
|
"(Network.PacketsReceivedDiscarded)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsReceivedErrors = prometheus.NewDesc(
|
c.packetsReceivedErrors = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_errors_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_errors_total"),
|
||||||
"(Network.PacketsReceivedErrors)",
|
"(Network.PacketsReceivedErrors)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsReceivedTotal = prometheus.NewDesc(
|
c.packetsReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
||||||
"(Network.PacketsReceivedPerSec)",
|
"(Network.PacketsReceivedPerSec)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsReceivedUnknown = prometheus.NewDesc(
|
c.packetsReceivedUnknown = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_unknown_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_unknown_total"),
|
||||||
"(Network.PacketsReceivedUnknown)",
|
"(Network.PacketsReceivedUnknown)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsTotal = prometheus.NewDesc(
|
c.packetsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_total"),
|
||||||
"(Network.PacketsPerSec)",
|
"(Network.PacketsPerSec)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsSentTotal = prometheus.NewDesc(
|
c.packetsSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_sent_total"),
|
||||||
"(Network.PacketsSentPerSec)",
|
"(Network.PacketsSentPerSec)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentBandwidth = prometheus.NewDesc(
|
c.currentBandwidth = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "current_bandwidth_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "current_bandwidth_bytes"),
|
||||||
"(Network.CurrentBandwidth)",
|
"(Network.CurrentBandwidth)",
|
||||||
[]string{"nic"},
|
[]string{"nic"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
|
||||||
c.nicIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.nicInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.nicExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.nicExclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting net metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting net metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -228,7 +240,7 @@ type networkInterface struct {
|
|||||||
CurrentBandwidth float64 `perflib:"Current Bandwidth"`
|
CurrentBandwidth float64 `perflib:"Current Bandwidth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []networkInterface
|
var dst []networkInterface
|
||||||
|
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["Network Interface"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["Network Interface"], &dst, c.logger); err != nil {
|
||||||
@@ -236,8 +248,8 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, nic := range dst {
|
for _, nic := range dst {
|
||||||
if c.nicExcludePattern.MatchString(nic.Name) ||
|
if c.config.NicExclude.MatchString(nic.Name) ||
|
||||||
!c.nicIncludePattern.MatchString(nic.Name) {
|
!c.config.NicInclude.MatchString(nic.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,83 +260,84 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
// Counters
|
// Counters
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesReceivedTotal,
|
c.bytesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.BytesReceivedPerSec,
|
nic.BytesReceivedPerSec,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesSentTotal,
|
c.bytesSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.BytesSentPerSec,
|
nic.BytesSentPerSec,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesTotal,
|
c.bytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.BytesTotalPerSec,
|
nic.BytesTotalPerSec,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OutputQueueLength,
|
c.outputQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
nic.OutputQueueLength,
|
nic.OutputQueueLength,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsOutboundDiscarded,
|
c.packetsOutboundDiscarded,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsOutboundDiscarded,
|
nic.PacketsOutboundDiscarded,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsOutboundErrors,
|
c.packetsOutboundErrors,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsOutboundErrors,
|
nic.PacketsOutboundErrors,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsTotal,
|
c.packetsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsPerSec,
|
nic.PacketsPerSec,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceivedDiscarded,
|
c.packetsReceivedDiscarded,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsReceivedDiscarded,
|
nic.PacketsReceivedDiscarded,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceivedErrors,
|
c.packetsReceivedErrors,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsReceivedErrors,
|
nic.PacketsReceivedErrors,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceivedTotal,
|
c.packetsReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsReceivedPerSec,
|
nic.PacketsReceivedPerSec,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceivedUnknown,
|
c.packetsReceivedUnknown,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsReceivedUnknown,
|
nic.PacketsReceivedUnknown,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsSentTotal,
|
c.packetsSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
nic.PacketsSentPerSec,
|
nic.PacketsSentPerSec,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentBandwidth,
|
c.currentBandwidth,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
nic.CurrentBandwidth/8,
|
nic.CurrentBandwidth/8,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
// Include is not set in testing context (kingpin flags not parsed), causing the collector to skip all interfaces.
|
// PrinterInclude is not set in testing context (kingpin flags not parsed), causing the collector to skip all interfaces.
|
||||||
localNicInclude := ".+"
|
localNicInclude := ".+"
|
||||||
|
|
||||||
kingpin.CommandLine.GetArg(net.FlagNicInclude).StringVar(&localNicInclude)
|
kingpin.CommandLine.GetArg("collector.net.nic-include").StringVar(&localNicInclude)
|
||||||
testutils.FuncBenchmarkCollector(b, net.Name, net.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, net.Name, net.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNetworkToInstanceName(t *testing.T) {
|
func TestNetworkToInstanceName(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
data := map[string]string{
|
data := map[string]string{
|
||||||
"Intel[R] Dual Band Wireless-AC 8260": "Intel_R__Dual_Band_Wireless_AC_8260",
|
"Intel[R] Dual Band Wireless-AC 8260": "Intel_R__Dual_Band_Wireless_AC_8260",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,11 @@
|
|||||||
package netframework_clrexceptions
|
package netframework_clrexceptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,58 +17,71 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
NumberofExcepsThrown *prometheus.Desc
|
numberOfExceptionsThrown *prometheus.Desc
|
||||||
NumberofFilters *prometheus.Desc
|
numberOfFilters *prometheus.Desc
|
||||||
NumberofFinallys *prometheus.Desc
|
numberOfFinally *prometheus.Desc
|
||||||
ThrowToCatchDepth *prometheus.Desc
|
throwToCatchDepth *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.NumberofExcepsThrown = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.numberOfExceptionsThrown = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "exceptions_thrown_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "exceptions_thrown_total"),
|
||||||
"Displays the total number of exceptions thrown since the application started. This includes both .NET exceptions and unmanaged exceptions that are converted into .NET exceptions.",
|
"Displays the total number of exceptions thrown since the application started. This includes both .NET exceptions and unmanaged exceptions that are converted into .NET exceptions.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofFilters = prometheus.NewDesc(
|
c.numberOfFilters = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "exceptions_filters_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "exceptions_filters_total"),
|
||||||
"Displays the total number of .NET exception filters executed. An exception filter evaluates regardless of whether an exception is handled.",
|
"Displays the total number of .NET exception filters executed. An exception filter evaluates regardless of whether an exception is handled.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofFinallys = prometheus.NewDesc(
|
c.numberOfFinally = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "exceptions_finallys_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "exceptions_finallys_total"),
|
||||||
"Displays the total number of finally blocks executed. Only the finally blocks executed for an exception are counted; finally blocks on normal code paths are not counted by this counter.",
|
"Displays the total number of finally blocks executed. Only the finally blocks executed for an exception are counted; finally blocks on normal code paths are not counted by this counter.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ThrowToCatchDepth = prometheus.NewDesc(
|
c.throwToCatchDepth = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "throw_to_catch_depth_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "throw_to_catch_depth_total"),
|
||||||
"Displays the total number of stack frames traversed, from the frame that threw the exception to the frame that handled the exception.",
|
"Displays the total number of stack frames traversed, from the frame that threw the exception to the frame that handled the exception.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -80,7 +92,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrexceptions metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrexceptions metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -98,7 +110,7 @@ type Win32_PerfRawData_NETFramework_NETCLRExceptions struct {
|
|||||||
ThrowToCatchDepthPersec uint32
|
ThrowToCatchDepthPersec uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -106,34 +118,33 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofExcepsThrown,
|
c.numberOfExceptionsThrown,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberofExcepsThrown),
|
float64(process.NumberofExcepsThrown),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofFilters,
|
c.numberOfFilters,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberofFiltersPersec),
|
float64(process.NumberofFiltersPersec),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofFinallys,
|
c.numberOfFinally,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberofFinallysPersec),
|
float64(process.NumberofFinallysPersec),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ThrowToCatchDepth,
|
c.throwToCatchDepth,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.ThrowToCatchDepthPersec),
|
float64(process.ThrowToCatchDepthPersec),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
// No context name required as collector source is WMI
|
// No context name required as Collector source is WMI
|
||||||
testutils.FuncBenchmarkCollector(b, netframework_clrexceptions.Name, netframework_clrexceptions.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, netframework_clrexceptions.Name, netframework_clrexceptions.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,11 @@
|
|||||||
package netframework_clrinterop
|
package netframework_clrinterop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,51 +17,64 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
NumberofCCWs *prometheus.Desc
|
numberOfCCWs *prometheus.Desc
|
||||||
Numberofmarshalling *prometheus.Desc
|
numberOfMarshalling *prometheus.Desc
|
||||||
NumberofStubs *prometheus.Desc
|
numberOfStubs *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.NumberofCCWs = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.numberOfCCWs = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "com_callable_wrappers_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "com_callable_wrappers_total"),
|
||||||
"Displays the current number of COM callable wrappers (CCWs). A CCW is a proxy for a managed object being referenced from an unmanaged COM client.",
|
"Displays the current number of COM callable wrappers (CCWs). A CCW is a proxy for a managed object being referenced from an unmanaged COM client.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Numberofmarshalling = prometheus.NewDesc(
|
c.numberOfMarshalling = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "interop_marshalling_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "interop_marshalling_total"),
|
||||||
"Displays the total number of times arguments and return values have been marshaled from managed to unmanaged code, and vice versa, since the application started.",
|
"Displays the total number of times arguments and return values have been marshaled from managed to unmanaged code, and vice versa, since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofStubs = prometheus.NewDesc(
|
c.numberOfStubs = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "interop_stubs_created_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "interop_stubs_created_total"),
|
||||||
"Displays the current number of stubs created by the common language runtime. Stubs are responsible for marshaling arguments and return values from managed to unmanaged code, and vice versa, during a COM interop call or a platform invoke call.",
|
"Displays the current number of stubs created by the common language runtime. Stubs are responsible for marshaling arguments and return values from managed to unmanaged code, and vice versa, during a COM interop call or a platform invoke call.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -73,7 +85,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrinterop metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrinterop metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -91,7 +103,7 @@ type Win32_PerfRawData_NETFramework_NETCLRInterop struct {
|
|||||||
NumberofTLBimportsPersec uint32
|
NumberofTLBimportsPersec uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -99,27 +111,26 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofCCWs,
|
c.numberOfCCWs,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberofCCWs),
|
float64(process.NumberofCCWs),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Numberofmarshalling,
|
c.numberOfMarshalling,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.Numberofmarshalling),
|
float64(process.Numberofmarshalling),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofStubs,
|
c.numberOfStubs,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberofStubs),
|
float64(process.NumberofStubs),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,58 +17,71 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
NumberofMethodsJitted *prometheus.Desc
|
numberOfMethodsJitted *prometheus.Desc
|
||||||
TimeinJit *prometheus.Desc
|
timeInJit *prometheus.Desc
|
||||||
StandardJitFailures *prometheus.Desc
|
standardJitFailures *prometheus.Desc
|
||||||
TotalNumberofILBytesJitted *prometheus.Desc
|
totalNumberOfILBytesJitted *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.NumberofMethodsJitted = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.numberOfMethodsJitted = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "jit_methods_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "jit_methods_total"),
|
||||||
"Displays the total number of methods JIT-compiled since the application started. This counter does not include pre-JIT-compiled methods.",
|
"Displays the total number of methods JIT-compiled since the application started. This counter does not include pre-JIT-compiled methods.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TimeinJit = prometheus.NewDesc(
|
c.timeInJit = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "jit_time_percent"),
|
prometheus.BuildFQName(types.Namespace, Name, "jit_time_percent"),
|
||||||
"Displays the percentage of time spent in JIT compilation. This counter is updated at the end of every JIT compilation phase. A JIT compilation phase occurs when a method and its dependencies are compiled.",
|
"Displays the percentage of time spent in JIT compilation. This counter is updated at the end of every JIT compilation phase. A JIT compilation phase occurs when a method and its dependencies are compiled.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.StandardJitFailures = prometheus.NewDesc(
|
c.standardJitFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "jit_standard_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "jit_standard_failures_total"),
|
||||||
"Displays the peak number of methods the JIT compiler has failed to compile since the application started. This failure can occur if the MSIL cannot be verified or if there is an internal error in the JIT compiler.",
|
"Displays the peak number of methods the JIT compiler has failed to compile since the application started. This failure can occur if the MSIL cannot be verified or if there is an internal error in the JIT compiler.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalNumberofILBytesJitted = prometheus.NewDesc(
|
c.totalNumberOfILBytesJitted = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "jit_il_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "jit_il_bytes_total"),
|
||||||
"Displays the total number of Microsoft intermediate language (MSIL) bytes compiled by the just-in-time (JIT) compiler since the application started",
|
"Displays the total number of Microsoft intermediate language (MSIL) bytes compiled by the just-in-time (JIT) compiler since the application started",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -79,7 +92,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrjit metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrjit metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -99,7 +112,7 @@ type Win32_PerfRawData_NETFramework_NETCLRJit struct {
|
|||||||
TotalNumberofILBytesJitted uint32
|
TotalNumberofILBytesJitted uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -107,34 +120,33 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofMethodsJitted,
|
c.numberOfMethodsJitted,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberofMethodsJitted),
|
float64(process.NumberofMethodsJitted),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeinJit,
|
c.timeInJit,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PercentTimeinJit)/float64(process.Frequency_PerfTime),
|
float64(process.PercentTimeinJit)/float64(process.Frequency_PerfTime),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StandardJitFailures,
|
c.standardJitFailures,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.StandardJitFailures),
|
float64(process.StandardJitFailures),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalNumberofILBytesJitted,
|
c.totalNumberOfILBytesJitted,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalNumberofILBytesJitted),
|
float64(process.TotalNumberofILBytesJitted),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,93 +17,106 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
BytesinLoaderHeap *prometheus.Desc
|
bytesInLoaderHeap *prometheus.Desc
|
||||||
Currentappdomains *prometheus.Desc
|
currentAppDomains *prometheus.Desc
|
||||||
CurrentAssemblies *prometheus.Desc
|
currentAssemblies *prometheus.Desc
|
||||||
CurrentClassesLoaded *prometheus.Desc
|
currentClassesLoaded *prometheus.Desc
|
||||||
TotalAppdomains *prometheus.Desc
|
totalAppDomains *prometheus.Desc
|
||||||
Totalappdomainsunloaded *prometheus.Desc
|
totalAppDomainsUnloaded *prometheus.Desc
|
||||||
TotalAssemblies *prometheus.Desc
|
totalAssemblies *prometheus.Desc
|
||||||
TotalClassesLoaded *prometheus.Desc
|
totalClassesLoaded *prometheus.Desc
|
||||||
TotalNumberofLoadFailures *prometheus.Desc
|
totalNumberOfLoadFailures *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.BytesinLoaderHeap = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.bytesInLoaderHeap = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "loader_heap_size_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "loader_heap_size_bytes"),
|
||||||
"Displays the current size, in bytes, of the memory committed by the class loader across all application domains. Committed memory is the physical space reserved in the disk paging file.",
|
"Displays the current size, in bytes, of the memory committed by the class loader across all application domains. Committed memory is the physical space reserved in the disk paging file.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Currentappdomains = prometheus.NewDesc(
|
c.currentAppDomains = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "appdomains_loaded_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "appdomains_loaded_current"),
|
||||||
"Displays the current number of application domains loaded in this application.",
|
"Displays the current number of application domains loaded in this application.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentAssemblies = prometheus.NewDesc(
|
c.currentAssemblies = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "assemblies_loaded_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "assemblies_loaded_current"),
|
||||||
"Displays the current number of assemblies loaded across all application domains in the currently running application. If the assembly is loaded as domain-neutral from multiple application domains, this counter is incremented only once.",
|
"Displays the current number of assemblies loaded across all application domains in the currently running application. If the assembly is loaded as domain-neutral from multiple application domains, this counter is incremented only once.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentClassesLoaded = prometheus.NewDesc(
|
c.currentClassesLoaded = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "classes_loaded_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "classes_loaded_current"),
|
||||||
"Displays the current number of classes loaded in all assemblies.",
|
"Displays the current number of classes loaded in all assemblies.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalAppdomains = prometheus.NewDesc(
|
c.totalAppDomains = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "appdomains_loaded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "appdomains_loaded_total"),
|
||||||
"Displays the peak number of application domains loaded since the application started.",
|
"Displays the peak number of application domains loaded since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Totalappdomainsunloaded = prometheus.NewDesc(
|
c.totalAppDomainsUnloaded = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "appdomains_unloaded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "appdomains_unloaded_total"),
|
||||||
"Displays the total number of application domains unloaded since the application started. If an application domain is loaded and unloaded multiple times, this counter increments each time the application domain is unloaded.",
|
"Displays the total number of application domains unloaded since the application started. If an application domain is loaded and unloaded multiple times, this counter increments each time the application domain is unloaded.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalAssemblies = prometheus.NewDesc(
|
c.totalAssemblies = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "assemblies_loaded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "assemblies_loaded_total"),
|
||||||
"Displays the total number of assemblies loaded since the application started. If the assembly is loaded as domain-neutral from multiple application domains, this counter is incremented only once.",
|
"Displays the total number of assemblies loaded since the application started. If the assembly is loaded as domain-neutral from multiple application domains, this counter is incremented only once.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalClassesLoaded = prometheus.NewDesc(
|
c.totalClassesLoaded = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "classes_loaded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "classes_loaded_total"),
|
||||||
"Displays the cumulative number of classes loaded in all assemblies since the application started.",
|
"Displays the cumulative number of classes loaded in all assemblies since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalNumberofLoadFailures = prometheus.NewDesc(
|
c.totalNumberOfLoadFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "class_load_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "class_load_failures_total"),
|
||||||
"Displays the peak number of classes that have failed to load since the application started.",
|
"Displays the peak number of classes that have failed to load since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -114,7 +127,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrloading metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrloading metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -143,7 +156,7 @@ type Win32_PerfRawData_NETFramework_NETCLRLoading struct {
|
|||||||
TotalNumberofLoadFailures uint32
|
TotalNumberofLoadFailures uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -151,69 +164,68 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesinLoaderHeap,
|
c.bytesInLoaderHeap,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.BytesinLoaderHeap),
|
float64(process.BytesinLoaderHeap),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Currentappdomains,
|
c.currentAppDomains,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Currentappdomains),
|
float64(process.Currentappdomains),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentAssemblies,
|
c.currentAssemblies,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.CurrentAssemblies),
|
float64(process.CurrentAssemblies),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentClassesLoaded,
|
c.currentClassesLoaded,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.CurrentClassesLoaded),
|
float64(process.CurrentClassesLoaded),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalAppdomains,
|
c.totalAppDomains,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalAppdomains),
|
float64(process.TotalAppdomains),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Totalappdomainsunloaded,
|
c.totalAppDomainsUnloaded,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.Totalappdomainsunloaded),
|
float64(process.Totalappdomainsunloaded),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalAssemblies,
|
c.totalAssemblies,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalAssemblies),
|
float64(process.TotalAssemblies),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalClassesLoaded,
|
c.totalClassesLoaded,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalClassesLoaded),
|
float64(process.TotalClassesLoaded),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalNumberofLoadFailures,
|
c.totalNumberOfLoadFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalNumberofLoadFailures),
|
float64(process.TotalNumberofLoadFailures),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,79 +17,92 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
CurrentQueueLength *prometheus.Desc
|
currentQueueLength *prometheus.Desc
|
||||||
NumberofcurrentlogicalThreads *prometheus.Desc
|
numberOfCurrentLogicalThreads *prometheus.Desc
|
||||||
NumberofcurrentphysicalThreads *prometheus.Desc
|
numberOfCurrentPhysicalThreads *prometheus.Desc
|
||||||
Numberofcurrentrecognizedthreads *prometheus.Desc
|
numberOfCurrentRecognizedThreads *prometheus.Desc
|
||||||
Numberoftotalrecognizedthreads *prometheus.Desc
|
numberOfTotalRecognizedThreads *prometheus.Desc
|
||||||
QueueLengthPeak *prometheus.Desc
|
queueLengthPeak *prometheus.Desc
|
||||||
TotalNumberofContentions *prometheus.Desc
|
totalNumberOfContentions *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.CurrentQueueLength = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.currentQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "current_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "current_queue_length"),
|
||||||
"Displays the total number of threads that are currently waiting to acquire a managed lock in the application.",
|
"Displays the total number of threads that are currently waiting to acquire a managed lock in the application.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofcurrentlogicalThreads = prometheus.NewDesc(
|
c.numberOfCurrentLogicalThreads = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "current_logical_threads"),
|
prometheus.BuildFQName(types.Namespace, Name, "current_logical_threads"),
|
||||||
"Displays the number of current managed thread objects in the application. This counter maintains the count of both running and stopped threads. ",
|
"Displays the number of current managed thread objects in the application. This counter maintains the count of both running and stopped threads. ",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofcurrentphysicalThreads = prometheus.NewDesc(
|
c.numberOfCurrentPhysicalThreads = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "physical_threads_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "physical_threads_current"),
|
||||||
"Displays the number of native operating system threads created and owned by the common language runtime to act as underlying threads for managed thread objects. This counter's value does not include the threads used by the runtime in its internal operations; it is a subset of the threads in the operating system process.",
|
"Displays the number of native operating system threads created and owned by the common language runtime to act as underlying threads for managed thread objects. This counter's value does not include the threads used by the runtime in its internal operations; it is a subset of the threads in the operating system process.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Numberofcurrentrecognizedthreads = prometheus.NewDesc(
|
c.numberOfCurrentRecognizedThreads = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "recognized_threads_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "recognized_threads_current"),
|
||||||
"Displays the number of threads that are currently recognized by the runtime. These threads are associated with a corresponding managed thread object. The runtime does not create these threads, but they have run inside the runtime at least once.",
|
"Displays the number of threads that are currently recognized by the runtime. These threads are associated with a corresponding managed thread object. The runtime does not create these threads, but they have run inside the runtime at least once.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Numberoftotalrecognizedthreads = prometheus.NewDesc(
|
c.numberOfTotalRecognizedThreads = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "recognized_threads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "recognized_threads_total"),
|
||||||
"Displays the total number of threads that have been recognized by the runtime since the application started. These threads are associated with a corresponding managed thread object. The runtime does not create these threads, but they have run inside the runtime at least once.",
|
"Displays the total number of threads that have been recognized by the runtime since the application started. These threads are associated with a corresponding managed thread object. The runtime does not create these threads, but they have run inside the runtime at least once.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.QueueLengthPeak = prometheus.NewDesc(
|
c.queueLengthPeak = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "queue_length_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "queue_length_total"),
|
||||||
"Displays the total number of threads that waited to acquire a managed lock since the application started.",
|
"Displays the total number of threads that waited to acquire a managed lock since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalNumberofContentions = prometheus.NewDesc(
|
c.totalNumberOfContentions = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "contentions_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "contentions_total"),
|
||||||
"Displays the total number of times that threads in the runtime have attempted to acquire a managed lock unsuccessfully.",
|
"Displays the total number of times that threads in the runtime have attempted to acquire a managed lock unsuccessfully.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -100,7 +113,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrlocksandthreads metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrlocksandthreads metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -123,7 +136,7 @@ type Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads struct {
|
|||||||
TotalNumberofContentions uint32
|
TotalNumberofContentions uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -131,55 +144,54 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentQueueLength,
|
c.currentQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.CurrentQueueLength),
|
float64(process.CurrentQueueLength),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofcurrentlogicalThreads,
|
c.numberOfCurrentLogicalThreads,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberofcurrentlogicalThreads),
|
float64(process.NumberofcurrentlogicalThreads),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofcurrentphysicalThreads,
|
c.numberOfCurrentPhysicalThreads,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberofcurrentphysicalThreads),
|
float64(process.NumberofcurrentphysicalThreads),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Numberofcurrentrecognizedthreads,
|
c.numberOfCurrentRecognizedThreads,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Numberofcurrentrecognizedthreads),
|
float64(process.Numberofcurrentrecognizedthreads),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Numberoftotalrecognizedthreads,
|
c.numberOfTotalRecognizedThreads,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.Numberoftotalrecognizedthreads),
|
float64(process.Numberoftotalrecognizedthreads),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.QueueLengthPeak,
|
c.queueLengthPeak,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.QueueLengthPeak),
|
float64(process.QueueLengthPeak),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalNumberofContentions,
|
c.totalNumberOfContentions,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalNumberofContentions),
|
float64(process.TotalNumberofContentions),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,117 +17,127 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
AllocatedBytes *prometheus.Desc
|
allocatedBytes *prometheus.Desc
|
||||||
FinalizationSurvivors *prometheus.Desc
|
finalizationSurvivors *prometheus.Desc
|
||||||
HeapSize *prometheus.Desc
|
heapSize *prometheus.Desc
|
||||||
PromotedBytes *prometheus.Desc
|
promotedBytes *prometheus.Desc
|
||||||
NumberGCHandles *prometheus.Desc
|
numberGCHandles *prometheus.Desc
|
||||||
NumberCollections *prometheus.Desc
|
numberCollections *prometheus.Desc
|
||||||
NumberInducedGC *prometheus.Desc
|
numberInducedGC *prometheus.Desc
|
||||||
NumberofPinnedObjects *prometheus.Desc
|
numberOfPinnedObjects *prometheus.Desc
|
||||||
NumberofSinkBlocksinuse *prometheus.Desc
|
numberOfSinkBlocksInUse *prometheus.Desc
|
||||||
NumberTotalCommittedBytes *prometheus.Desc
|
numberTotalCommittedBytes *prometheus.Desc
|
||||||
NumberTotalreservedBytes *prometheus.Desc
|
numberTotalReservedBytes *prometheus.Desc
|
||||||
TimeinGC *prometheus.Desc
|
timeInGC *prometheus.Desc
|
||||||
PromotedFinalizationMemoryfromGen0 *prometheus.Desc
|
|
||||||
PromotedMemoryfromGen0 *prometheus.Desc
|
|
||||||
PromotedMemoryfromGen1 *prometheus.Desc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.AllocatedBytes = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.allocatedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "allocated_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "allocated_bytes_total"),
|
||||||
"Displays the total number of bytes allocated on the garbage collection heap.",
|
"Displays the total number of bytes allocated on the garbage collection heap.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FinalizationSurvivors = prometheus.NewDesc(
|
c.finalizationSurvivors = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "finalization_survivors"),
|
prometheus.BuildFQName(types.Namespace, Name, "finalization_survivors"),
|
||||||
"Displays the number of garbage-collected objects that survive a collection because they are waiting to be finalized.",
|
"Displays the number of garbage-collected objects that survive a collection because they are waiting to be finalized.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.HeapSize = prometheus.NewDesc(
|
c.heapSize = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "heap_size_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "heap_size_bytes"),
|
||||||
"Displays the maximum bytes that can be allocated; it does not indicate the current number of bytes allocated.",
|
"Displays the maximum bytes that can be allocated; it does not indicate the current number of bytes allocated.",
|
||||||
[]string{"process", "area"},
|
[]string{"process", "area"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PromotedBytes = prometheus.NewDesc(
|
c.promotedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "promoted_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "promoted_bytes"),
|
||||||
"Displays the bytes that were promoted from the generation to the next one during the last GC. Memory is promoted when it survives a garbage collection.",
|
"Displays the bytes that were promoted from the generation to the next one during the last GC. Memory is promoted when it survives a garbage collection.",
|
||||||
[]string{"process", "area"},
|
[]string{"process", "area"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberGCHandles = prometheus.NewDesc(
|
c.numberGCHandles = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "number_gc_handles"),
|
prometheus.BuildFQName(types.Namespace, Name, "number_gc_handles"),
|
||||||
"Displays the current number of garbage collection handles in use. Garbage collection handles are handles to resources external to the common language runtime and the managed environment.",
|
"Displays the current number of garbage collection handles in use. Garbage collection handles are handles to resources external to the common language runtime and the managed environment.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberCollections = prometheus.NewDesc(
|
c.numberCollections = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "collections_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "collections_total"),
|
||||||
"Displays the number of times the generation objects are garbage collected since the application started.",
|
"Displays the number of times the generation objects are garbage collected since the application started.",
|
||||||
[]string{"process", "area"},
|
[]string{"process", "area"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberInducedGC = prometheus.NewDesc(
|
c.numberInducedGC = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "induced_gc_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "induced_gc_total"),
|
||||||
"Displays the peak number of times garbage collection was performed because of an explicit call to GC.Collect.",
|
"Displays the peak number of times garbage collection was performed because of an explicit call to GC.Collect.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofPinnedObjects = prometheus.NewDesc(
|
c.numberOfPinnedObjects = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "number_pinned_objects"),
|
prometheus.BuildFQName(types.Namespace, Name, "number_pinned_objects"),
|
||||||
"Displays the number of pinned objects encountered in the last garbage collection.",
|
"Displays the number of pinned objects encountered in the last garbage collection.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberofSinkBlocksinuse = prometheus.NewDesc(
|
c.numberOfSinkBlocksInUse = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "number_sink_blocksinuse"),
|
prometheus.BuildFQName(types.Namespace, Name, "number_sink_blocksinuse"),
|
||||||
"Displays the current number of synchronization blocks in use. Synchronization blocks are per-object data structures allocated for storing synchronization information. They hold weak references to managed objects and must be scanned by the garbage collector.",
|
"Displays the current number of synchronization blocks in use. Synchronization blocks are per-object data structures allocated for storing synchronization information. They hold weak references to managed objects and must be scanned by the garbage collector.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberTotalCommittedBytes = prometheus.NewDesc(
|
c.numberTotalCommittedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "committed_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "committed_bytes"),
|
||||||
"Displays the amount of virtual memory, in bytes, currently committed by the garbage collector. Committed memory is the physical memory for which space has been reserved in the disk paging file.",
|
"Displays the amount of virtual memory, in bytes, currently committed by the garbage collector. Committed memory is the physical memory for which space has been reserved in the disk paging file.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NumberTotalreservedBytes = prometheus.NewDesc(
|
c.numberTotalReservedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "reserved_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "reserved_bytes"),
|
||||||
"Displays the amount of virtual memory, in bytes, currently reserved by the garbage collector. Reserved memory is the virtual memory space reserved for the application when no disk or main memory pages have been used.",
|
"Displays the amount of virtual memory, in bytes, currently reserved by the garbage collector. Reserved memory is the virtual memory space reserved for the application when no disk or main memory pages have been used.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TimeinGC = prometheus.NewDesc(
|
c.timeInGC = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gc_time_percent"),
|
prometheus.BuildFQName(types.Namespace, Name, "gc_time_percent"),
|
||||||
"Displays the percentage of time that was spent performing a garbage collection in the last sample.",
|
"Displays the percentage of time that was spent performing a garbage collection in the last sample.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -138,7 +148,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrmemory metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrmemory metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -180,7 +190,7 @@ type Win32_PerfRawData_NETFramework_NETCLRMemory struct {
|
|||||||
PromotedMemoryfromGen1 uint64
|
PromotedMemoryfromGen1 uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -188,27 +198,26 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AllocatedBytes,
|
c.allocatedBytes,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.AllocatedBytesPersec),
|
float64(process.AllocatedBytesPersec),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FinalizationSurvivors,
|
c.finalizationSurvivors,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.FinalizationSurvivors),
|
float64(process.FinalizationSurvivors),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HeapSize,
|
c.heapSize,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Gen0heapsize),
|
float64(process.Gen0heapsize),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -216,7 +225,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PromotedBytes,
|
c.promotedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Gen0PromotedBytesPerSec),
|
float64(process.Gen0PromotedBytesPerSec),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -224,7 +233,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HeapSize,
|
c.heapSize,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Gen1heapsize),
|
float64(process.Gen1heapsize),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -232,7 +241,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PromotedBytes,
|
c.promotedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Gen1PromotedBytesPerSec),
|
float64(process.Gen1PromotedBytesPerSec),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -240,7 +249,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HeapSize,
|
c.heapSize,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Gen2heapsize),
|
float64(process.Gen2heapsize),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -248,7 +257,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HeapSize,
|
c.heapSize,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.LargeObjectHeapsize),
|
float64(process.LargeObjectHeapsize),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -256,14 +265,14 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberGCHandles,
|
c.numberGCHandles,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberGCHandles),
|
float64(process.NumberGCHandles),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberCollections,
|
c.numberCollections,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberGen0Collections),
|
float64(process.NumberGen0Collections),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -271,7 +280,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberCollections,
|
c.numberCollections,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberGen1Collections),
|
float64(process.NumberGen1Collections),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -279,7 +288,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberCollections,
|
c.numberCollections,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberGen2Collections),
|
float64(process.NumberGen2Collections),
|
||||||
process.Name,
|
process.Name,
|
||||||
@@ -287,42 +296,42 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberInducedGC,
|
c.numberInducedGC,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberInducedGC),
|
float64(process.NumberInducedGC),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofPinnedObjects,
|
c.numberOfPinnedObjects,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberofPinnedObjects),
|
float64(process.NumberofPinnedObjects),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberofSinkBlocksinuse,
|
c.numberOfSinkBlocksInUse,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberofSinkBlocksinuse),
|
float64(process.NumberofSinkBlocksinuse),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberTotalCommittedBytes,
|
c.numberTotalCommittedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberTotalcommittedBytes),
|
float64(process.NumberTotalcommittedBytes),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberTotalreservedBytes,
|
c.numberTotalReservedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.NumberTotalreservedBytes),
|
float64(process.NumberTotalreservedBytes),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeinGC,
|
c.timeInGC,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(100*process.PercentTimeinGC)/float64(process.PercentTimeinGC_base),
|
float64(100*process.PercentTimeinGC)/float64(process.PercentTimeinGC_base),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,72 +17,85 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
Channels *prometheus.Desc
|
channels *prometheus.Desc
|
||||||
ContextBoundClassesLoaded *prometheus.Desc
|
contextBoundClassesLoaded *prometheus.Desc
|
||||||
ContextBoundObjects *prometheus.Desc
|
contextBoundObjects *prometheus.Desc
|
||||||
ContextProxies *prometheus.Desc
|
contextProxies *prometheus.Desc
|
||||||
Contexts *prometheus.Desc
|
contexts *prometheus.Desc
|
||||||
TotalRemoteCalls *prometheus.Desc
|
totalRemoteCalls *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.Channels = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.channels = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "channels_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "channels_total"),
|
||||||
"Displays the total number of remoting channels registered across all application domains since application started.",
|
"Displays the total number of remoting channels registered across all application domains since application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ContextBoundClassesLoaded = prometheus.NewDesc(
|
c.contextBoundClassesLoaded = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "context_bound_classes_loaded"),
|
prometheus.BuildFQName(types.Namespace, Name, "context_bound_classes_loaded"),
|
||||||
"Displays the current number of context-bound classes that are loaded.",
|
"Displays the current number of context-bound classes that are loaded.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ContextBoundObjects = prometheus.NewDesc(
|
c.contextBoundObjects = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "context_bound_objects_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "context_bound_objects_total"),
|
||||||
"Displays the total number of context-bound objects allocated.",
|
"Displays the total number of context-bound objects allocated.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ContextProxies = prometheus.NewDesc(
|
c.contextProxies = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "context_proxies_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "context_proxies_total"),
|
||||||
"Displays the total number of remoting proxy objects in this process since it started.",
|
"Displays the total number of remoting proxy objects in this process since it started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Contexts = prometheus.NewDesc(
|
c.contexts = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "contexts"),
|
prometheus.BuildFQName(types.Namespace, Name, "contexts"),
|
||||||
"Displays the current number of remoting contexts in the application.",
|
"Displays the current number of remoting contexts in the application.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalRemoteCalls = prometheus.NewDesc(
|
c.totalRemoteCalls = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "remote_calls_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "remote_calls_total"),
|
||||||
"Displays the total number of remote procedure calls invoked since the application started.",
|
"Displays the total number of remote procedure calls invoked since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -93,7 +106,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrremoting metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrremoting metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -113,7 +126,7 @@ type Win32_PerfRawData_NETFramework_NETCLRRemoting struct {
|
|||||||
TotalRemoteCalls uint32
|
TotalRemoteCalls uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -121,48 +134,47 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Channels,
|
c.channels,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.Channels),
|
float64(process.Channels),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContextBoundClassesLoaded,
|
c.contextBoundClassesLoaded,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.ContextBoundClassesLoaded),
|
float64(process.ContextBoundClassesLoaded),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContextBoundObjects,
|
c.contextBoundObjects,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.ContextBoundObjectsAllocPersec),
|
float64(process.ContextBoundObjectsAllocPersec),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContextProxies,
|
c.contextProxies,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.ContextProxies),
|
float64(process.ContextProxies),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Contexts,
|
c.contexts,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.Contexts),
|
float64(process.Contexts),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalRemoteCalls,
|
c.totalRemoteCalls,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalRemoteCalls),
|
float64(process.TotalRemoteCalls),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,58 +17,71 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
NumberLinkTimeChecks *prometheus.Desc
|
numberLinkTimeChecks *prometheus.Desc
|
||||||
TimeinRTchecks *prometheus.Desc
|
timeInRTChecks *prometheus.Desc
|
||||||
StackWalkDepth *prometheus.Desc
|
stackWalkDepth *prometheus.Desc
|
||||||
TotalRuntimeChecks *prometheus.Desc
|
totalRuntimeChecks *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.NumberLinkTimeChecks = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.numberLinkTimeChecks = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "link_time_checks_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "link_time_checks_total"),
|
||||||
"Displays the total number of link-time code access security checks since the application started.",
|
"Displays the total number of link-time code access security checks since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TimeinRTchecks = prometheus.NewDesc(
|
c.timeInRTChecks = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "rt_checks_time_percent"),
|
prometheus.BuildFQName(types.Namespace, Name, "rt_checks_time_percent"),
|
||||||
"Displays the percentage of time spent performing runtime code access security checks in the last sample.",
|
"Displays the percentage of time spent performing runtime code access security checks in the last sample.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.StackWalkDepth = prometheus.NewDesc(
|
c.stackWalkDepth = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "stack_walk_depth"),
|
prometheus.BuildFQName(types.Namespace, Name, "stack_walk_depth"),
|
||||||
"Displays the depth of the stack during that last runtime code access security check.",
|
"Displays the depth of the stack during that last runtime code access security check.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalRuntimeChecks = prometheus.NewDesc(
|
c.totalRuntimeChecks = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "runtime_checks_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "runtime_checks_total"),
|
||||||
"Displays the total number of runtime code access security checks performed since the application started.",
|
"Displays the total number of runtime code access security checks performed since the application started.",
|
||||||
[]string{"process"},
|
[]string{"process"},
|
||||||
@@ -79,7 +92,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrsecurity metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrsecurity metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -98,7 +111,7 @@ type Win32_PerfRawData_NETFramework_NETCLRSecurity struct {
|
|||||||
TotalRuntimeChecks uint32
|
TotalRuntimeChecks uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -106,34 +119,33 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, process := range dst {
|
for _, process := range dst {
|
||||||
|
|
||||||
if process.Name == "_Global_" {
|
if process.Name == "_Global_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NumberLinkTimeChecks,
|
c.numberLinkTimeChecks,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.NumberLinkTimeChecks),
|
float64(process.NumberLinkTimeChecks),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TimeinRTchecks,
|
c.timeInRTChecks,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PercentTimeinRTchecks)/float64(process.Frequency_PerfTime),
|
float64(process.PercentTimeinRTchecks)/float64(process.Frequency_PerfTime),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StackWalkDepth,
|
c.stackWalkDepth,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.StackWalkDepth),
|
float64(process.StackWalkDepth),
|
||||||
process.Name,
|
process.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalRuntimeChecks,
|
c.totalRuntimeChecks,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.TotalRuntimeChecks),
|
float64(process.TotalRuntimeChecks),
|
||||||
process.Name,
|
process.Name,
|
||||||
|
|||||||
@@ -17,207 +17,220 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// collector is a Prometheus collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics
|
// Collector is a Prometheus Collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
AccessAccepts *prometheus.Desc
|
accessAccepts *prometheus.Desc
|
||||||
AccessChallenges *prometheus.Desc
|
accessChallenges *prometheus.Desc
|
||||||
AccessRejects *prometheus.Desc
|
accessRejects *prometheus.Desc
|
||||||
AccessRequests *prometheus.Desc
|
accessRequests *prometheus.Desc
|
||||||
AccessBadAuthenticators *prometheus.Desc
|
accessBadAuthenticators *prometheus.Desc
|
||||||
AccessDroppedPackets *prometheus.Desc
|
accessDroppedPackets *prometheus.Desc
|
||||||
AccessInvalidRequests *prometheus.Desc
|
accessInvalidRequests *prometheus.Desc
|
||||||
AccessMalformedPackets *prometheus.Desc
|
accessMalformedPackets *prometheus.Desc
|
||||||
AccessPacketsReceived *prometheus.Desc
|
accessPacketsReceived *prometheus.Desc
|
||||||
AccessPacketsSent *prometheus.Desc
|
accessPacketsSent *prometheus.Desc
|
||||||
AccessServerResetTime *prometheus.Desc
|
accessServerResetTime *prometheus.Desc
|
||||||
AccessServerUpTime *prometheus.Desc
|
accessServerUpTime *prometheus.Desc
|
||||||
AccessUnknownType *prometheus.Desc
|
accessUnknownType *prometheus.Desc
|
||||||
|
|
||||||
AccountingRequests *prometheus.Desc
|
accountingRequests *prometheus.Desc
|
||||||
AccountingResponses *prometheus.Desc
|
accountingResponses *prometheus.Desc
|
||||||
AccountingBadAuthenticators *prometheus.Desc
|
accountingBadAuthenticators *prometheus.Desc
|
||||||
AccountingDroppedPackets *prometheus.Desc
|
accountingDroppedPackets *prometheus.Desc
|
||||||
AccountingInvalidRequests *prometheus.Desc
|
accountingInvalidRequests *prometheus.Desc
|
||||||
AccountingMalformedPackets *prometheus.Desc
|
accountingMalformedPackets *prometheus.Desc
|
||||||
AccountingNoRecord *prometheus.Desc
|
accountingNoRecord *prometheus.Desc
|
||||||
AccountingPacketsReceived *prometheus.Desc
|
accountingPacketsReceived *prometheus.Desc
|
||||||
AccountingPacketsSent *prometheus.Desc
|
accountingPacketsSent *prometheus.Desc
|
||||||
AccountingServerResetTime *prometheus.Desc
|
accountingServerResetTime *prometheus.Desc
|
||||||
AccountingServerUpTime *prometheus.Desc
|
accountingServerUpTime *prometheus.Desc
|
||||||
AccountingUnknownType *prometheus.Desc
|
accountingUnknownType *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.AccessAccepts = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.accessAccepts = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_accepts"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_accepts"),
|
||||||
"(AccessAccepts)",
|
"(AccessAccepts)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessChallenges = prometheus.NewDesc(
|
c.accessChallenges = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_challenges"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_challenges"),
|
||||||
"(AccessChallenges)",
|
"(AccessChallenges)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessRejects = prometheus.NewDesc(
|
c.accessRejects = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_rejects"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_rejects"),
|
||||||
"(AccessRejects)",
|
"(AccessRejects)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessRequests = prometheus.NewDesc(
|
c.accessRequests = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_requests"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_requests"),
|
||||||
"(AccessRequests)",
|
"(AccessRequests)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessBadAuthenticators = prometheus.NewDesc(
|
c.accessBadAuthenticators = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_bad_authenticators"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_bad_authenticators"),
|
||||||
"(BadAuthenticators)",
|
"(BadAuthenticators)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessDroppedPackets = prometheus.NewDesc(
|
c.accessDroppedPackets = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_dropped_packets"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_dropped_packets"),
|
||||||
"(DroppedPackets)",
|
"(DroppedPackets)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessInvalidRequests = prometheus.NewDesc(
|
c.accessInvalidRequests = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_invalid_requests"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_invalid_requests"),
|
||||||
"(InvalidRequests)",
|
"(InvalidRequests)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessMalformedPackets = prometheus.NewDesc(
|
c.accessMalformedPackets = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_malformed_packets"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_malformed_packets"),
|
||||||
"(MalformedPackets)",
|
"(MalformedPackets)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessPacketsReceived = prometheus.NewDesc(
|
c.accessPacketsReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_packets_received"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_packets_received"),
|
||||||
"(PacketsReceived)",
|
"(PacketsReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessPacketsSent = prometheus.NewDesc(
|
c.accessPacketsSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_packets_sent"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_packets_sent"),
|
||||||
"(PacketsSent)",
|
"(PacketsSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessServerResetTime = prometheus.NewDesc(
|
c.accessServerResetTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_server_reset_time"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_server_reset_time"),
|
||||||
"(ServerResetTime)",
|
"(ServerResetTime)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessServerUpTime = prometheus.NewDesc(
|
c.accessServerUpTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_server_up_time"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_server_up_time"),
|
||||||
"(ServerUpTime)",
|
"(ServerUpTime)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccessUnknownType = prometheus.NewDesc(
|
c.accessUnknownType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_unknown_type"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_unknown_type"),
|
||||||
"(UnknownType)",
|
"(UnknownType)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.AccountingRequests = prometheus.NewDesc(
|
c.accountingRequests = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_requests"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_requests"),
|
||||||
"(AccountingRequests)",
|
"(AccountingRequests)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingResponses = prometheus.NewDesc(
|
c.accountingResponses = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_responses"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_responses"),
|
||||||
"(AccountingResponses)",
|
"(AccountingResponses)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingBadAuthenticators = prometheus.NewDesc(
|
c.accountingBadAuthenticators = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_bad_authenticators"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_bad_authenticators"),
|
||||||
"(BadAuthenticators)",
|
"(BadAuthenticators)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingDroppedPackets = prometheus.NewDesc(
|
c.accountingDroppedPackets = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_dropped_packets"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_dropped_packets"),
|
||||||
"(DroppedPackets)",
|
"(DroppedPackets)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingInvalidRequests = prometheus.NewDesc(
|
c.accountingInvalidRequests = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_invalid_requests"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_invalid_requests"),
|
||||||
"(InvalidRequests)",
|
"(InvalidRequests)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingMalformedPackets = prometheus.NewDesc(
|
c.accountingMalformedPackets = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_malformed_packets"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_malformed_packets"),
|
||||||
"(MalformedPackets)",
|
"(MalformedPackets)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingNoRecord = prometheus.NewDesc(
|
c.accountingNoRecord = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_no_record"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_no_record"),
|
||||||
"(NoRecord)",
|
"(NoRecord)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingPacketsReceived = prometheus.NewDesc(
|
c.accountingPacketsReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_packets_received"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_packets_received"),
|
||||||
"(PacketsReceived)",
|
"(PacketsReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingPacketsSent = prometheus.NewDesc(
|
c.accountingPacketsSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_packets_sent"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_packets_sent"),
|
||||||
"(PacketsSent)",
|
"(PacketsSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingServerResetTime = prometheus.NewDesc(
|
c.accountingServerResetTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_server_reset_time"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_server_reset_time"),
|
||||||
"(ServerResetTime)",
|
"(ServerResetTime)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingServerUpTime = prometheus.NewDesc(
|
c.accountingServerUpTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_server_up_time"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_server_up_time"),
|
||||||
"(ServerUpTime)",
|
"(ServerUpTime)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AccountingUnknownType = prometheus.NewDesc(
|
c.accountingUnknownType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "accounting_unknown_type"),
|
prometheus.BuildFQName(types.Namespace, Name, "accounting_unknown_type"),
|
||||||
"(UnknownType)",
|
"(UnknownType)",
|
||||||
nil,
|
nil,
|
||||||
@@ -228,7 +241,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.CollectAccept(ch); err != nil {
|
if err := c.CollectAccept(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("failed collecting NPS accept data: %s", err))
|
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("failed collecting NPS accept data: %s", err))
|
||||||
return err
|
return err
|
||||||
@@ -241,7 +254,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Win32_PerfRawData_IAS_NPSAuthenticationServer docs:
|
// Win32_PerfRawData_IAS_NPSAuthenticationServer docs:
|
||||||
// at the moment there is no Microsoft documentation
|
// at the moment there is no Microsoft documentation.
|
||||||
type Win32_PerfRawData_IAS_NPSAuthenticationServer struct {
|
type Win32_PerfRawData_IAS_NPSAuthenticationServer struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -279,7 +292,7 @@ type Win32_PerfRawData_IAS_NPSAccountingServer struct {
|
|||||||
|
|
||||||
// CollectAccept sends the metric values for each metric
|
// CollectAccept sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
func (c *Collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_IAS_NPSAuthenticationServer
|
var dst []Win32_PerfRawData_IAS_NPSAuthenticationServer
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -287,79 +300,79 @@ func (c *collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessAccepts,
|
c.accessAccepts,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessAccepts),
|
float64(dst[0].AccessAccepts),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessChallenges,
|
c.accessChallenges,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessChallenges),
|
float64(dst[0].AccessChallenges),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessRejects,
|
c.accessRejects,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessRejects),
|
float64(dst[0].AccessRejects),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessRequests,
|
c.accessRequests,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessRequests),
|
float64(dst[0].AccessRequests),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessBadAuthenticators,
|
c.accessBadAuthenticators,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessBadAuthenticators),
|
float64(dst[0].AccessBadAuthenticators),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessDroppedPackets,
|
c.accessDroppedPackets,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessDroppedPackets),
|
float64(dst[0].AccessDroppedPackets),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessInvalidRequests,
|
c.accessInvalidRequests,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessInvalidRequests),
|
float64(dst[0].AccessInvalidRequests),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessMalformedPackets,
|
c.accessMalformedPackets,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessMalformedPackets),
|
float64(dst[0].AccessMalformedPackets),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessPacketsReceived,
|
c.accessPacketsReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessPacketsReceived),
|
float64(dst[0].AccessPacketsReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessPacketsSent,
|
c.accessPacketsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessPacketsSent),
|
float64(dst[0].AccessPacketsSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessServerResetTime,
|
c.accessServerResetTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessServerResetTime),
|
float64(dst[0].AccessServerResetTime),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessServerUpTime,
|
c.accessServerUpTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessServerUpTime),
|
float64(dst[0].AccessServerUpTime),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccessUnknownType,
|
c.accessUnknownType,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccessUnknownType),
|
float64(dst[0].AccessUnknownType),
|
||||||
)
|
)
|
||||||
@@ -367,7 +380,7 @@ func (c *collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) CollectAccounting(ch chan<- prometheus.Metric) error {
|
func (c *Collector) CollectAccounting(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_IAS_NPSAccountingServer
|
var dst []Win32_PerfRawData_IAS_NPSAccountingServer
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -375,73 +388,73 @@ func (c *collector) CollectAccounting(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingRequests,
|
c.accountingRequests,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingRequests),
|
float64(dst[0].AccountingRequests),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingResponses,
|
c.accountingResponses,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingResponses),
|
float64(dst[0].AccountingResponses),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingBadAuthenticators,
|
c.accountingBadAuthenticators,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingBadAuthenticators),
|
float64(dst[0].AccountingBadAuthenticators),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingDroppedPackets,
|
c.accountingDroppedPackets,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingDroppedPackets),
|
float64(dst[0].AccountingDroppedPackets),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingInvalidRequests,
|
c.accountingInvalidRequests,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingInvalidRequests),
|
float64(dst[0].AccountingInvalidRequests),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingMalformedPackets,
|
c.accountingMalformedPackets,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingMalformedPackets),
|
float64(dst[0].AccountingMalformedPackets),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingNoRecord,
|
c.accountingNoRecord,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingNoRecord),
|
float64(dst[0].AccountingNoRecord),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingPacketsReceived,
|
c.accountingPacketsReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingPacketsReceived),
|
float64(dst[0].AccountingPacketsReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingPacketsSent,
|
c.accountingPacketsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingPacketsSent),
|
float64(dst[0].AccountingPacketsSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingServerResetTime,
|
c.accountingServerResetTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingServerResetTime),
|
float64(dst[0].AccountingServerResetTime),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingServerUpTime,
|
c.accountingServerUpTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingServerUpTime),
|
float64(dst[0].AccountingServerUpTime),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AccountingUnknownType,
|
c.accountingUnknownType,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AccountingUnknownType),
|
float64(dst[0].AccountingUnknownType),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/alecthomas/kingpin/v2"
|
||||||
|
"github.com/go-kit/log"
|
||||||
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/kernel32"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/kernel32"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/netapi32"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/netapi32"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/psapi"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/psapi"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/sysinfoapi"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/sysinfoapi"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/go-kit/log/level"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
@@ -31,23 +30,24 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI metrics
|
// A Collector is a Prometheus Collector for WMI metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
OSInformation *prometheus.Desc
|
osInformation *prometheus.Desc
|
||||||
PhysicalMemoryFreeBytes *prometheus.Desc
|
pagingFreeBytes *prometheus.Desc
|
||||||
PagingFreeBytes *prometheus.Desc
|
pagingLimitBytes *prometheus.Desc
|
||||||
VirtualMemoryFreeBytes *prometheus.Desc
|
physicalMemoryFreeBytes *prometheus.Desc
|
||||||
ProcessesLimit *prometheus.Desc
|
processMemoryLimitBytes *prometheus.Desc
|
||||||
ProcessMemoryLimitBytes *prometheus.Desc
|
processes *prometheus.Desc
|
||||||
Processes *prometheus.Desc
|
processesLimit *prometheus.Desc
|
||||||
Users *prometheus.Desc
|
time *prometheus.Desc
|
||||||
PagingLimitBytes *prometheus.Desc
|
timezone *prometheus.Desc
|
||||||
VirtualMemoryBytes *prometheus.Desc
|
users *prometheus.Desc
|
||||||
VisibleMemoryBytes *prometheus.Desc
|
virtualMemoryBytes *prometheus.Desc
|
||||||
Time *prometheus.Desc
|
virtualMemoryFreeBytes *prometheus.Desc
|
||||||
Timezone *prometheus.Desc
|
visibleMemoryBytes *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
type pagingFileCounter struct {
|
type pagingFileCounter struct {
|
||||||
@@ -56,102 +56,114 @@ type pagingFileCounter struct {
|
|||||||
UsagePeak float64 `perflib:"% Usage Peak"`
|
UsagePeak float64 `perflib:"% Usage Peak"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Paging File"}, nil
|
return []string{"Paging File"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.OSInformation = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.osInformation = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||||
"OperatingSystem.Caption, OperatingSystem.Version",
|
"OperatingSystem.Caption, OperatingSystem.Version",
|
||||||
[]string{"product", "version", "major_version", "minor_version", "build_number", "revision"},
|
[]string{"product", "version", "major_version", "minor_version", "build_number", "revision"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PagingLimitBytes = prometheus.NewDesc(
|
c.pagingLimitBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "paging_limit_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "paging_limit_bytes"),
|
||||||
"OperatingSystem.SizeStoredInPagingFiles",
|
"OperatingSystem.SizeStoredInPagingFiles",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PagingFreeBytes = prometheus.NewDesc(
|
c.pagingFreeBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "paging_free_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "paging_free_bytes"),
|
||||||
"OperatingSystem.FreeSpaceInPagingFiles",
|
"OperatingSystem.FreeSpaceInPagingFiles",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PhysicalMemoryFreeBytes = prometheus.NewDesc(
|
c.physicalMemoryFreeBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "physical_memory_free_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "physical_memory_free_bytes"),
|
||||||
"OperatingSystem.FreePhysicalMemory",
|
"OperatingSystem.FreePhysicalMemory",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Time = prometheus.NewDesc(
|
c.time = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "time"),
|
prometheus.BuildFQName(types.Namespace, Name, "time"),
|
||||||
"OperatingSystem.LocalDateTime",
|
"OperatingSystem.LocalDateTime",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Timezone = prometheus.NewDesc(
|
c.timezone = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "timezone"),
|
prometheus.BuildFQName(types.Namespace, Name, "timezone"),
|
||||||
"OperatingSystem.LocalDateTime",
|
"OperatingSystem.LocalDateTime",
|
||||||
[]string{"timezone"},
|
[]string{"timezone"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Processes = prometheus.NewDesc(
|
c.processes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processes"),
|
prometheus.BuildFQName(types.Namespace, Name, "processes"),
|
||||||
"OperatingSystem.NumberOfProcesses",
|
"OperatingSystem.NumberOfProcesses",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessesLimit = prometheus.NewDesc(
|
c.processesLimit = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processes_limit"),
|
prometheus.BuildFQName(types.Namespace, Name, "processes_limit"),
|
||||||
"OperatingSystem.MaxNumberOfProcesses",
|
"OperatingSystem.MaxNumberOfProcesses",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessMemoryLimitBytes = prometheus.NewDesc(
|
c.processMemoryLimitBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "process_memory_limit_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "process_memory_limit_bytes"),
|
||||||
"OperatingSystem.MaxProcessMemorySize",
|
"OperatingSystem.MaxProcessMemorySize",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Users = prometheus.NewDesc(
|
c.users = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "users"),
|
prometheus.BuildFQName(types.Namespace, Name, "users"),
|
||||||
"OperatingSystem.NumberOfUsers",
|
"OperatingSystem.NumberOfUsers",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.VirtualMemoryBytes = prometheus.NewDesc(
|
c.virtualMemoryBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "virtual_memory_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "virtual_memory_bytes"),
|
||||||
"OperatingSystem.TotalVirtualMemorySize",
|
"OperatingSystem.TotalVirtualMemorySize",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.VisibleMemoryBytes = prometheus.NewDesc(
|
c.visibleMemoryBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "visible_memory_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "visible_memory_bytes"),
|
||||||
"OperatingSystem.TotalVisibleMemorySize",
|
"OperatingSystem.TotalVisibleMemorySize",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.VirtualMemoryFreeBytes = prometheus.NewDesc(
|
c.virtualMemoryFreeBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "virtual_memory_free_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "virtual_memory_free_bytes"),
|
||||||
"OperatingSystem.FreeVirtualMemory",
|
"OperatingSystem.FreeVirtualMemory",
|
||||||
nil,
|
nil,
|
||||||
@@ -162,7 +174,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting os metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting os metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -171,7 +183,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Win32_OperatingSystem docs:
|
// Win32_OperatingSystem docs:
|
||||||
// - https://msdn.microsoft.com/en-us/library/aa394239 - Win32_OperatingSystem class
|
// - https://msdn.microsoft.com/en-us/library/aa394239 - Win32_OperatingSystem class.
|
||||||
type Win32_OperatingSystem struct {
|
type Win32_OperatingSystem struct {
|
||||||
Caption string
|
Caption string
|
||||||
FreePhysicalMemory uint64
|
FreePhysicalMemory uint64
|
||||||
@@ -188,7 +200,7 @@ type Win32_OperatingSystem struct {
|
|||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
nwgi, err := netapi32.GetWorkstationInfo()
|
nwgi, err := netapi32.GetWorkstationInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -211,11 +223,12 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
// Get total allocation of paging files across all disks.
|
// Get total allocation of paging files across all disks.
|
||||||
memManKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management`, registry.QUERY_VALUE)
|
memManKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management`, registry.QUERY_VALUE)
|
||||||
defer memManKey.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer memManKey.Close()
|
||||||
|
|
||||||
pagingFiles, _, pagingErr := memManKey.GetStringsValue("ExistingPageFiles")
|
pagingFiles, _, pagingErr := memManKey.GetStringsValue("ExistingPageFiles")
|
||||||
|
|
||||||
var fsipf float64
|
var fsipf float64
|
||||||
@@ -232,12 +245,12 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
// Get build number and product name from registry
|
// Get build number and product name from registry
|
||||||
ntKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
ntKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
||||||
defer ntKey.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer ntKey.Close()
|
||||||
|
|
||||||
pn, _, err := ntKey.GetStringValue("ProductName")
|
pn, _, err := ntKey.GetStringValue("ProductName")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -278,7 +291,7 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
pfb := fsipf - (pfbRaw * float64(gpi.PageSize))
|
pfb := fsipf - (pfbRaw * float64(gpi.PageSize))
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OSInformation,
|
c.osInformation,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1.0,
|
1.0,
|
||||||
"Microsoft "+pn, // Caption
|
"Microsoft "+pn, // Caption
|
||||||
@@ -290,19 +303,19 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PhysicalMemoryFreeBytes,
|
c.physicalMemoryFreeBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(gmse.AvailPhys),
|
float64(gmse.AvailPhys),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Time,
|
c.time,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(currentTime.Unix()),
|
float64(currentTime.Unix()),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Timezone,
|
c.timezone,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
1.0,
|
1.0,
|
||||||
timezoneName,
|
timezoneName,
|
||||||
@@ -310,13 +323,13 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
if pagingErr == nil {
|
if pagingErr == nil {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PagingFreeBytes,
|
c.pagingFreeBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
pfb,
|
pfb,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PagingLimitBytes,
|
c.pagingLimitBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
fsipf,
|
fsipf,
|
||||||
)
|
)
|
||||||
@@ -324,7 +337,7 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
_ = level.Debug(c.logger).Log("msg", "Could not find HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management key. windows_os_paging_free_bytes and windows_os_paging_limit_bytes will be omitted.")
|
_ = level.Debug(c.logger).Log("msg", "Could not find HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management key. windows_os_paging_free_bytes and windows_os_paging_limit_bytes will be omitted.")
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VirtualMemoryFreeBytes,
|
c.virtualMemoryFreeBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(gmse.AvailPageFile),
|
float64(gmse.AvailPageFile),
|
||||||
)
|
)
|
||||||
@@ -333,37 +346,37 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
// https://techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-processes-and-threads/ba-p/723824
|
// https://techcommunity.microsoft.com/t5/windows-blog-archive/pushing-the-limits-of-windows-processes-and-threads/ba-p/723824
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem
|
// https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessesLimit,
|
c.processesLimit,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(4294967295),
|
float64(4294967295),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessMemoryLimitBytes,
|
c.processMemoryLimitBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(gmse.TotalVirtual),
|
float64(gmse.TotalVirtual),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Processes,
|
c.processes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(gpi.ProcessCount),
|
float64(gpi.ProcessCount),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Users,
|
c.users,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(nwgi.LoggedOnUsers),
|
float64(nwgi.LoggedOnUsers),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VirtualMemoryBytes,
|
c.virtualMemoryBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(gmse.TotalPageFile),
|
float64(gmse.TotalPageFile),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VisibleMemoryBytes,
|
c.visibleMemoryBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(gmse.TotalPhys),
|
float64(gmse.TotalPhys),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,197 +15,202 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "physical_disk"
|
||||||
Name = "physical_disk"
|
|
||||||
FlagPhysicalDiskExclude = "collector.physical_disk.disk-exclude"
|
|
||||||
FlagPhysicalDiskInclude = "collector.physical_disk.disk-include"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DiskInclude string `yaml:"disk_include"`
|
DiskInclude *regexp.Regexp `yaml:"disk_include"`
|
||||||
DiskExclude string `yaml:"disk_exclude"`
|
DiskExclude *regexp.Regexp `yaml:"disk_exclude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
DiskInclude: ".+",
|
DiskInclude: types.RegExpAny,
|
||||||
DiskExclude: "",
|
DiskExclude: types.RegExpEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for perflib PhysicalDisk metrics
|
// A Collector is a Prometheus Collector for perflib PhysicalDisk metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
diskInclude *string
|
idleTime *prometheus.Desc
|
||||||
diskExclude *string
|
readBytesTotal *prometheus.Desc
|
||||||
|
readLatency *prometheus.Desc
|
||||||
diskIncludeSet bool
|
readTime *prometheus.Desc
|
||||||
diskExcludeSet bool
|
readWriteLatency *prometheus.Desc
|
||||||
|
readsTotal *prometheus.Desc
|
||||||
RequestsQueued *prometheus.Desc
|
requestsQueued *prometheus.Desc
|
||||||
ReadBytesTotal *prometheus.Desc
|
splitIOs *prometheus.Desc
|
||||||
ReadsTotal *prometheus.Desc
|
writeBytesTotal *prometheus.Desc
|
||||||
WriteBytesTotal *prometheus.Desc
|
writeLatency *prometheus.Desc
|
||||||
WritesTotal *prometheus.Desc
|
writeTime *prometheus.Desc
|
||||||
ReadTime *prometheus.Desc
|
writesTotal *prometheus.Desc
|
||||||
WriteTime *prometheus.Desc
|
|
||||||
IdleTime *prometheus.Desc
|
|
||||||
SplitIOs *prometheus.Desc
|
|
||||||
ReadLatency *prometheus.Desc
|
|
||||||
WriteLatency *prometheus.Desc
|
|
||||||
ReadWriteLatency *prometheus.Desc
|
|
||||||
|
|
||||||
diskIncludePattern *regexp.Regexp
|
|
||||||
diskExcludePattern *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.DiskExclude == nil {
|
||||||
diskExclude: &config.DiskExclude,
|
config.DiskExclude = ConfigDefaults.DiskExclude
|
||||||
diskInclude: &config.DiskInclude,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.DiskInclude == nil {
|
||||||
|
config.DiskInclude = ConfigDefaults.DiskInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{}
|
c := &Collector{
|
||||||
|
config: ConfigDefaults,
|
||||||
|
}
|
||||||
|
|
||||||
c.diskInclude = app.Flag(
|
var diskExclude, diskInclude string
|
||||||
FlagPhysicalDiskInclude,
|
|
||||||
"Regexp of disks to include. Disk number must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.DiskInclude).PreAction(func(_ *kingpin.ParseContext) error {
|
|
||||||
c.diskIncludeSet = true
|
|
||||||
return nil
|
|
||||||
}).String()
|
|
||||||
|
|
||||||
c.diskExclude = app.Flag(
|
app.Flag(
|
||||||
FlagPhysicalDiskExclude,
|
"collector.physical_disk.disk-exclude",
|
||||||
"Regexp of disks to exclude. Disk number must both match include and not match exclude to be included.",
|
"Regexp of disks to exclude. Disk number must both match include and not match exclude to be included.",
|
||||||
).Default(ConfigDefaults.DiskExclude).PreAction(func(_ *kingpin.ParseContext) error {
|
).Default(c.config.DiskExclude.String()).StringVar(&diskExclude)
|
||||||
c.diskExcludeSet = true
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.physical_disk.disk-include",
|
||||||
|
"Regexp of disks to include. Disk number must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.DiskInclude.String()).StringVar(&diskInclude)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.DiskExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", diskExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.physical_disk.disk-exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.DiskInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", diskInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.physical_disk.disk-include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}).String()
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"PhysicalDisk"}, nil
|
return []string{"PhysicalDisk"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.RequestsQueued = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.requestsQueued = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
||||||
"The number of requests queued to the disk (PhysicalDisk.CurrentDiskQueueLength)",
|
"The number of requests queued to the disk (PhysicalDisk.CurrentDiskQueueLength)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadBytesTotal = prometheus.NewDesc(
|
c.readBytesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_bytes_total"),
|
||||||
"The number of bytes transferred from the disk during read operations (PhysicalDisk.DiskReadBytesPerSec)",
|
"The number of bytes transferred from the disk during read operations (PhysicalDisk.DiskReadBytesPerSec)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadsTotal = prometheus.NewDesc(
|
c.readsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "reads_total"),
|
||||||
"The number of read operations on the disk (PhysicalDisk.DiskReadsPerSec)",
|
"The number of read operations on the disk (PhysicalDisk.DiskReadsPerSec)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WriteBytesTotal = prometheus.NewDesc(
|
c.writeBytesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_bytes_total"),
|
||||||
"The number of bytes transferred to the disk during write operations (PhysicalDisk.DiskWriteBytesPerSec)",
|
"The number of bytes transferred to the disk during write operations (PhysicalDisk.DiskWriteBytesPerSec)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WritesTotal = prometheus.NewDesc(
|
c.writesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "writes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "writes_total"),
|
||||||
"The number of write operations on the disk (PhysicalDisk.DiskWritesPerSec)",
|
"The number of write operations on the disk (PhysicalDisk.DiskWritesPerSec)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadTime = prometheus.NewDesc(
|
c.readTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_seconds_total"),
|
||||||
"Seconds that the disk was busy servicing read requests (PhysicalDisk.PercentDiskReadTime)",
|
"Seconds that the disk was busy servicing read requests (PhysicalDisk.PercentDiskReadTime)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WriteTime = prometheus.NewDesc(
|
c.writeTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_seconds_total"),
|
||||||
"Seconds that the disk was busy servicing write requests (PhysicalDisk.PercentDiskWriteTime)",
|
"Seconds that the disk was busy servicing write requests (PhysicalDisk.PercentDiskWriteTime)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.IdleTime = prometheus.NewDesc(
|
c.idleTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "idle_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "idle_seconds_total"),
|
||||||
"Seconds that the disk was idle (PhysicalDisk.PercentIdleTime)",
|
"Seconds that the disk was idle (PhysicalDisk.PercentIdleTime)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.SplitIOs = prometheus.NewDesc(
|
c.splitIOs = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "split_ios_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "split_ios_total"),
|
||||||
"The number of I/Os to the disk were split into multiple I/Os (PhysicalDisk.SplitIOPerSec)",
|
"The number of I/Os to the disk were split into multiple I/Os (PhysicalDisk.SplitIOPerSec)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadLatency = prometheus.NewDesc(
|
c.readLatency = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_latency_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_latency_seconds_total"),
|
||||||
"Shows the average time, in seconds, of a read operation from the disk (PhysicalDisk.AvgDiskSecPerRead)",
|
"Shows the average time, in seconds, of a read operation from the disk (PhysicalDisk.AvgDiskSecPerRead)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.WriteLatency = prometheus.NewDesc(
|
c.writeLatency = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "write_latency_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "write_latency_seconds_total"),
|
||||||
"Shows the average time, in seconds, of a write operation to the disk (PhysicalDisk.AvgDiskSecPerWrite)",
|
"Shows the average time, in seconds, of a write operation to the disk (PhysicalDisk.AvgDiskSecPerWrite)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ReadWriteLatency = prometheus.NewDesc(
|
c.readWriteLatency = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "read_write_latency_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "read_write_latency_seconds_total"),
|
||||||
"Shows the time, in seconds, of the average disk transfer (PhysicalDisk.AvgDiskSecPerTransfer)",
|
"Shows the time, in seconds, of the average disk transfer (PhysicalDisk.AvgDiskSecPerTransfer)",
|
||||||
[]string{"disk"},
|
[]string{"disk"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
|
||||||
c.diskIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.diskInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.diskExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.diskExclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting physical_disk metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting physical_disk metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -215,7 +220,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
// PhysicalDisk
|
// PhysicalDisk
|
||||||
// Win32_PerfRawData_PerfDisk_PhysicalDisk docs:
|
// Win32_PerfRawData_PerfDisk_PhysicalDisk docs:
|
||||||
// - https://docs.microsoft.com/en-us/previous-versions/aa394308(v=vs.85) - Win32_PerfRawData_PerfDisk_PhysicalDisk class
|
// - https://docs.microsoft.com/en-us/previous-versions/aa394308(v=vs.85) - Win32_PerfRawData_PerfDisk_PhysicalDisk class.
|
||||||
type PhysicalDisk struct {
|
type PhysicalDisk struct {
|
||||||
Name string
|
Name string
|
||||||
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
|
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
|
||||||
@@ -232,7 +237,7 @@ type PhysicalDisk struct {
|
|||||||
AvgDiskSecPerTransfer float64 `perflib:"Avg. Disk sec/Transfer"`
|
AvgDiskSecPerTransfer float64 `perflib:"Avg. Disk sec/Transfer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []PhysicalDisk
|
var dst []PhysicalDisk
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["PhysicalDisk"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["PhysicalDisk"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -240,8 +245,8 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
for _, disk := range dst {
|
for _, disk := range dst {
|
||||||
if disk.Name == "_Total" ||
|
if disk.Name == "_Total" ||
|
||||||
c.diskExcludePattern.MatchString(disk.Name) ||
|
c.config.DiskExclude.MatchString(disk.Name) ||
|
||||||
!c.diskIncludePattern.MatchString(disk.Name) {
|
!c.config.DiskInclude.MatchString(disk.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,84 +255,84 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
disk_number, _, _ := strings.Cut(disk.Name, " ")
|
disk_number, _, _ := strings.Cut(disk.Name, " ")
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestsQueued,
|
c.requestsQueued,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
disk.CurrentDiskQueueLength,
|
disk.CurrentDiskQueueLength,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadBytesTotal,
|
c.readBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.DiskReadBytesPerSec,
|
disk.DiskReadBytesPerSec,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadsTotal,
|
c.readsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.DiskReadsPerSec,
|
disk.DiskReadsPerSec,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteBytesTotal,
|
c.writeBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.DiskWriteBytesPerSec,
|
disk.DiskWriteBytesPerSec,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WritesTotal,
|
c.writesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.DiskWritesPerSec,
|
disk.DiskWritesPerSec,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadTime,
|
c.readTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.PercentDiskReadTime,
|
disk.PercentDiskReadTime,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteTime,
|
c.writeTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.PercentDiskWriteTime,
|
disk.PercentDiskWriteTime,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IdleTime,
|
c.idleTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.PercentIdleTime,
|
disk.PercentIdleTime,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SplitIOs,
|
c.splitIOs,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.SplitIOPerSec,
|
disk.SplitIOPerSec,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadLatency,
|
c.readLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.AvgDiskSecPerRead*perflib.TicksToSecondScaleFactor,
|
disk.AvgDiskSecPerRead*perflib.TicksToSecondScaleFactor,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteLatency,
|
c.writeLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.AvgDiskSecPerWrite*perflib.TicksToSecondScaleFactor,
|
disk.AvgDiskSecPerWrite*perflib.TicksToSecondScaleFactor,
|
||||||
disk_number,
|
disk_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadWriteLatency,
|
c.readWriteLatency,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
disk.AvgDiskSecPerTransfer*perflib.TicksToSecondScaleFactor,
|
disk.AvgDiskSecPerTransfer*perflib.TicksToSecondScaleFactor,
|
||||||
disk_number,
|
disk_number,
|
||||||
|
|||||||
12
pkg/collector/physical_disk/physical_disk_test.go
Normal file
12
pkg/collector/physical_disk/physical_disk_test.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package physical_disk_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/collector/physical_disk"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/testutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCollector(b *testing.B) {
|
||||||
|
testutils.FuncBenchmarkCollector(b, physical_disk.Name, physical_disk.NewWithFlags)
|
||||||
|
}
|
||||||
@@ -10,18 +10,12 @@ import (
|
|||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "printer"
|
||||||
Name = "printer"
|
|
||||||
|
|
||||||
FlagPrinterInclude = "collector.printer.include"
|
|
||||||
FlagPrinterExclude = "collector.printer.exclude"
|
|
||||||
)
|
|
||||||
|
|
||||||
// printerStatusMap source: https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer#:~:text=Power%20Save-,PrinterStatus,Offline%20(7),-PrintJobDataType
|
// printerStatusMap source: https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer#:~:text=Power%20Save-,PrinterStatus,Offline%20(7),-PrintJobDataType
|
||||||
var printerStatusMap = map[uint16]string{
|
var printerStatusMap = map[uint16]string{
|
||||||
@@ -35,60 +29,91 @@ var printerStatusMap = map[uint16]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Include string `yaml:"printer_include"`
|
PrinterInclude *regexp.Regexp `yaml:"printer_include"`
|
||||||
Exclude string `yaml:"printer_exclude"`
|
PrinterExclude *regexp.Regexp `yaml:"printer_exclude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
Include: ".+",
|
PrinterInclude: types.RegExpAny,
|
||||||
Exclude: "",
|
PrinterExclude: types.RegExpEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
printerInclude *string
|
|
||||||
printerExclude *string
|
|
||||||
|
|
||||||
printerStatus *prometheus.Desc
|
printerStatus *prometheus.Desc
|
||||||
printerJobStatus *prometheus.Desc
|
printerJobStatus *prometheus.Desc
|
||||||
printerJobCount *prometheus.Desc
|
printerJobCount *prometheus.Desc
|
||||||
|
|
||||||
printerIncludePattern *regexp.Regexp
|
|
||||||
printerExcludePattern *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
c := &collector{
|
|
||||||
printerInclude: &config.Include,
|
if config.PrinterExclude == nil {
|
||||||
printerExclude: &config.Exclude,
|
config.PrinterExclude = ConfigDefaults.PrinterExclude
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.PrinterInclude == nil {
|
||||||
|
config.PrinterInclude = ConfigDefaults.PrinterInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
printerInclude: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagPrinterInclude,
|
|
||||||
"Regular expression to match printers to collect metrics for",
|
|
||||||
).Default(ConfigDefaults.Include).String(),
|
|
||||||
printerExclude: app.Flag(
|
|
||||||
FlagPrinterExclude,
|
|
||||||
"Regular expression to match printers to exclude",
|
|
||||||
).Default(ConfigDefaults.Exclude).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var printerInclude, printerExclude string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.printer.include",
|
||||||
|
"Regular expression to match printers to collect metrics for",
|
||||||
|
).Default(c.config.PrinterInclude.String()).StringVar(&printerInclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.printer.exclude",
|
||||||
|
"Regular expression to match printers to exclude",
|
||||||
|
).Default(c.config.PrinterExclude.String()).StringVar(&printerExclude)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.PrinterInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", printerInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.printer.include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.PrinterExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", printerExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.printer.exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
c.printerJobStatus = prometheus.NewDesc(
|
c.printerJobStatus = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "job_status"),
|
prometheus.BuildFQName(types.Namespace, Name, "job_status"),
|
||||||
"A counter of printer jobs by status",
|
"A counter of printer jobs by status",
|
||||||
@@ -108,53 +133,50 @@ func (c *collector) Build() error {
|
|||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
return nil
|
||||||
c.printerIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.printerInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.printerExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.printerExclude))
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string { return Name }
|
func (c *Collector) GetName() string { return Name }
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) { return []string{"Printer"}, nil }
|
func (c *Collector) GetPerfCounter() ([]string, error) { return []string{"Printer"}, nil }
|
||||||
|
|
||||||
type win32_Printer struct {
|
type wmiPrinter struct {
|
||||||
Name string
|
Name string
|
||||||
Default bool
|
Default bool
|
||||||
PrinterStatus uint16
|
PrinterStatus uint16
|
||||||
JobCountSinceLastReset uint32
|
JobCountSinceLastReset uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type win32_PrintJob struct {
|
type wmiPrintJob struct {
|
||||||
Name string
|
Name string
|
||||||
Status string
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collectPrinterStatus(ch); err != nil {
|
if err := c.collectPrinterStatus(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed to collect printer status metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed to collect printer status metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectPrinterJobStatus(ch); err != nil {
|
if err := c.collectPrinterJobStatus(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed to collect printer job status metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed to collect printer job status metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
||||||
var printers []win32_Printer
|
var printers []wmiPrinter
|
||||||
q := wmi.QueryAll(&printers, c.logger)
|
|
||||||
|
q := wmi.QueryAllForClass(&printers, "win32_Printer", c.logger)
|
||||||
if err := wmi.Query(q, &printers); err != nil {
|
if err := wmi.Query(q, &printers); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, printer := range printers {
|
for _, printer := range printers {
|
||||||
if c.printerExcludePattern.MatchString(printer.Name) ||
|
if c.config.PrinterExclude.MatchString(printer.Name) ||
|
||||||
!c.printerIncludePattern.MatchString(printer.Name) {
|
!c.config.PrinterInclude.MatchString(printer.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,9 +206,10 @@ func (c *collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectPrinterJobStatus(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectPrinterJobStatus(ch chan<- prometheus.Metric) error {
|
||||||
var printJobs []win32_PrintJob
|
var printJobs []wmiPrintJob
|
||||||
q := wmi.QueryAll(&printJobs, c.logger)
|
|
||||||
|
q := wmi.QueryAllForClass(&printJobs, "win32_PrintJob", c.logger)
|
||||||
if err := wmi.Query(q, &printJobs); err != nil {
|
if err := wmi.Query(q, &printJobs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -201,6 +224,7 @@ func (c *collector) collectPrinterJobStatus(ch chan<- prometheus.Metric) error {
|
|||||||
group.status,
|
group.status,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,19 +233,22 @@ type PrintJobStatusGroup struct {
|
|||||||
status string
|
status string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) groupPrintJobs(printJobs []win32_PrintJob) map[PrintJobStatusGroup]int {
|
func (c *Collector) groupPrintJobs(printJobs []wmiPrintJob) map[PrintJobStatusGroup]int {
|
||||||
groupedPrintJobs := make(map[PrintJobStatusGroup]int)
|
groupedPrintJobs := make(map[PrintJobStatusGroup]int)
|
||||||
|
|
||||||
for _, printJob := range printJobs {
|
for _, printJob := range printJobs {
|
||||||
printerName := strings.Split(printJob.Name, ",")[0]
|
printerName := strings.Split(printJob.Name, ",")[0]
|
||||||
|
|
||||||
if c.printerExcludePattern.MatchString(printerName) ||
|
if c.config.PrinterExclude.MatchString(printerName) ||
|
||||||
!c.printerIncludePattern.MatchString(printerName) {
|
!c.config.PrinterInclude.MatchString(printerName) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
groupedPrintJobs[PrintJobStatusGroup{
|
groupedPrintJobs[PrintJobStatusGroup{
|
||||||
printerName: printerName,
|
printerName: printerName,
|
||||||
status: printJob.Status,
|
status: printJob.Status,
|
||||||
}]++
|
}]++
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupedPrintJobs
|
return groupedPrintJobs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/printer"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/printer"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/testutils"
|
"github.com/prometheus-community/windows_exporter/pkg/testutils"
|
||||||
)
|
)
|
||||||
@@ -12,6 +11,6 @@ import (
|
|||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all printers.
|
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all printers.
|
||||||
printersInclude := ".+"
|
printersInclude := ".+"
|
||||||
kingpin.CommandLine.GetArg(printer.FlagPrinterInclude).StringVar(&printersInclude)
|
kingpin.CommandLine.GetArg("collector.printer.include").StringVar(&printersInclude)
|
||||||
testutils.FuncBenchmarkCollector(b, "printer", printer.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, "printer", printer.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package process
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -16,210 +15,229 @@ import (
|
|||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "process"
|
||||||
Name = "process"
|
|
||||||
FlagProcessExclude = "collector.process.exclude"
|
|
||||||
FlagProcessInclude = "collector.process.include"
|
|
||||||
FlagEnableWorkerProcess = "collector.process.iis"
|
|
||||||
FlagEnableReportOwner = "collector.process.report-owner"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ProcessInclude string `yaml:"process_include"`
|
ProcessInclude *regexp.Regexp `yaml:"process_include"`
|
||||||
ProcessExclude string `yaml:"process_exclude"`
|
ProcessExclude *regexp.Regexp `yaml:"process_exclude"`
|
||||||
EnableWorkerProcess bool `yaml:"enable_iis_worker_process"`
|
EnableWorkerProcess bool `yaml:"enable_iis_worker_process"` //nolint:tagliatelle
|
||||||
EnableReportOwner bool `yaml:"enable_report_owner"`
|
EnableReportOwner bool `yaml:"enable_report_owner"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
ProcessInclude: ".+",
|
ProcessInclude: types.RegExpAny,
|
||||||
ProcessExclude: "",
|
ProcessExclude: types.RegExpEmpty,
|
||||||
EnableWorkerProcess: false,
|
EnableWorkerProcess: false,
|
||||||
EnableReportOwner: false,
|
EnableReportOwner: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
processInclude *string
|
|
||||||
processExclude *string
|
|
||||||
|
|
||||||
enableWorkerProcess *bool
|
|
||||||
enableReportOwner *bool
|
|
||||||
|
|
||||||
StartTime *prometheus.Desc
|
|
||||||
CPUTimeTotal *prometheus.Desc
|
|
||||||
HandleCount *prometheus.Desc
|
|
||||||
IOBytesTotal *prometheus.Desc
|
|
||||||
IOOperationsTotal *prometheus.Desc
|
|
||||||
PageFaultsTotal *prometheus.Desc
|
|
||||||
PageFileBytes *prometheus.Desc
|
|
||||||
PoolBytes *prometheus.Desc
|
|
||||||
PriorityBase *prometheus.Desc
|
|
||||||
PrivateBytes *prometheus.Desc
|
|
||||||
ThreadCount *prometheus.Desc
|
|
||||||
VirtualBytes *prometheus.Desc
|
|
||||||
WorkingSetPrivate *prometheus.Desc
|
|
||||||
WorkingSetPeak *prometheus.Desc
|
|
||||||
WorkingSet *prometheus.Desc
|
|
||||||
|
|
||||||
processIncludePattern *regexp.Regexp
|
|
||||||
processExcludePattern *regexp.Regexp
|
|
||||||
|
|
||||||
lookupCache map[string]string
|
lookupCache map[string]string
|
||||||
|
|
||||||
|
cpuTimeTotal *prometheus.Desc
|
||||||
|
handleCount *prometheus.Desc
|
||||||
|
ioBytesTotal *prometheus.Desc
|
||||||
|
ioOperationsTotal *prometheus.Desc
|
||||||
|
pageFaultsTotal *prometheus.Desc
|
||||||
|
pageFileBytes *prometheus.Desc
|
||||||
|
poolBytes *prometheus.Desc
|
||||||
|
priorityBase *prometheus.Desc
|
||||||
|
privateBytes *prometheus.Desc
|
||||||
|
startTime *prometheus.Desc
|
||||||
|
threadCount *prometheus.Desc
|
||||||
|
virtualBytes *prometheus.Desc
|
||||||
|
workingSet *prometheus.Desc
|
||||||
|
workingSetPeak *prometheus.Desc
|
||||||
|
workingSetPrivate *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.ProcessExclude == nil {
|
||||||
processExclude: &config.ProcessExclude,
|
config.ProcessExclude = ConfigDefaults.ProcessExclude
|
||||||
processInclude: &config.ProcessInclude,
|
|
||||||
enableWorkerProcess: &config.EnableWorkerProcess,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.ProcessInclude == nil {
|
||||||
|
config.ProcessInclude = ConfigDefaults.ProcessInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
processInclude: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagProcessInclude,
|
|
||||||
"Regexp of processes to include. Process name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.ProcessInclude).String(),
|
|
||||||
|
|
||||||
processExclude: app.Flag(
|
|
||||||
FlagProcessExclude,
|
|
||||||
"Regexp of processes to exclude. Process name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.ProcessExclude).String(),
|
|
||||||
|
|
||||||
enableWorkerProcess: app.Flag(
|
|
||||||
FlagEnableWorkerProcess,
|
|
||||||
"Enable IIS worker process name queries. May cause the collector to leak memory.",
|
|
||||||
).Default("false").Bool(),
|
|
||||||
|
|
||||||
enableReportOwner: app.Flag(
|
|
||||||
FlagEnableReportOwner,
|
|
||||||
"Enable reporting of process owner.",
|
|
||||||
).Default("false").Bool(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var processExclude, processInclude string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.process.exclude",
|
||||||
|
"Regexp of processes to exclude. Process name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.ProcessExclude.String()).StringVar(&processExclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.process.include",
|
||||||
|
"Regexp of processes to include. Process name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.ProcessInclude.String()).StringVar(&processInclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.process.iis",
|
||||||
|
"Enable IIS worker process name queries. May cause the collector to leak memory.",
|
||||||
|
).Default(strconv.FormatBool(c.config.EnableWorkerProcess)).BoolVar(&c.config.EnableWorkerProcess)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.process.report-owner",
|
||||||
|
"Enable reporting of process owner.",
|
||||||
|
).Default(strconv.FormatBool(c.config.EnableReportOwner)).BoolVar(&c.config.EnableReportOwner)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.ProcessExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", processExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.process.exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.ProcessInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", processInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.process.include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Process"}, nil
|
return []string{"Process"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
if c.processInclude != nil && *c.processInclude == ".*" && utils.IsEmpty(c.processExclude) {
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
if c.config.ProcessInclude.String() == "^(?:.*)$" && c.config.ProcessExclude.String() == "^(?:)$" {
|
||||||
_ = level.Warn(c.logger).Log("msg", "No filters specified for process collector. This will generate a very large number of metrics!")
|
_ = level.Warn(c.logger).Log("msg", "No filters specified for process collector. This will generate a very large number of metrics!")
|
||||||
}
|
}
|
||||||
|
|
||||||
commonLabels := make([]string, 0)
|
commonLabels := make([]string, 0)
|
||||||
if *c.enableReportOwner {
|
if c.config.EnableReportOwner {
|
||||||
commonLabels = []string{"owner"}
|
commonLabels = []string{"owner"}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.StartTime = prometheus.NewDesc(
|
c.startTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "start_time"),
|
prometheus.BuildFQName(types.Namespace, Name, "start_time"),
|
||||||
"Time of process start.",
|
"Time of process start.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CPUTimeTotal = prometheus.NewDesc(
|
c.cpuTimeTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_time_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_time_total"),
|
||||||
"Returns elapsed time that all of the threads of this process used the processor to execute instructions by mode (privileged, user).",
|
"Returns elapsed time that all of the threads of this process used the processor to execute instructions by mode (privileged, user).",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id", "mode"),
|
append(commonLabels, "process", "process_id", "creating_process_id", "mode"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.HandleCount = prometheus.NewDesc(
|
c.handleCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "handles"),
|
prometheus.BuildFQName(types.Namespace, Name, "handles"),
|
||||||
"Total number of handles the process has open. This number is the sum of the handles currently open by each thread in the process.",
|
"Total number of handles the process has open. This number is the sum of the handles currently open by each thread in the process.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.IOBytesTotal = prometheus.NewDesc(
|
c.ioBytesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "io_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "io_bytes_total"),
|
||||||
"Bytes issued to I/O operations in different modes (read, write, other).",
|
"Bytes issued to I/O operations in different modes (read, write, other).",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id", "mode"),
|
append(commonLabels, "process", "process_id", "creating_process_id", "mode"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.IOOperationsTotal = prometheus.NewDesc(
|
c.ioOperationsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "io_operations_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "io_operations_total"),
|
||||||
"I/O operations issued in different modes (read, write, other).",
|
"I/O operations issued in different modes (read, write, other).",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id", "mode"),
|
append(commonLabels, "process", "process_id", "creating_process_id", "mode"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PageFaultsTotal = prometheus.NewDesc(
|
c.pageFaultsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "page_faults_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "page_faults_total"),
|
||||||
"Page faults by the threads executing in this process.",
|
"Page faults by the threads executing in this process.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PageFileBytes = prometheus.NewDesc(
|
c.pageFileBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "page_file_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "page_file_bytes"),
|
||||||
"Current number of bytes this process has used in the paging file(s).",
|
"Current number of bytes this process has used in the paging file(s).",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolBytes = prometheus.NewDesc(
|
c.poolBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_bytes"),
|
||||||
"Pool Bytes is the last observed number of bytes in the paged or nonpaged pool.",
|
"Pool Bytes is the last observed number of bytes in the paged or nonpaged pool.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id", "pool"),
|
append(commonLabels, "process", "process_id", "creating_process_id", "pool"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PriorityBase = prometheus.NewDesc(
|
c.priorityBase = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "priority_base"),
|
prometheus.BuildFQName(types.Namespace, Name, "priority_base"),
|
||||||
"Current base priority of this process. Threads within a process can raise and lower their own base priority relative to the process base priority of the process.",
|
"Current base priority of this process. Threads within a process can raise and lower their own base priority relative to the process base priority of the process.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PrivateBytes = prometheus.NewDesc(
|
c.privateBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "private_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "private_bytes"),
|
||||||
"Current number of bytes this process has allocated that cannot be shared with other processes.",
|
"Current number of bytes this process has allocated that cannot be shared with other processes.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ThreadCount = prometheus.NewDesc(
|
c.threadCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "threads"),
|
prometheus.BuildFQName(types.Namespace, Name, "threads"),
|
||||||
"Number of threads currently active in this process.",
|
"Number of threads currently active in this process.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.VirtualBytes = prometheus.NewDesc(
|
c.virtualBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "virtual_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "virtual_bytes"),
|
||||||
"Current size, in bytes, of the virtual address space that the process is using.",
|
"Current size, in bytes, of the virtual address space that the process is using.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WorkingSetPrivate = prometheus.NewDesc(
|
c.workingSetPrivate = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "working_set_private_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "working_set_private_bytes"),
|
||||||
"Size of the working set, in bytes, that is use for this process only and not shared nor shareable by other processes.",
|
"Size of the working set, in bytes, that is use for this process only and not shared nor shareable by other processes.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WorkingSetPeak = prometheus.NewDesc(
|
c.workingSetPeak = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "working_set_peak_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "working_set_peak_bytes"),
|
||||||
"Maximum size, in bytes, of the Working Set of this process at any point in time. The Working Set is the set of memory pages touched recently by the threads in the process.",
|
"Maximum size, in bytes, of the Working Set of this process at any point in time. The Working Set is the set of memory pages touched recently by the threads in the process.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WorkingSet = prometheus.NewDesc(
|
c.workingSet = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "working_set_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "working_set_bytes"),
|
||||||
"Maximum number of bytes in the working set of this process at any point in time. The working set is the set of memory pages touched recently by the threads in the process.",
|
"Maximum number of bytes in the working set of this process at any point in time. The working set is the set of memory pages touched recently by the threads in the process.",
|
||||||
append(commonLabels, "process", "process_id", "creating_process_id"),
|
append(commonLabels, "process", "process_id", "creating_process_id"),
|
||||||
@@ -228,18 +246,6 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
c.lookupCache = make(map[string]string)
|
c.lookupCache = make(map[string]string)
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
c.processIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.processInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.processExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.processExclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +269,7 @@ type perflibProcess struct {
|
|||||||
PageFaultsPerSec float64 `perflib:"Page Faults/sec"`
|
PageFaultsPerSec float64 `perflib:"Page Faults/sec"`
|
||||||
PageFileBytesPeak float64 `perflib:"Page File Bytes Peak"`
|
PageFileBytesPeak float64 `perflib:"Page File Bytes Peak"`
|
||||||
PageFileBytes float64 `perflib:"Page File Bytes"`
|
PageFileBytes float64 `perflib:"Page File Bytes"`
|
||||||
PoolNonpagedBytes float64 `perflib:"Pool Nonpaged Bytes"`
|
PoolNonPagedBytes float64 `perflib:"Pool Nonpaged Bytes"`
|
||||||
PoolPagedBytes float64 `perflib:"Pool Paged Bytes"`
|
PoolPagedBytes float64 `perflib:"Pool Paged Bytes"`
|
||||||
PriorityBase float64 `perflib:"Priority Base"`
|
PriorityBase float64 `perflib:"Priority Base"`
|
||||||
PrivateBytes float64 `perflib:"Private Bytes"`
|
PrivateBytes float64 `perflib:"Private Bytes"`
|
||||||
@@ -280,17 +286,17 @@ type WorkerProcess struct {
|
|||||||
ProcessId uint64
|
ProcessId uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
data := make([]perflibProcess, 0)
|
data := make([]perflibProcess, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["Process"], &data, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["Process"], &data, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var dst_wp []WorkerProcess
|
var workerProcesses []WorkerProcess
|
||||||
if *c.enableWorkerProcess {
|
if c.config.EnableWorkerProcess {
|
||||||
q_wp := wmi.QueryAll(&dst_wp, c.logger)
|
queryWorkerProcess := wmi.QueryAllForClass(&workerProcesses, "WorkerProcess", c.logger)
|
||||||
if err := wmi.QueryNamespace(q_wp, &dst_wp, "root\\WebAdministration"); err != nil {
|
if err := wmi.QueryNamespace(queryWorkerProcess, &workerProcesses, "root\\WebAdministration"); err != nil {
|
||||||
_ = level.Debug(c.logger).Log("msg", "Could not query WebAdministration namespace for IIS worker processes", "err", err)
|
_ = level.Debug(c.logger).Log("msg", "Could not query WebAdministration namespace for IIS worker processes", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,17 +305,18 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
for _, process := range data {
|
for _, process := range data {
|
||||||
if process.Name == "_Total" ||
|
if process.Name == "_Total" ||
|
||||||
c.processExcludePattern.MatchString(process.Name) ||
|
c.config.ProcessExclude.MatchString(process.Name) ||
|
||||||
!c.processIncludePattern.MatchString(process.Name) {
|
!c.config.ProcessInclude.MatchString(process.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Duplicate processes are suffixed # and an index number. Remove those.
|
|
||||||
processName := strings.Split(process.Name, "#")[0]
|
|
||||||
pid := strconv.FormatUint(uint64(process.IDProcess), 10)
|
|
||||||
cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 10)
|
|
||||||
|
|
||||||
if *c.enableWorkerProcess {
|
// Duplicate processes are suffixed #, and an index number. Remove those.
|
||||||
for _, wp := range dst_wp {
|
processName, _, _ := strings.Cut(process.Name, "#")
|
||||||
|
pid := strconv.FormatUint(uint64(process.IDProcess), 10)
|
||||||
|
parentPID := strconv.FormatUint(uint64(process.CreatingProcessID), 10)
|
||||||
|
|
||||||
|
if c.config.EnableWorkerProcess {
|
||||||
|
for _, wp := range workerProcesses {
|
||||||
if wp.ProcessId == uint64(process.IDProcess) {
|
if wp.ProcessId == uint64(process.IDProcess) {
|
||||||
processName = strings.Join([]string{processName, wp.AppPoolName}, "_")
|
processName = strings.Join([]string{processName, wp.AppPoolName}, "_")
|
||||||
break
|
break
|
||||||
@@ -319,7 +326,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
labels := make([]string, 0, 4)
|
labels := make([]string, 0, 4)
|
||||||
|
|
||||||
if *c.enableReportOwner {
|
if c.config.EnableReportOwner {
|
||||||
owner, err = c.getProcessOwner(int(process.IDProcess))
|
owner, err = c.getProcessOwner(int(process.IDProcess))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
owner = "unknown"
|
owner = "unknown"
|
||||||
@@ -328,150 +335,150 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
labels = []string{owner}
|
labels = []string{owner}
|
||||||
}
|
}
|
||||||
|
|
||||||
labels = append(labels, processName, pid, cpid)
|
labels = append(labels, processName, pid, parentPID)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.StartTime,
|
c.startTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.ElapsedTime,
|
process.ElapsedTime,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HandleCount,
|
c.handleCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.HandleCount,
|
process.HandleCount,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CPUTimeTotal,
|
c.cpuTimeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.PercentPrivilegedTime,
|
process.PercentPrivilegedTime,
|
||||||
append(labels, "privileged")...,
|
append(labels, "privileged")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CPUTimeTotal,
|
c.cpuTimeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.PercentUserTime,
|
process.PercentUserTime,
|
||||||
append(labels, "user")...,
|
append(labels, "user")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IOBytesTotal,
|
c.ioBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.IOOtherBytesPerSec,
|
process.IOOtherBytesPerSec,
|
||||||
append(labels, "other")...,
|
append(labels, "other")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IOOperationsTotal,
|
c.ioOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.IOOtherOperationsPerSec,
|
process.IOOtherOperationsPerSec,
|
||||||
append(labels, "other")...,
|
append(labels, "other")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IOBytesTotal,
|
c.ioBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.IOReadBytesPerSec,
|
process.IOReadBytesPerSec,
|
||||||
append(labels, "read")...,
|
append(labels, "read")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IOOperationsTotal,
|
c.ioOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.IOReadOperationsPerSec,
|
process.IOReadOperationsPerSec,
|
||||||
append(labels, "read")...,
|
append(labels, "read")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IOBytesTotal,
|
c.ioBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.IOWriteBytesPerSec,
|
process.IOWriteBytesPerSec,
|
||||||
append(labels, "write")...,
|
append(labels, "write")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.IOOperationsTotal,
|
c.ioOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.IOWriteOperationsPerSec,
|
process.IOWriteOperationsPerSec,
|
||||||
append(labels, "write")...,
|
append(labels, "write")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PageFaultsTotal,
|
c.pageFaultsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
process.PageFaultsPerSec,
|
process.PageFaultsPerSec,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PageFileBytes,
|
c.pageFileBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.PageFileBytes,
|
process.PageFileBytes,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolBytes,
|
c.poolBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.PoolNonpagedBytes,
|
process.PoolNonPagedBytes,
|
||||||
append(labels, "nonpaged")...,
|
append(labels, "nonpaged")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolBytes,
|
c.poolBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.PoolPagedBytes,
|
process.PoolPagedBytes,
|
||||||
append(labels, "paged")...,
|
append(labels, "paged")...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PriorityBase,
|
c.priorityBase,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.PriorityBase,
|
process.PriorityBase,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PrivateBytes,
|
c.privateBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.PrivateBytes,
|
process.PrivateBytes,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ThreadCount,
|
c.threadCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.ThreadCount,
|
process.ThreadCount,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VirtualBytes,
|
c.virtualBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.VirtualBytes,
|
process.VirtualBytes,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WorkingSetPrivate,
|
c.workingSetPrivate,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.WorkingSetPrivate,
|
process.WorkingSetPrivate,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WorkingSetPeak,
|
c.workingSetPeak,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.WorkingSetPeak,
|
process.WorkingSetPeak,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WorkingSet,
|
c.workingSet,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
process.WorkingSet,
|
process.WorkingSet,
|
||||||
labels...,
|
labels...,
|
||||||
@@ -482,14 +489,14 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ref: https://github.com/microsoft/hcsshim/blob/8beabacfc2d21767a07c20f8dd5f9f3932dbf305/internal/uvm/stats.go#L25
|
// ref: https://github.com/microsoft/hcsshim/blob/8beabacfc2d21767a07c20f8dd5f9f3932dbf305/internal/uvm/stats.go#L25
|
||||||
func (c *collector) getProcessOwner(pid int) (string, error) {
|
func (c *Collector) getProcessOwner(pid int) (string, error) {
|
||||||
p, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
|
p, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
|
||||||
if errors.Is(err, syscall.Errno(0x57)) { // invalid parameter, for PIDs that don't exist
|
if errors.Is(err, syscall.Errno(0x57)) { // invalid parameter, for PIDs that don't exist
|
||||||
return "", errors.New("process not found")
|
return "", errors.New("process not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("OpenProcess: %T %w", err, err)
|
return "", fmt.Errorf("OpenProcess: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer windows.Close(p)
|
defer windows.Close(p)
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkProcessCollector(b *testing.B) {
|
func BenchmarkProcessCollector(b *testing.B) {
|
||||||
// Include is not set in testing context (kingpin flags not parsed), causing the collector to skip all processes.
|
// PrinterInclude is not set in testing context (kingpin flags not parsed), causing the collector to skip all processes.
|
||||||
localProcessInclude := ".+"
|
localProcessInclude := ".+"
|
||||||
kingpin.CommandLine.GetArg(process.FlagProcessInclude).StringVar(&localProcessInclude)
|
kingpin.CommandLine.GetArg("collector.process.include").StringVar(&localProcessInclude)
|
||||||
// No context name required as collector source is WMI
|
// No context name required as collector source is WMI
|
||||||
testutils.FuncBenchmarkCollector(b, process.Name, process.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, process.Name, process.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func (coll *Prometheus) Collect(ch chan<- prometheus.Metric) {
|
|||||||
time.Since(t).Seconds(),
|
time.Since(t).Seconds(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ch <- prometheus.NewInvalidMetric(coll.scrapeSuccessDesc, fmt.Errorf("failed to prepare scrape: %v", err))
|
ch <- prometheus.NewInvalidMetric(coll.scrapeSuccessDesc, fmt.Errorf("failed to prepare scrape: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ func (coll *Prometheus) Collect(ch chan<- prometheus.Metric) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for name, c := range coll.collectors.collectors {
|
for name, c := range coll.collectors.collectors {
|
||||||
go func(name string, c types.Collector) {
|
go func(name string, c Collector) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
outcome := coll.execute(name, c, scrapeContext, metricsBuffer)
|
outcome := coll.execute(name, c, scrapeContext, metricsBuffer)
|
||||||
l.Lock()
|
l.Lock()
|
||||||
@@ -171,7 +171,7 @@ func (coll *Prometheus) Collect(ch chan<- prometheus.Metric) {
|
|||||||
l.Unlock()
|
l.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (coll *Prometheus) execute(name string, c types.Collector, ctx *types.ScrapeContext, ch chan<- prometheus.Metric) collectorOutcome {
|
func (coll *Prometheus) execute(name string, c Collector, ctx *types.ScrapeContext, ch chan<- prometheus.Metric) collectorOutcome {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
err := c.Collect(ctx, ch)
|
err := c.Collect(ctx, ch)
|
||||||
duration := time.Since(t).Seconds()
|
duration := time.Since(t).Seconds()
|
||||||
|
|||||||
@@ -20,136 +20,149 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// collector
|
// Collector
|
||||||
// A RemoteFxNetworkCollector is a Prometheus collector for
|
// A RemoteFxNetworkCollector is a Prometheus Collector for
|
||||||
// WMI Win32_PerfRawData_Counters_RemoteFXNetwork & Win32_PerfRawData_Counters_RemoteFXGraphics metrics
|
// WMI Win32_PerfRawData_Counters_RemoteFXNetwork & Win32_PerfRawData_Counters_RemoteFXGraphics metrics
|
||||||
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_remotefxnetwork/
|
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_remotefxnetwork/
|
||||||
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_remotefxgraphics/
|
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_remotefxgraphics/
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
// net
|
// net
|
||||||
BaseTCPRTT *prometheus.Desc
|
baseTCPRTT *prometheus.Desc
|
||||||
BaseUDPRTT *prometheus.Desc
|
baseUDPRTT *prometheus.Desc
|
||||||
CurrentTCPBandwidth *prometheus.Desc
|
currentTCPBandwidth *prometheus.Desc
|
||||||
CurrentTCPRTT *prometheus.Desc
|
currentTCPRTT *prometheus.Desc
|
||||||
CurrentUDPBandwidth *prometheus.Desc
|
currentUDPBandwidth *prometheus.Desc
|
||||||
CurrentUDPRTT *prometheus.Desc
|
currentUDPRTT *prometheus.Desc
|
||||||
TotalReceivedBytes *prometheus.Desc
|
fecRate *prometheus.Desc
|
||||||
TotalSentBytes *prometheus.Desc
|
lossRate *prometheus.Desc
|
||||||
UDPPacketsReceivedPersec *prometheus.Desc
|
retransmissionRate *prometheus.Desc
|
||||||
UDPPacketsSentPersec *prometheus.Desc
|
totalReceivedBytes *prometheus.Desc
|
||||||
FECRate *prometheus.Desc
|
totalSentBytes *prometheus.Desc
|
||||||
LossRate *prometheus.Desc
|
udpPacketsReceivedPerSec *prometheus.Desc
|
||||||
RetransmissionRate *prometheus.Desc
|
udpPacketsSentPerSec *prometheus.Desc
|
||||||
|
|
||||||
// gfx
|
// gfx
|
||||||
AverageEncodingTime *prometheus.Desc
|
averageEncodingTime *prometheus.Desc
|
||||||
FrameQuality *prometheus.Desc
|
frameQuality *prometheus.Desc
|
||||||
FramesSkippedPerSecondInsufficientResources *prometheus.Desc
|
framesSkippedPerSecondInsufficientResources *prometheus.Desc
|
||||||
GraphicsCompressionratio *prometheus.Desc
|
graphicsCompressionRatio *prometheus.Desc
|
||||||
InputFramesPerSecond *prometheus.Desc
|
inputFramesPerSecond *prometheus.Desc
|
||||||
OutputFramesPerSecond *prometheus.Desc
|
outputFramesPerSecond *prometheus.Desc
|
||||||
SourceFramesPerSecond *prometheus.Desc
|
sourceFramesPerSecond *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"RemoteFX Network", "RemoteFX Graphics"}, nil
|
return []string{"RemoteFX Network", "RemoteFX Graphics"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
// net
|
// net
|
||||||
c.BaseTCPRTT = prometheus.NewDesc(
|
c.baseTCPRTT = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_base_tcp_rtt_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_base_tcp_rtt_seconds"),
|
||||||
"Base TCP round-trip time (RTT) detected in seconds",
|
"Base TCP round-trip time (RTT) detected in seconds",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BaseUDPRTT = prometheus.NewDesc(
|
c.baseUDPRTT = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_base_udp_rtt_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_base_udp_rtt_seconds"),
|
||||||
"Base UDP round-trip time (RTT) detected in seconds.",
|
"Base UDP round-trip time (RTT) detected in seconds.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentTCPBandwidth = prometheus.NewDesc(
|
c.currentTCPBandwidth = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_current_tcp_bandwidth"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_current_tcp_bandwidth"),
|
||||||
"TCP Bandwidth detected in bytes per second.",
|
"TCP Bandwidth detected in bytes per second.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentTCPRTT = prometheus.NewDesc(
|
c.currentTCPRTT = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_current_tcp_rtt_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_current_tcp_rtt_seconds"),
|
||||||
"Average TCP round-trip time (RTT) detected in seconds.",
|
"Average TCP round-trip time (RTT) detected in seconds.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentUDPBandwidth = prometheus.NewDesc(
|
c.currentUDPBandwidth = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_current_udp_bandwidth"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_current_udp_bandwidth"),
|
||||||
"UDP Bandwidth detected in bytes per second.",
|
"UDP Bandwidth detected in bytes per second.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentUDPRTT = prometheus.NewDesc(
|
c.currentUDPRTT = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_current_udp_rtt_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_current_udp_rtt_seconds"),
|
||||||
"Average UDP round-trip time (RTT) detected in seconds.",
|
"Average UDP round-trip time (RTT) detected in seconds.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalReceivedBytes = prometheus.NewDesc(
|
c.totalReceivedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_received_bytes_total"),
|
||||||
"(TotalReceivedBytes)",
|
"(TotalReceivedBytes)",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TotalSentBytes = prometheus.NewDesc(
|
c.totalSentBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_sent_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_sent_bytes_total"),
|
||||||
"(TotalSentBytes)",
|
"(TotalSentBytes)",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.UDPPacketsReceivedPersec = prometheus.NewDesc(
|
c.udpPacketsReceivedPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_udp_packets_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_udp_packets_received_total"),
|
||||||
"Rate in packets per second at which packets are received over UDP.",
|
"Rate in packets per second at which packets are received over UDP.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.UDPPacketsSentPersec = prometheus.NewDesc(
|
c.udpPacketsSentPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_udp_packets_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_udp_packets_sent_total"),
|
||||||
"Rate in packets per second at which packets are sent over UDP.",
|
"Rate in packets per second at which packets are sent over UDP.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FECRate = prometheus.NewDesc(
|
c.fecRate = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_fec_rate"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_fec_rate"),
|
||||||
"Forward Error Correction (FEC) percentage",
|
"Forward Error Correction (FEC) percentage",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.LossRate = prometheus.NewDesc(
|
c.lossRate = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_loss_rate"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_loss_rate"),
|
||||||
"Loss percentage",
|
"Loss percentage",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RetransmissionRate = prometheus.NewDesc(
|
c.retransmissionRate = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_retransmission_rate"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_retransmission_rate"),
|
||||||
"Percentage of packets that have been retransmitted",
|
"Percentage of packets that have been retransmitted",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
@@ -157,43 +170,43 @@ func (c *collector) Build() error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// gfx
|
// gfx
|
||||||
c.AverageEncodingTime = prometheus.NewDesc(
|
c.averageEncodingTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_average_encoding_time_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_average_encoding_time_seconds"),
|
||||||
"Average frame encoding time in seconds",
|
"Average frame encoding time in seconds",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FrameQuality = prometheus.NewDesc(
|
c.frameQuality = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_frame_quality"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_frame_quality"),
|
||||||
"Quality of the output frame expressed as a percentage of the quality of the source frame.",
|
"Quality of the output frame expressed as a percentage of the quality of the source frame.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.FramesSkippedPerSecondInsufficientResources = prometheus.NewDesc(
|
c.framesSkippedPerSecondInsufficientResources = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_frames_skipped_insufficient_resource_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_frames_skipped_insufficient_resource_total"),
|
||||||
"Number of frames skipped per second due to insufficient client resources.",
|
"Number of frames skipped per second due to insufficient client resources.",
|
||||||
[]string{"session_name", "resource"},
|
[]string{"session_name", "resource"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.GraphicsCompressionratio = prometheus.NewDesc(
|
c.graphicsCompressionRatio = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_graphics_compression_ratio"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_graphics_compression_ratio"),
|
||||||
"Ratio of the number of bytes encoded to the number of bytes input.",
|
"Ratio of the number of bytes encoded to the number of bytes input.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.InputFramesPerSecond = prometheus.NewDesc(
|
c.inputFramesPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_input_frames_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_input_frames_total"),
|
||||||
"Number of sources frames provided as input to RemoteFX graphics per second.",
|
"Number of sources frames provided as input to RemoteFX graphics per second.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OutputFramesPerSecond = prometheus.NewDesc(
|
c.outputFramesPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_output_frames_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_output_frames_total"),
|
||||||
"Number of frames sent to the client per second.",
|
"Number of frames sent to the client per second.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SourceFramesPerSecond = prometheus.NewDesc(
|
c.sourceFramesPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "gfx_source_frames_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "gfx_source_frames_total"),
|
||||||
"Number of frames composed by the source (DWM) per second.",
|
"Number of frames composed by the source (DWM) per second.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
@@ -204,7 +217,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collectRemoteFXNetworkCount(ctx, ch); err != nil {
|
if err := c.collectRemoteFXNetworkCount(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting terminal services session count metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting terminal services session count metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -233,7 +246,7 @@ type perflibRemoteFxNetwork struct {
|
|||||||
RetransmissionRate float64 `perflib:"Percentage of packets that have been retransmitted"`
|
RetransmissionRate float64 `perflib:"Percentage of packets that have been retransmitted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectRemoteFXNetworkCount(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectRemoteFXNetworkCount(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
dst := make([]perflibRemoteFxNetwork, 0)
|
dst := make([]perflibRemoteFxNetwork, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["RemoteFX Network"], &dst, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["RemoteFX Network"], &dst, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -247,81 +260,81 @@ func (c *collector) collectRemoteFXNetworkCount(ctx *types.ScrapeContext, ch cha
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BaseTCPRTT,
|
c.baseTCPRTT,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.BaseTCPRTT),
|
utils.MilliSecToSec(d.BaseTCPRTT),
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BaseUDPRTT,
|
c.baseUDPRTT,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.BaseUDPRTT),
|
utils.MilliSecToSec(d.BaseUDPRTT),
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentTCPBandwidth,
|
c.currentTCPBandwidth,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
(d.CurrentTCPBandwidth*1000)/8,
|
(d.CurrentTCPBandwidth*1000)/8,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentTCPRTT,
|
c.currentTCPRTT,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.CurrentTCPRTT),
|
utils.MilliSecToSec(d.CurrentTCPRTT),
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentUDPBandwidth,
|
c.currentUDPBandwidth,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
(d.CurrentUDPBandwidth*1000)/8,
|
(d.CurrentUDPBandwidth*1000)/8,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentUDPRTT,
|
c.currentUDPRTT,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.CurrentUDPRTT),
|
utils.MilliSecToSec(d.CurrentUDPRTT),
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalReceivedBytes,
|
c.totalReceivedBytes,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.TotalReceivedBytes,
|
d.TotalReceivedBytes,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TotalSentBytes,
|
c.totalSentBytes,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.TotalSentBytes,
|
d.TotalSentBytes,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UDPPacketsReceivedPersec,
|
c.udpPacketsReceivedPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.UDPPacketsReceivedPersec,
|
d.UDPPacketsReceivedPersec,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.UDPPacketsSentPersec,
|
c.udpPacketsSentPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.UDPPacketsSentPersec,
|
d.UDPPacketsSentPersec,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FECRate,
|
c.fecRate,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.FECRate,
|
d.FECRate,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LossRate,
|
c.lossRate,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.LossRate,
|
d.LossRate,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RetransmissionRate,
|
c.retransmissionRate,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.RetransmissionRate,
|
d.RetransmissionRate,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
@@ -343,7 +356,7 @@ type perflibRemoteFxGraphics struct {
|
|||||||
SourceFramesPerSecond float64 `perflib:"Source Frames/Second"`
|
SourceFramesPerSecond float64 `perflib:"Source Frames/Second"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectRemoteFXGraphicsCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectRemoteFXGraphicsCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
dst := make([]perflibRemoteFxGraphics, 0)
|
dst := make([]perflibRemoteFxGraphics, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["RemoteFX Graphics"], &dst, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["RemoteFX Graphics"], &dst, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -357,58 +370,58 @@ func (c *collector) collectRemoteFXGraphicsCounters(ctx *types.ScrapeContext, ch
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AverageEncodingTime,
|
c.averageEncodingTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
utils.MilliSecToSec(d.AverageEncodingTime),
|
utils.MilliSecToSec(d.AverageEncodingTime),
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FrameQuality,
|
c.frameQuality,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.FrameQuality,
|
d.FrameQuality,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FramesSkippedPerSecondInsufficientResources,
|
c.framesSkippedPerSecondInsufficientResources,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.FramesSkippedPerSecondInsufficientClientResources,
|
d.FramesSkippedPerSecondInsufficientClientResources,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
"client",
|
"client",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FramesSkippedPerSecondInsufficientResources,
|
c.framesSkippedPerSecondInsufficientResources,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.FramesSkippedPerSecondInsufficientNetworkResources,
|
d.FramesSkippedPerSecondInsufficientNetworkResources,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
"network",
|
"network",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.FramesSkippedPerSecondInsufficientResources,
|
c.framesSkippedPerSecondInsufficientResources,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.FramesSkippedPerSecondInsufficientServerResources,
|
d.FramesSkippedPerSecondInsufficientServerResources,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
"server",
|
"server",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.GraphicsCompressionratio,
|
c.graphicsCompressionRatio,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.GraphicsCompressionratio,
|
d.GraphicsCompressionratio,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InputFramesPerSecond,
|
c.inputFramesPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.InputFramesPerSecond,
|
d.InputFramesPerSecond,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OutputFramesPerSecond,
|
c.outputFramesPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.OutputFramesPerSecond,
|
d.OutputFramesPerSecond,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SourceFramesPerSecond,
|
c.sourceFramesPerSecond,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.SourceFramesPerSecond,
|
d.SourceFramesPerSecond,
|
||||||
normalizeSessionName(d.Name),
|
normalizeSessionName(d.Name),
|
||||||
@@ -418,7 +431,7 @@ func (c *collector) collectRemoteFXGraphicsCounters(ctx *types.ScrapeContext, ch
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeSessionName ensure that the session is the same between WTS API and performance counters
|
// normalizeSessionName ensure that the session is the same between WTS API and performance counters.
|
||||||
func normalizeSessionName(sessionName string) string {
|
func normalizeSessionName(sessionName string) string {
|
||||||
return strings.Replace(sessionName, "RDP-tcp", "RDP-Tcp", 1)
|
return strings.Replace(sessionName, "RDP-tcp", "RDP-Tcp", 1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,45 +9,34 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/go-ole/go-ole"
|
"github.com/go-ole/go-ole"
|
||||||
"github.com/go-ole/go-ole/oleutil"
|
"github.com/go-ole/go-ole/oleutil"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "scheduled_task"
|
||||||
Name = "scheduled_task"
|
|
||||||
|
|
||||||
FlagScheduledTaskExclude = "collector.scheduled_task.exclude"
|
|
||||||
FlagScheduledTaskInclude = "collector.scheduled_task.include"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
TaskExclude string `yaml:"task_exclude"`
|
TaskExclude *regexp.Regexp `yaml:"task_exclude"`
|
||||||
TaskInclude string `yaml:"task_include"`
|
TaskInclude *regexp.Regexp `yaml:"task_include"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
TaskExclude: "",
|
TaskExclude: types.RegExpEmpty,
|
||||||
TaskInclude: ".+",
|
TaskInclude: types.RegExpAny,
|
||||||
}
|
}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
taskExclude *string
|
lastResult *prometheus.Desc
|
||||||
taskInclude *string
|
missedRuns *prometheus.Desc
|
||||||
|
state *prometheus.Desc
|
||||||
LastResult *prometheus.Desc
|
|
||||||
MissedRuns *prometheus.Desc
|
|
||||||
State *prometheus.Desc
|
|
||||||
|
|
||||||
taskIncludePattern *regexp.Regexp
|
|
||||||
taskExcludePattern *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskState ...
|
// TaskState ...
|
||||||
@@ -62,7 +51,11 @@ const (
|
|||||||
TASK_STATE_QUEUED
|
TASK_STATE_QUEUED
|
||||||
TASK_STATE_READY
|
TASK_STATE_READY
|
||||||
TASK_STATE_RUNNING
|
TASK_STATE_RUNNING
|
||||||
TASK_RESULT_SUCCESS TaskResult = 0x0
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SCHED_S_SUCCESS TaskResult = 0x0
|
||||||
|
SCHED_S_TASK_HAS_NOT_RUN TaskResult = 0x00041303
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScheduledTask struct {
|
type ScheduledTask struct {
|
||||||
@@ -76,85 +69,106 @@ type ScheduledTask struct {
|
|||||||
|
|
||||||
type ScheduledTasks []ScheduledTask
|
type ScheduledTasks []ScheduledTask
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.TaskExclude == nil {
|
||||||
taskExclude: &config.TaskExclude,
|
config.TaskExclude = ConfigDefaults.TaskExclude
|
||||||
taskInclude: &config.TaskInclude,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.TaskInclude == nil {
|
||||||
|
config.TaskInclude = ConfigDefaults.TaskInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
taskInclude: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagScheduledTaskInclude,
|
|
||||||
"Regexp of tasks to include. Task path must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.TaskInclude).String(),
|
|
||||||
|
|
||||||
taskExclude: app.Flag(
|
|
||||||
FlagScheduledTaskExclude,
|
|
||||||
"Regexp of tasks to exclude. Task path must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.TaskExclude).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var taskExclude, taskInclude string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.scheduled_task.exclude",
|
||||||
|
"Regexp of tasks to exclude. Task path must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.TaskExclude.String()).StringVar(&taskExclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.scheduled_task.include",
|
||||||
|
"Regexp of tasks to include. Task path must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.TaskInclude.String()).StringVar(&taskInclude)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.TaskExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", taskExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.scheduled_task.exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.TaskInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", taskInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.scheduled_task.include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.LastResult = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.lastResult = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "last_result"),
|
prometheus.BuildFQName(types.Namespace, Name, "last_result"),
|
||||||
"The result that was returned the last time the registered task was run",
|
"The result that was returned the last time the registered task was run",
|
||||||
[]string{"task"},
|
[]string{"task"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.MissedRuns = prometheus.NewDesc(
|
c.missedRuns = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "missed_runs"),
|
prometheus.BuildFQName(types.Namespace, Name, "missed_runs"),
|
||||||
"The number of times the registered task missed a scheduled run",
|
"The number of times the registered task missed a scheduled run",
|
||||||
[]string{"task"},
|
[]string{"task"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.State = prometheus.NewDesc(
|
c.state = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
prometheus.BuildFQName(types.Namespace, Name, "state"),
|
||||||
"The current state of a scheduled task",
|
"The current state of a scheduled task",
|
||||||
[]string{"task", "state"},
|
[]string{"task", "state"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
c.taskIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.taskInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.taskExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.taskExclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting user metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting user metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -165,37 +179,18 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
|
|
||||||
var TASK_STATES = []string{"disabled", "queued", "ready", "running", "unknown"}
|
var TASK_STATES = []string{"disabled", "queued", "ready", "running", "unknown"}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
scheduledTasks, err := getScheduledTasks()
|
scheduledTasks, err := getScheduledTasks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, task := range scheduledTasks {
|
for _, task := range scheduledTasks {
|
||||||
if c.taskExcludePattern.MatchString(task.Path) ||
|
if c.config.TaskExclude.MatchString(task.Path) ||
|
||||||
!c.taskIncludePattern.MatchString(task.Path) {
|
!c.config.TaskInclude.MatchString(task.Path) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
lastResult := 0.0
|
|
||||||
if task.LastTaskResult == TASK_RESULT_SUCCESS {
|
|
||||||
lastResult = 1.0
|
|
||||||
}
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.LastResult,
|
|
||||||
prometheus.GaugeValue,
|
|
||||||
lastResult,
|
|
||||||
task.Path,
|
|
||||||
)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.MissedRuns,
|
|
||||||
prometheus.GaugeValue,
|
|
||||||
task.MissedRunsCount,
|
|
||||||
task.Path,
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, state := range TASK_STATES {
|
for _, state := range TASK_STATES {
|
||||||
var stateValue float64
|
var stateValue float64
|
||||||
|
|
||||||
@@ -204,13 +199,36 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.State,
|
c.state,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
stateValue,
|
stateValue,
|
||||||
task.Path,
|
task.Path,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if task.LastTaskResult == SCHED_S_TASK_HAS_NOT_RUN {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
lastResult := 0.0
|
||||||
|
if task.LastTaskResult == SCHED_S_SUCCESS {
|
||||||
|
lastResult = 1.0
|
||||||
|
}
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.lastResult,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
lastResult,
|
||||||
|
task.Path,
|
||||||
|
)
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.missedRuns,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
task.MissedRunsCount,
|
||||||
|
task.Path,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -221,7 +239,9 @@ const SCHEDULED_TASK_PROGRAM_ID = "Schedule.Service.1"
|
|||||||
// S_FALSE is returned by CoInitialize if it was already called on this thread.
|
// S_FALSE is returned by CoInitialize if it was already called on this thread.
|
||||||
const S_FALSE = 0x00000001
|
const S_FALSE = 0x00000001
|
||||||
|
|
||||||
func getScheduledTasks() (scheduledTasks ScheduledTasks, err error) {
|
func getScheduledTasks() (ScheduledTasks, error) {
|
||||||
|
var scheduledTasks ScheduledTasks
|
||||||
|
|
||||||
// The only way to run WMI queries in parallel while being thread-safe is to
|
// The only way to run WMI queries in parallel while being thread-safe is to
|
||||||
// ensure the CoInitialize[Ex]() call is bound to its current OS thread.
|
// ensure the CoInitialize[Ex]() call is bound to its current OS thread.
|
||||||
// Otherwise, attempting to initialize and run parallel queries across
|
// Otherwise, attempting to initialize and run parallel queries across
|
||||||
@@ -316,7 +336,9 @@ func fetchTasksRecursively(folder *ole.IDispatch, scheduledTasks *ScheduledTasks
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTask(task *ole.IDispatch) (scheduledTask ScheduledTask, err error) {
|
func parseTask(task *ole.IDispatch) (ScheduledTask, error) {
|
||||||
|
var scheduledTask ScheduledTask
|
||||||
|
|
||||||
taskNameVar, err := oleutil.GetProperty(task, "Name")
|
taskNameVar, err := oleutil.GetProperty(task, "Name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return scheduledTask, err
|
return scheduledTask, err
|
||||||
@@ -379,7 +401,9 @@ func parseTask(task *ole.IDispatch) (scheduledTask ScheduledTask, err error) {
|
|||||||
|
|
||||||
scheduledTask.Name = taskNameVar.ToString()
|
scheduledTask.Name = taskNameVar.ToString()
|
||||||
scheduledTask.Path = strings.ReplaceAll(taskPathVar.ToString(), "\\", "/")
|
scheduledTask.Path = strings.ReplaceAll(taskPathVar.ToString(), "\\", "/")
|
||||||
scheduledTask.Enabled = taskEnabledVar.Value().(bool)
|
if val, ok := taskEnabledVar.Value().(bool); ok {
|
||||||
|
scheduledTask.Enabled = val
|
||||||
|
}
|
||||||
scheduledTask.State = TaskState(taskStateVar.Val)
|
scheduledTask.State = TaskState(taskStateVar.Val)
|
||||||
scheduledTask.MissedRunsCount = float64(taskNumberOfMissedRunsVar.Val)
|
scheduledTask.MissedRunsCount = float64(taskNumberOfMissedRunsVar.Val)
|
||||||
scheduledTask.LastTaskResult = TaskResult(taskLastTaskResultVar.Val)
|
scheduledTask.LastTaskResult = TaskResult(taskLastTaskResultVar.Val)
|
||||||
|
|||||||
@@ -21,12 +21,7 @@ import (
|
|||||||
"golang.org/x/sys/windows/svc/mgr"
|
"golang.org/x/sys/windows/svc/mgr"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "service"
|
||||||
Name = "service"
|
|
||||||
FlagServiceWhereClause = "collector.service.services-where"
|
|
||||||
FlagServiceUseAPI = "collector.service.use-api"
|
|
||||||
FlagServiceCollectorV2 = "collector.service.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ServiceWhereClause string `yaml:"service_where_clause"`
|
ServiceWhereClause string `yaml:"service_where_clause"`
|
||||||
@@ -40,8 +35,8 @@ var ConfigDefaults = Config{
|
|||||||
V2: false,
|
V2: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_Service metrics
|
// A Collector is a Prometheus Collector for WMI Win32_Service metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
serviceWhereClause *string
|
serviceWhereClause *string
|
||||||
@@ -55,49 +50,54 @@ type collector struct {
|
|||||||
StateV2 *prometheus.Desc
|
StateV2 *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
serviceWhereClause: &config.ServiceWhereClause,
|
serviceWhereClause: &config.ServiceWhereClause,
|
||||||
useAPI: &config.UseAPI,
|
useAPI: &config.UseAPI,
|
||||||
}
|
}
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
return &collector{
|
return &Collector{
|
||||||
serviceWhereClause: app.Flag(
|
serviceWhereClause: app.Flag(
|
||||||
FlagServiceWhereClause,
|
"collector.service.services-where",
|
||||||
"WQL 'where' clause to use in WMI metrics query. Limits the response to the services you specify and reduces the size of the response.",
|
"WQL 'where' clause to use in WMI metrics query. Limits the response to the services you specify and reduces the size of the response.",
|
||||||
).Default(ConfigDefaults.ServiceWhereClause).String(),
|
).Default(ConfigDefaults.ServiceWhereClause).String(),
|
||||||
useAPI: app.Flag(
|
useAPI: app.Flag(
|
||||||
FlagServiceUseAPI,
|
"collector.service.use-api",
|
||||||
"Use API calls to collect service data instead of WMI. Flag 'collector.service.services-where' won't be effective.",
|
"Use API calls to collect service data instead of WMI. Flag 'collector.service.services-where' won't be effective.",
|
||||||
).Default(strconv.FormatBool(ConfigDefaults.UseAPI)).Bool(),
|
).Default(strconv.FormatBool(ConfigDefaults.UseAPI)).Bool(),
|
||||||
v2: app.Flag(
|
v2: app.Flag(
|
||||||
FlagServiceCollectorV2,
|
"collector.service.v2",
|
||||||
"Enable V2 service collector. This collector can services state much more efficiently, can't provide general service information.",
|
"Enable V2 service collector. This collector can services state much more efficiently, can't provide general service information.",
|
||||||
).Default(strconv.FormatBool(ConfigDefaults.V2)).Bool(),
|
).Default(strconv.FormatBool(ConfigDefaults.V2)).Bool(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
if utils.IsEmpty(c.serviceWhereClause) {
|
if utils.IsEmpty(c.serviceWhereClause) {
|
||||||
_ = level.Warn(c.logger).Log("msg", "No where-clause specified for service collector. This will generate a very large number of metrics!")
|
_ = level.Warn(c.logger).Log("msg", "No where-clause specified for service collector. This will generate a very large number of metrics!")
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
@@ -224,9 +224,9 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *collector) collectWMI(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectWMI(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_Service
|
var dst []Win32_Service
|
||||||
q := wmi.QueryAllWhere(&dst, *c.serviceWhereClause, c.logger)
|
q := wmi.QueryAllWhere(&dst, *c.serviceWhereClause, c.logger) //nolint:staticcheck
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ func (c *collector) collectWMI(ch chan<- prometheus.Metric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectAPI(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAPI(ch chan<- prometheus.Metric) error {
|
||||||
svcmgrConnection, err := mgr.Connect()
|
svcmgrConnection, err := mgr.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -384,7 +384,7 @@ func (c *collector) collectAPI(ch chan<- prometheus.Metric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectAPIV2(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAPIV2(ch chan<- prometheus.Metric) error {
|
||||||
services, err := c.queryAllServiceStates()
|
services, err := c.queryAllServiceStates()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = level.Warn(c.logger).Log("msg", "Failed to query services", "err", err)
|
_ = level.Warn(c.logger).Log("msg", "Failed to query services", "err", err)
|
||||||
@@ -428,7 +428,7 @@ func (c *collector) collectAPIV2(ch chan<- prometheus.Metric) error {
|
|||||||
// Copyright 2016-present Datadog, Inc.
|
// Copyright 2016-present Datadog, Inc.
|
||||||
//
|
//
|
||||||
// Source: https://github.com/DataDog/datadog-agent/blob/afbd8b6c87939c92610c654cb07fdfd439e4fb27/pkg/util/winutil/scmmonitor.go#L61-L96
|
// Source: https://github.com/DataDog/datadog-agent/blob/afbd8b6c87939c92610c654cb07fdfd439e4fb27/pkg/util/winutil/scmmonitor.go#L61-L96
|
||||||
func (c *collector) queryAllServiceStates() ([]windows.ENUM_SERVICE_STATUS_PROCESS, error) {
|
func (c *Collector) queryAllServiceStates() ([]windows.ENUM_SERVICE_STATUS_PROCESS, error) {
|
||||||
// EnumServiceStatusEx requires only SC_MANAGER_ENUM_SERVICE.
|
// EnumServiceStatusEx requires only SC_MANAGER_ENUM_SERVICE.
|
||||||
h, err := windows.OpenSCManager(nil, nil, windows.SC_MANAGER_ENUMERATE_SERVICE)
|
h, err := windows.OpenSCManager(nil, nil, windows.SC_MANAGER_ENUMERATE_SERVICE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
package smb
|
package smb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
@@ -16,80 +13,57 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "smb"
|
||||||
Name = "smb"
|
|
||||||
FlagSmbListAllCollectors = "collectors.smb.list"
|
|
||||||
FlagSmbCollectorsEnabled = "collectors.smb.enabled"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct{}
|
||||||
CollectorsEnabled string `yaml:"collectors_enabled"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{}
|
||||||
CollectorsEnabled: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
smbListAllCollectors *bool
|
treeConnectCount *prometheus.Desc
|
||||||
smbCollectorsEnabled *string
|
currentOpenFileCount *prometheus.Desc
|
||||||
|
|
||||||
TreeConnectCount *prometheus.Desc
|
|
||||||
CurrentOpenFileCount *prometheus.Desc
|
|
||||||
|
|
||||||
enabledCollectors []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All available collector functions
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
var smbAllCollectorNames = []string{
|
|
||||||
"ServerShares",
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
smbListAllCollectors := false
|
c := &Collector{
|
||||||
c := &collector{
|
config: *config,
|
||||||
smbCollectorsEnabled: &config.CollectorsEnabled,
|
|
||||||
smbListAllCollectors: &smbListAllCollectors,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{
|
return &Collector{}
|
||||||
smbListAllCollectors: app.Flag(
|
|
||||||
FlagSmbListAllCollectors,
|
|
||||||
"List the collectors along with their perflib object name/ids",
|
|
||||||
).Bool(),
|
|
||||||
|
|
||||||
smbCollectorsEnabled: app.Flag(
|
|
||||||
FlagSmbCollectorsEnabled,
|
|
||||||
"Comma-separated list of collectors to use. Defaults to all, if not specified.",
|
|
||||||
).Default(ConfigDefaults.CollectorsEnabled).String(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{
|
return []string{
|
||||||
"SMB Server Shares",
|
"SMB Server Shares",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
// desc creates a new prometheus description
|
// desc creates a new prometheus description
|
||||||
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
||||||
return prometheus.NewDesc(
|
return prometheus.NewDesc(
|
||||||
@@ -100,56 +74,24 @@ func (c *collector) Build() error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.CurrentOpenFileCount = desc("server_shares_current_open_file_count", "Current total count open files on the SMB Server")
|
c.currentOpenFileCount = desc("server_shares_current_open_file_count", "Current total count open files on the SMB Server")
|
||||||
c.TreeConnectCount = desc("server_shares_tree_connect_count", "Count of user connections to the SMB Server")
|
c.treeConnectCount = desc("server_shares_tree_connect_count", "Count of user connections to the SMB Server")
|
||||||
|
|
||||||
c.enabledCollectors = make([]string, 0, len(smbAllCollectorNames))
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
collectorDesc := map[string]string{
|
// Collect collects smb metrics and sends them to prometheus.
|
||||||
"ServerShares": "SMB Server Shares",
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
}
|
if err := c.collectServerShares(ctx, ch); err != nil {
|
||||||
|
_ = level.Error(c.logger).Log("msg", "failed to collect server share metrics", "err", err)
|
||||||
|
|
||||||
if *c.smbListAllCollectors {
|
return err
|
||||||
fmt.Printf("%-32s %-32s\n", "Collector Name", "Perflib Object")
|
|
||||||
for _, cname := range smbAllCollectorNames {
|
|
||||||
fmt.Printf("%-32s %-32s\n", cname, collectorDesc[cname])
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *c.smbCollectorsEnabled == "" {
|
|
||||||
for _, collectorName := range smbAllCollectorNames {
|
|
||||||
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, collectorName := range strings.Split(*c.smbCollectorsEnabled, ",") {
|
|
||||||
if slices.Contains(smbAllCollectorNames, collectorName) {
|
|
||||||
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("unknown smb collector: %s", collectorName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect collects smb metrics and sends them to prometheus
|
// Perflib: SMB Server Shares.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
|
||||||
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
|
|
||||||
"ServerShares": c.collectServerShares,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, collectorName := range c.enabledCollectors {
|
|
||||||
if err := collectorFuncs[collectorName](ctx, ch); err != nil {
|
|
||||||
_ = level.Error(c.logger).Log("msg", "Error in "+collectorName, "err", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perflib: SMB Server Shares
|
|
||||||
type perflibServerShares struct {
|
type perflibServerShares struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -157,7 +99,7 @@ type perflibServerShares struct {
|
|||||||
TreeConnectCount float64 `perflib:"Tree Connect Count"`
|
TreeConnectCount float64 `perflib:"Tree Connect Count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibServerShares
|
var data []perflibServerShares
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMB Server Shares"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMB Server Shares"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -169,23 +111,22 @@ func (c *collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentOpenFileCount,
|
c.currentOpenFileCount,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.CurrentOpenFileCount,
|
instance.CurrentOpenFileCount,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TreeConnectCount,
|
c.treeConnectCount,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.TreeConnectCount,
|
instance.TreeConnectCount,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores
|
// toLabelName converts strings to lowercase and replaces all whitespaces and dots with underscores.
|
||||||
func (c *collector) toLabelName(name string) string {
|
func (c *Collector) toLabelName(name string) string {
|
||||||
s := strings.ReplaceAll(strings.Join(strings.Fields(strings.ToLower(name)), "_"), ".", "_")
|
s := strings.ReplaceAll(strings.Join(strings.Fields(strings.ToLower(name)), "_"), ".", "_")
|
||||||
s = strings.ReplaceAll(s, "__", "_")
|
s = strings.ReplaceAll(s, "__", "_")
|
||||||
return s
|
return s
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
package smbclient
|
package smbclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
@@ -17,100 +14,78 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Name = "smbclient"
|
Name = "smbclient"
|
||||||
FlagSmbClientListAllCollectors = "collectors.smbclient.list"
|
|
||||||
FlagSmbClientCollectorsEnabled = "collectors.smbclient.enabled"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct{}
|
||||||
CollectorsEnabled string `yaml:"collectors_enabled"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{}
|
||||||
CollectorsEnabled: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
smbclientListAllCollectors *bool
|
readBytesTotal *prometheus.Desc
|
||||||
smbclientCollectorsEnabled *string
|
readBytesTransmittedViaSMBDirectTotal *prometheus.Desc
|
||||||
|
readRequestQueueSecsTotal *prometheus.Desc
|
||||||
ReadRequestQueueSecsTotal *prometheus.Desc
|
readRequestsTransmittedViaSMBDirectTotal *prometheus.Desc
|
||||||
ReadBytesTotal *prometheus.Desc
|
readSecsTotal *prometheus.Desc
|
||||||
ReadsTotal *prometheus.Desc
|
readsTotal *prometheus.Desc
|
||||||
ReadBytesTransmittedViaSMBDirectTotal *prometheus.Desc
|
turboIOReadsTotal *prometheus.Desc
|
||||||
ReadRequestsTransmittedViaSMBDirectTotal *prometheus.Desc
|
|
||||||
TurboIOReadsTotal *prometheus.Desc
|
|
||||||
ReadSecsTotal *prometheus.Desc
|
|
||||||
|
|
||||||
WriteRequestQueueSecsTotal *prometheus.Desc
|
|
||||||
WriteBytesTotal *prometheus.Desc
|
|
||||||
WritesTotal *prometheus.Desc
|
|
||||||
WriteBytesTransmittedViaSMBDirectTotal *prometheus.Desc
|
|
||||||
WriteRequestsTransmittedViaSMBDirectTotal *prometheus.Desc
|
|
||||||
TurboIOWritesTotal *prometheus.Desc
|
TurboIOWritesTotal *prometheus.Desc
|
||||||
WriteSecsTotal *prometheus.Desc
|
writeBytesTotal *prometheus.Desc
|
||||||
|
writeBytesTransmittedViaSMBDirectTotal *prometheus.Desc
|
||||||
|
writeRequestQueueSecsTotal *prometheus.Desc
|
||||||
|
writeRequestsTransmittedViaSMBDirectTotal *prometheus.Desc
|
||||||
|
writeSecsTotal *prometheus.Desc
|
||||||
|
writesTotal *prometheus.Desc
|
||||||
|
|
||||||
RequestQueueSecsTotal *prometheus.Desc
|
creditStallsTotal *prometheus.Desc
|
||||||
RequestSecs *prometheus.Desc
|
currentDataQueued *prometheus.Desc
|
||||||
CreditStallsTotal *prometheus.Desc
|
dataBytesTotal *prometheus.Desc
|
||||||
CurrentDataQueued *prometheus.Desc
|
dataRequestsTotal *prometheus.Desc
|
||||||
DataBytesTotal *prometheus.Desc
|
metadataRequestsTotal *prometheus.Desc
|
||||||
DataRequestsTotal *prometheus.Desc
|
requestQueueSecsTotal *prometheus.Desc
|
||||||
MetadataRequestsTotal *prometheus.Desc
|
requestSecs *prometheus.Desc
|
||||||
|
|
||||||
enabledCollectors []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All available collector functions
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
var smbclientAllCollectorNames = []string{
|
|
||||||
"ClientShares",
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
smbclientListAllCollectors := false
|
c := &Collector{
|
||||||
c := &collector{
|
config: *config,
|
||||||
smbclientCollectorsEnabled: &config.CollectorsEnabled,
|
|
||||||
smbclientListAllCollectors: &smbclientListAllCollectors,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{
|
return &Collector{}
|
||||||
smbclientListAllCollectors: app.Flag(
|
|
||||||
FlagSmbClientListAllCollectors,
|
|
||||||
"List the collectors along with their perflib object name/ids",
|
|
||||||
).Bool(),
|
|
||||||
|
|
||||||
smbclientCollectorsEnabled: app.Flag(
|
|
||||||
FlagSmbClientCollectorsEnabled,
|
|
||||||
"Comma-separated list of collectors to use. Defaults to all, if not specified.",
|
|
||||||
).Default(ConfigDefaults.CollectorsEnabled).String(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{
|
return []string{
|
||||||
"SMB Client Shares",
|
"SMB Client Shares",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
// desc creates a new prometheus description
|
// desc creates a new prometheus description
|
||||||
desc := func(metricName string, description string, labels []string) *prometheus.Desc {
|
desc := func(metricName string, description string, labels []string) *prometheus.Desc {
|
||||||
return prometheus.NewDesc(
|
return prometheus.NewDesc(
|
||||||
@@ -121,59 +96,59 @@ func (c *collector) Build() error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.RequestQueueSecsTotal = desc("data_queue_seconds_total",
|
c.requestQueueSecsTotal = desc("data_queue_seconds_total",
|
||||||
"Seconds requests waited on queue on this share",
|
"Seconds requests waited on queue on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.ReadRequestQueueSecsTotal = desc("read_queue_seconds_total",
|
c.readRequestQueueSecsTotal = desc("read_queue_seconds_total",
|
||||||
"Seconds read requests waited on queue on this share",
|
"Seconds read requests waited on queue on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.WriteRequestQueueSecsTotal = desc("write_queue_seconds_total",
|
c.writeRequestQueueSecsTotal = desc("write_queue_seconds_total",
|
||||||
"Seconds write requests waited on queue on this share",
|
"Seconds write requests waited on queue on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.RequestSecs = desc("request_seconds_total",
|
c.requestSecs = desc("request_seconds_total",
|
||||||
"Seconds waiting for requests on this share",
|
"Seconds waiting for requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.CreditStallsTotal = desc("stalls_total",
|
c.creditStallsTotal = desc("stalls_total",
|
||||||
"The number of requests delayed based on insufficient credits on this share",
|
"The number of requests delayed based on insufficient credits on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.CurrentDataQueued = desc("requests_queued",
|
c.currentDataQueued = desc("requests_queued",
|
||||||
"The point in time number of requests outstanding on this share",
|
"The point in time number of requests outstanding on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.DataBytesTotal = desc("data_bytes_total",
|
c.dataBytesTotal = desc("data_bytes_total",
|
||||||
"The bytes read or written on this share",
|
"The bytes read or written on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.DataRequestsTotal = desc("requests_total",
|
c.dataRequestsTotal = desc("requests_total",
|
||||||
"The requests on this share",
|
"The requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.MetadataRequestsTotal = desc("metadata_requests_total",
|
c.metadataRequestsTotal = desc("metadata_requests_total",
|
||||||
"The metadata requests on this share",
|
"The metadata requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.ReadBytesTransmittedViaSMBDirectTotal = desc("read_bytes_via_smbdirect_total",
|
c.readBytesTransmittedViaSMBDirectTotal = desc("read_bytes_via_smbdirect_total",
|
||||||
"The bytes read from this share via RDMA direct placement",
|
"The bytes read from this share via RDMA direct placement",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.ReadBytesTotal = desc("read_bytes_total",
|
c.readBytesTotal = desc("read_bytes_total",
|
||||||
"The bytes read on this share",
|
"The bytes read on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.ReadRequestsTransmittedViaSMBDirectTotal = desc("read_requests_via_smbdirect_total",
|
c.readRequestsTransmittedViaSMBDirectTotal = desc("read_requests_via_smbdirect_total",
|
||||||
"The read requests on this share via RDMA direct placement",
|
"The read requests on this share via RDMA direct placement",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.ReadsTotal = desc("read_requests_total",
|
c.readsTotal = desc("read_requests_total",
|
||||||
"The read requests on this share",
|
"The read requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.TurboIOReadsTotal = desc("turbo_io_reads_total",
|
c.turboIOReadsTotal = desc("turbo_io_reads_total",
|
||||||
"The read requests that go through Turbo I/O",
|
"The read requests that go through Turbo I/O",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
@@ -181,78 +156,45 @@ func (c *collector) Build() error {
|
|||||||
"The write requests that go through Turbo I/O",
|
"The write requests that go through Turbo I/O",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.WriteBytesTransmittedViaSMBDirectTotal = desc("write_bytes_via_smbdirect_total",
|
c.writeBytesTransmittedViaSMBDirectTotal = desc("write_bytes_via_smbdirect_total",
|
||||||
"The written bytes to this share via RDMA direct placement",
|
"The written bytes to this share via RDMA direct placement",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.WriteBytesTotal = desc("write_bytes_total",
|
c.writeBytesTotal = desc("write_bytes_total",
|
||||||
"The bytes written on this share",
|
"The bytes written on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.WriteRequestsTransmittedViaSMBDirectTotal = desc("write_requests_via_smbdirect_total",
|
c.writeRequestsTransmittedViaSMBDirectTotal = desc("write_requests_via_smbdirect_total",
|
||||||
"The write requests to this share via RDMA direct placement",
|
"The write requests to this share via RDMA direct placement",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.WritesTotal = desc("write_requests_total",
|
c.writesTotal = desc("write_requests_total",
|
||||||
"The write requests on this share",
|
"The write requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.ReadSecsTotal = desc("read_seconds_total",
|
c.readSecsTotal = desc("read_seconds_total",
|
||||||
"Seconds waiting for read requests on this share",
|
"Seconds waiting for read requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
c.WriteSecsTotal = desc("write_seconds_total",
|
c.writeSecsTotal = desc("write_seconds_total",
|
||||||
"Seconds waiting for write requests on this share",
|
"Seconds waiting for write requests on this share",
|
||||||
[]string{"server", "share"},
|
[]string{"server", "share"},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.enabledCollectors = make([]string, 0, len(smbclientAllCollectorNames))
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
collectorDesc := map[string]string{
|
// Collect collects smb client metrics and sends them to prometheus.
|
||||||
"ClientShares": "SMB Client Shares",
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
}
|
if err := c.collectClientShares(ctx, ch); err != nil {
|
||||||
|
_ = level.Error(c.logger).Log("msg", "Error in ClientShares", "err", err)
|
||||||
if *c.smbclientListAllCollectors {
|
return err
|
||||||
fmt.Printf("%-32s %-32s\n", "Collector Name", "Perflib Object")
|
|
||||||
for _, cname := range smbclientAllCollectorNames {
|
|
||||||
fmt.Printf("%-32s %-32s\n", cname, collectorDesc[cname])
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *c.smbclientCollectorsEnabled == "" {
|
|
||||||
for _, collectorName := range smbclientAllCollectorNames {
|
|
||||||
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, collectorName := range strings.Split(*c.smbclientCollectorsEnabled, ",") {
|
|
||||||
if slices.Contains(smbclientAllCollectorNames, collectorName) {
|
|
||||||
c.enabledCollectors = append(c.enabledCollectors, collectorName)
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("unknown smbclient collector: %s", collectorName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect collects smb client metrics and sends them to prometheus
|
// Perflib: SMB Client Shares.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
|
||||||
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
|
|
||||||
"ClientShares": c.collectClientShares,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, collectorName := range c.enabledCollectors {
|
|
||||||
if err := collectorFuncs[collectorName](ctx, ch); err != nil {
|
|
||||||
_ = level.Error(c.logger).Log("msg", "Error in "+collectorName, "err", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perflib: SMB Client Shares
|
|
||||||
type perflibClientShares struct {
|
type perflibClientShares struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -279,7 +221,7 @@ type perflibClientShares struct {
|
|||||||
WriteRequestsPerSec float64 `perflib:"Write Requests/sec"`
|
WriteRequestsPerSec float64 `perflib:"Write Requests/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectClientShares(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectClientShares(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var data []perflibClientShares
|
var data []perflibClientShares
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMB Client Shares"], &data, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMB Client Shares"], &data, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -294,7 +236,7 @@ func (c *collector) collectClientShares(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
shareValue := parsed[1]
|
shareValue := parsed[1]
|
||||||
// Request time spent on queue. Convert from ticks to seconds.
|
// Request time spent on queue. Convert from ticks to seconds.
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestQueueSecsTotal,
|
c.requestQueueSecsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.AvgDataQueueLength*perflib.TicksToSecondScaleFactor,
|
instance.AvgDataQueueLength*perflib.TicksToSecondScaleFactor,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
@@ -302,28 +244,28 @@ func (c *collector) collectClientShares(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
|
|
||||||
// Read time spent on queue. Convert from ticks to seconds.
|
// Read time spent on queue. Convert from ticks to seconds.
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadRequestQueueSecsTotal,
|
c.readRequestQueueSecsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.AvgReadQueueLength*perflib.TicksToSecondScaleFactor,
|
instance.AvgReadQueueLength*perflib.TicksToSecondScaleFactor,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadSecsTotal,
|
c.readSecsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.AvgSecPerRead*perflib.TicksToSecondScaleFactor,
|
instance.AvgSecPerRead*perflib.TicksToSecondScaleFactor,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteSecsTotal,
|
c.writeSecsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.AvgSecPerWrite*perflib.TicksToSecondScaleFactor,
|
instance.AvgSecPerWrite*perflib.TicksToSecondScaleFactor,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RequestSecs,
|
c.requestSecs,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.AvgSecPerDataRequest*perflib.TicksToSecondScaleFactor,
|
instance.AvgSecPerDataRequest*perflib.TicksToSecondScaleFactor,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
@@ -331,77 +273,77 @@ func (c *collector) collectClientShares(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
|
|
||||||
// Write time spent on queue. Convert from ticks to seconds.
|
// Write time spent on queue. Convert from ticks to seconds.
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteRequestQueueSecsTotal,
|
c.writeRequestQueueSecsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.AvgWriteQueueLength*perflib.TicksToSecondScaleFactor,
|
instance.AvgWriteQueueLength*perflib.TicksToSecondScaleFactor,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CreditStallsTotal,
|
c.creditStallsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.CreditStallsPerSec,
|
instance.CreditStallsPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentDataQueued,
|
c.currentDataQueued,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
instance.CurrentDataQueueLength,
|
instance.CurrentDataQueueLength,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DataBytesTotal,
|
c.dataBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.DataBytesPerSec,
|
instance.DataBytesPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DataRequestsTotal,
|
c.dataRequestsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.DataRequestsPerSec,
|
instance.DataRequestsPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MetadataRequestsTotal,
|
c.metadataRequestsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.MetadataRequestsPerSec,
|
instance.MetadataRequestsPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadBytesTransmittedViaSMBDirectTotal,
|
c.readBytesTransmittedViaSMBDirectTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.ReadBytesTransmittedViaSMBDirectPerSec,
|
instance.ReadBytesTransmittedViaSMBDirectPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadBytesTotal,
|
c.readBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.ReadBytesPerSec,
|
instance.ReadBytesPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadRequestsTransmittedViaSMBDirectTotal,
|
c.readRequestsTransmittedViaSMBDirectTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.ReadRequestsTransmittedViaSMBDirectPerSec,
|
instance.ReadRequestsTransmittedViaSMBDirectPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ReadsTotal,
|
c.readsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.ReadRequestsPerSec,
|
instance.ReadRequestsPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TurboIOReadsTotal,
|
c.turboIOReadsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.TurboIOReadsPerSec,
|
instance.TurboIOReadsPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
@@ -415,33 +357,32 @@ func (c *collector) collectClientShares(ctx *types.ScrapeContext, ch chan<- prom
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteBytesTransmittedViaSMBDirectTotal,
|
c.writeBytesTransmittedViaSMBDirectTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.WriteBytesTransmittedViaSMBDirectPerSec,
|
instance.WriteBytesTransmittedViaSMBDirectPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteBytesTotal,
|
c.writeBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.WriteBytesPerSec,
|
instance.WriteBytesPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WriteRequestsTransmittedViaSMBDirectTotal,
|
c.writeRequestsTransmittedViaSMBDirectTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.WriteRequestsTransmittedViaSMBDirectPerSec,
|
instance.WriteRequestsTransmittedViaSMBDirectPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WritesTotal,
|
c.writesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
instance.WriteRequestsPerSec,
|
instance.WriteRequestsPerSec,
|
||||||
serverValue, shareValue,
|
serverValue, shareValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,391 +14,402 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "smtp"
|
||||||
Name = "smtp"
|
|
||||||
|
|
||||||
FlagSmtpServerExclude = "collector.smtp.server-exclude"
|
|
||||||
FlagSmtpServerInclude = "collector.smtp.server-include"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ServerInclude string `yaml:"server_include"`
|
ServerInclude *regexp.Regexp `yaml:"server_include"`
|
||||||
ServerExclude string `yaml:"server_exclude"`
|
ServerExclude *regexp.Regexp `yaml:"server_exclude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
ServerInclude: ".+",
|
ServerInclude: types.RegExpAny,
|
||||||
ServerExclude: "",
|
ServerExclude: types.RegExpEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
serverInclude *string
|
badMailedMessagesBadPickupFileTotal *prometheus.Desc
|
||||||
serverExclude *string
|
badMailedMessagesGeneralFailureTotal *prometheus.Desc
|
||||||
|
badMailedMessagesHopCountExceededTotal *prometheus.Desc
|
||||||
BadmailedMessagesBadPickupFileTotal *prometheus.Desc
|
badMailedMessagesNDROfDSNTotal *prometheus.Desc
|
||||||
BadmailedMessagesGeneralFailureTotal *prometheus.Desc
|
badMailedMessagesNoRecipientsTotal *prometheus.Desc
|
||||||
BadmailedMessagesHopCountExceededTotal *prometheus.Desc
|
badMailedMessagesTriggeredViaEventTotal *prometheus.Desc
|
||||||
BadmailedMessagesNDROfDSNTotal *prometheus.Desc
|
bytesReceivedTotal *prometheus.Desc
|
||||||
BadmailedMessagesNoRecipientsTotal *prometheus.Desc
|
bytesSentTotal *prometheus.Desc
|
||||||
BadmailedMessagesTriggeredViaEventTotal *prometheus.Desc
|
categorizerQueueLength *prometheus.Desc
|
||||||
BytesSentTotal *prometheus.Desc
|
connectionErrorsTotal *prometheus.Desc
|
||||||
BytesReceivedTotal *prometheus.Desc
|
currentMessagesInLocalDelivery *prometheus.Desc
|
||||||
CategorizerQueueLength *prometheus.Desc
|
dnsQueriesTotal *prometheus.Desc
|
||||||
ConnectionErrorsTotal *prometheus.Desc
|
dsnFailuresTotal *prometheus.Desc
|
||||||
CurrentMessagesInLocalDelivery *prometheus.Desc
|
directoryDropsTotal *prometheus.Desc
|
||||||
DirectoryDropsTotal *prometheus.Desc
|
etrnMessagesTotal *prometheus.Desc
|
||||||
DNSQueriesTotal *prometheus.Desc
|
inboundConnectionsCurrent *prometheus.Desc
|
||||||
DSNFailuresTotal *prometheus.Desc
|
inboundConnectionsTotal *prometheus.Desc
|
||||||
ETRNMessagesTotal *prometheus.Desc
|
localQueueLength *prometheus.Desc
|
||||||
InboundConnectionsCurrent *prometheus.Desc
|
localRetryQueueLength *prometheus.Desc
|
||||||
InboundConnectionsTotal *prometheus.Desc
|
mailFilesOpen *prometheus.Desc
|
||||||
LocalQueueLength *prometheus.Desc
|
messageBytesReceivedTotal *prometheus.Desc
|
||||||
LocalRetryQueueLength *prometheus.Desc
|
messageBytesSentTotal *prometheus.Desc
|
||||||
MailFilesOpen *prometheus.Desc
|
messageDeliveryRetriesTotal *prometheus.Desc
|
||||||
MessageBytesReceivedTotal *prometheus.Desc
|
messageSendRetriesTotal *prometheus.Desc
|
||||||
MessageBytesSentTotal *prometheus.Desc
|
messagesCurrentlyUndeliverable *prometheus.Desc
|
||||||
MessageDeliveryRetriesTotal *prometheus.Desc
|
messagesDeliveredTotal *prometheus.Desc
|
||||||
MessageSendRetriesTotal *prometheus.Desc
|
messagesPendingRouting *prometheus.Desc
|
||||||
MessagesCurrentlyUndeliverable *prometheus.Desc
|
messagesReceivedTotal *prometheus.Desc
|
||||||
MessagesDeliveredTotal *prometheus.Desc
|
messagesRefusedForAddressObjectsTotal *prometheus.Desc
|
||||||
MessagesPendingRouting *prometheus.Desc
|
messagesRefusedForMailObjectsTotal *prometheus.Desc
|
||||||
MessagesReceivedTotal *prometheus.Desc
|
messagesRefusedForSizeTotal *prometheus.Desc
|
||||||
MessagesRefusedForAddressObjectsTotal *prometheus.Desc
|
messagesSentTotal *prometheus.Desc
|
||||||
MessagesRefusedForMailObjectsTotal *prometheus.Desc
|
messagesSubmittedTotal *prometheus.Desc
|
||||||
MessagesRefusedForSizeTotal *prometheus.Desc
|
ndrsGeneratedTotal *prometheus.Desc
|
||||||
MessagesSentTotal *prometheus.Desc
|
outboundConnectionsCurrent *prometheus.Desc
|
||||||
MessagesSubmittedTotal *prometheus.Desc
|
outboundConnectionsRefusedTotal *prometheus.Desc
|
||||||
NDRsGeneratedTotal *prometheus.Desc
|
outboundConnectionsTotal *prometheus.Desc
|
||||||
OutboundConnectionsCurrent *prometheus.Desc
|
pickupDirectoryMessagesRetrievedTotal *prometheus.Desc
|
||||||
OutboundConnectionsRefusedTotal *prometheus.Desc
|
queueFilesOpen *prometheus.Desc
|
||||||
OutboundConnectionsTotal *prometheus.Desc
|
remoteQueueLength *prometheus.Desc
|
||||||
QueueFilesOpen *prometheus.Desc
|
remoteRetryQueueLength *prometheus.Desc
|
||||||
PickupDirectoryMessagesRetrievedTotal *prometheus.Desc
|
routingTableLookupsTotal *prometheus.Desc
|
||||||
RemoteQueueLength *prometheus.Desc
|
|
||||||
RemoteRetryQueueLength *prometheus.Desc
|
|
||||||
RoutingTableLookupsTotal *prometheus.Desc
|
|
||||||
|
|
||||||
serverIncludePattern *regexp.Regexp
|
|
||||||
serverExcludePattern *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.ServerExclude == nil {
|
||||||
serverExclude: &config.ServerExclude,
|
config.ServerExclude = ConfigDefaults.ServerExclude
|
||||||
serverInclude: &config.ServerInclude,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.ServerInclude == nil {
|
||||||
|
config.ServerInclude = ConfigDefaults.ServerInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
c := &collector{
|
c := &Collector{
|
||||||
serverInclude: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagSmtpServerInclude,
|
|
||||||
"Regexp of virtual servers to include. Server name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.ServerInclude).String(),
|
|
||||||
|
|
||||||
serverExclude: app.Flag(
|
|
||||||
FlagSmtpServerExclude,
|
|
||||||
"Regexp of virtual servers to exclude. Server name must both match include and not match exclude to be included.",
|
|
||||||
).Default(ConfigDefaults.ServerExclude).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var serverExclude, serverInclude string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.smtp.server-exclude",
|
||||||
|
"Regexp of virtual servers to exclude. Server name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.ServerExclude.String()).StringVar(&serverExclude)
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.smtp.server-include",
|
||||||
|
"Regexp of virtual servers to include. Server name must both match include and not match exclude to be included.",
|
||||||
|
).Default(c.config.ServerInclude.String()).StringVar(&serverInclude)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
c.config.ServerExclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", serverExclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.smtp.server-exclude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.ServerInclude, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", serverInclude))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("collector.smtp.server-include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"SMTP Server"}, nil
|
return []string{"SMTP Server"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
_ = level.Info(c.logger).Log("msg", "smtp collector is in an experimental state! Metrics for this collector have not been tested.")
|
_ = level.Info(c.logger).Log("msg", "smtp collector is in an experimental state! Metrics for this collector have not been tested.")
|
||||||
|
|
||||||
c.BadmailedMessagesBadPickupFileTotal = prometheus.NewDesc(
|
c.badMailedMessagesBadPickupFileTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_bad_pickup_file_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_bad_pickup_file_total"),
|
||||||
"Total number of malformed pickup messages sent to badmail",
|
"Total number of malformed pickup messages sent to badmail",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BadmailedMessagesGeneralFailureTotal = prometheus.NewDesc(
|
c.badMailedMessagesGeneralFailureTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_general_failure_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_general_failure_total"),
|
||||||
"Total number of messages sent to badmail for reasons not associated with a specific counter",
|
"Total number of messages sent to badmail for reasons not associated with a specific counter",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BadmailedMessagesHopCountExceededTotal = prometheus.NewDesc(
|
c.badMailedMessagesHopCountExceededTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_hop_count_exceeded_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_hop_count_exceeded_total"),
|
||||||
"Total number of messages sent to badmail because they had exceeded the maximum hop count",
|
"Total number of messages sent to badmail because they had exceeded the maximum hop count",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BadmailedMessagesNDROfDSNTotal = prometheus.NewDesc(
|
c.badMailedMessagesNDROfDSNTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_ndr_of_dns_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_ndr_of_dns_total"),
|
||||||
"Total number of Delivery Status Notifications sent to badmail because they could not be delivered",
|
"Total number of Delivery Status Notifications sent to badmail because they could not be delivered",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BadmailedMessagesNoRecipientsTotal = prometheus.NewDesc(
|
c.badMailedMessagesNoRecipientsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_no_recipients_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_no_recipients_total"),
|
||||||
"Total number of messages sent to badmail because they had no recipients",
|
"Total number of messages sent to badmail because they had no recipients",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BadmailedMessagesTriggeredViaEventTotal = prometheus.NewDesc(
|
c.badMailedMessagesTriggeredViaEventTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_triggered_via_event_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_triggered_via_event_total"),
|
||||||
"Total number of messages sent to badmail at the request of a server event sink",
|
"Total number of messages sent to badmail at the request of a server event sink",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesSentTotal = prometheus.NewDesc(
|
c.bytesSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_sent_total"),
|
||||||
"Total number of bytes sent",
|
"Total number of bytes sent",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesReceivedTotal = prometheus.NewDesc(
|
c.bytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
||||||
"Total number of bytes received",
|
"Total number of bytes received",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CategorizerQueueLength = prometheus.NewDesc(
|
c.categorizerQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "categorizer_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "categorizer_queue_length"),
|
||||||
"Number of messages in the categorizer queue",
|
"Number of messages in the categorizer queue",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConnectionErrorsTotal = prometheus.NewDesc(
|
c.connectionErrorsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_errors_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_errors_total"),
|
||||||
"Total number of connection errors",
|
"Total number of connection errors",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CurrentMessagesInLocalDelivery = prometheus.NewDesc(
|
c.currentMessagesInLocalDelivery = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "current_messages_in_local_delivery"),
|
prometheus.BuildFQName(types.Namespace, Name, "current_messages_in_local_delivery"),
|
||||||
"Number of messages that are currently being processed by a server event sink for local delivery",
|
"Number of messages that are currently being processed by a server event sink for local delivery",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DirectoryDropsTotal = prometheus.NewDesc(
|
c.directoryDropsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "directory_drops_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "directory_drops_total"),
|
||||||
"Total number of messages placed in a drop directory",
|
"Total number of messages placed in a drop directory",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DSNFailuresTotal = prometheus.NewDesc(
|
c.dsnFailuresTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dsn_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "dsn_failures_total"),
|
||||||
"Total number of failed DSN generation attempts",
|
"Total number of failed DSN generation attempts",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.DNSQueriesTotal = prometheus.NewDesc(
|
c.dnsQueriesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "dns_queries_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "dns_queries_total"),
|
||||||
"Total number of DNS lookups",
|
"Total number of DNS lookups",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ETRNMessagesTotal = prometheus.NewDesc(
|
c.etrnMessagesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "etrn_messages_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "etrn_messages_total"),
|
||||||
"Total number of ETRN messages received by the server",
|
"Total number of ETRN messages received by the server",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.InboundConnectionsCurrent = prometheus.NewDesc(
|
c.inboundConnectionsCurrent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "inbound_connections_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "inbound_connections_current"),
|
||||||
"Total number of connections currently inbound",
|
"Total number of connections currently inbound",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.InboundConnectionsTotal = prometheus.NewDesc(
|
c.inboundConnectionsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "inbound_connections_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "inbound_connections_total"),
|
||||||
"Total number of inbound connections received",
|
"Total number of inbound connections received",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.LocalQueueLength = prometheus.NewDesc(
|
c.localQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "local_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "local_queue_length"),
|
||||||
"Number of messages in the local queue",
|
"Number of messages in the local queue",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.LocalRetryQueueLength = prometheus.NewDesc(
|
c.localRetryQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "local_retry_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "local_retry_queue_length"),
|
||||||
"Number of messages in the local retry queue",
|
"Number of messages in the local retry queue",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MailFilesOpen = prometheus.NewDesc(
|
c.mailFilesOpen = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mail_files_open"),
|
prometheus.BuildFQName(types.Namespace, Name, "mail_files_open"),
|
||||||
"Number of handles to open mail files",
|
"Number of handles to open mail files",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessageBytesReceivedTotal = prometheus.NewDesc(
|
c.messageBytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "message_bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "message_bytes_received_total"),
|
||||||
"Total number of bytes received in messages",
|
"Total number of bytes received in messages",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessageBytesSentTotal = prometheus.NewDesc(
|
c.messageBytesSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "message_bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "message_bytes_sent_total"),
|
||||||
"Total number of bytes sent in messages",
|
"Total number of bytes sent in messages",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessageDeliveryRetriesTotal = prometheus.NewDesc(
|
c.messageDeliveryRetriesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "message_delivery_retries_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "message_delivery_retries_total"),
|
||||||
"Total number of local deliveries that were retried",
|
"Total number of local deliveries that were retried",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessageSendRetriesTotal = prometheus.NewDesc(
|
c.messageSendRetriesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "message_send_retries_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "message_send_retries_total"),
|
||||||
"Total number of outbound message sends that were retried",
|
"Total number of outbound message sends that were retried",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesCurrentlyUndeliverable = prometheus.NewDesc(
|
c.messagesCurrentlyUndeliverable = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_currently_undeliverable"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_currently_undeliverable"),
|
||||||
"Number of messages that have been reported as currently undeliverable by routing",
|
"Number of messages that have been reported as currently undeliverable by routing",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesDeliveredTotal = prometheus.NewDesc(
|
c.messagesDeliveredTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_delivered_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_delivered_total"),
|
||||||
"Total number of messages delivered to local mailboxes",
|
"Total number of messages delivered to local mailboxes",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesPendingRouting = prometheus.NewDesc(
|
c.messagesPendingRouting = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_pending_routing"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_pending_routing"),
|
||||||
"Number of messages that have been categorized but not routed",
|
"Number of messages that have been categorized but not routed",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesReceivedTotal = prometheus.NewDesc(
|
c.messagesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_received_total"),
|
||||||
"Total number of inbound messages accepted",
|
"Total number of inbound messages accepted",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesRefusedForAddressObjectsTotal = prometheus.NewDesc(
|
c.messagesRefusedForAddressObjectsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_refused_for_address_objects_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_refused_for_address_objects_total"),
|
||||||
"Total number of messages refused due to no address objects",
|
"Total number of messages refused due to no address objects",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesRefusedForMailObjectsTotal = prometheus.NewDesc(
|
c.messagesRefusedForMailObjectsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_refused_for_mail_objects_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_refused_for_mail_objects_total"),
|
||||||
"Total number of messages refused due to no mail objects",
|
"Total number of messages refused due to no mail objects",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesRefusedForSizeTotal = prometheus.NewDesc(
|
c.messagesRefusedForSizeTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_refused_for_size_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_refused_for_size_total"),
|
||||||
"Total number of messages rejected because they were too big",
|
"Total number of messages rejected because they were too big",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesSentTotal = prometheus.NewDesc(
|
c.messagesSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_sent_total"),
|
||||||
"Total number of outbound messages sent",
|
"Total number of outbound messages sent",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MessagesSubmittedTotal = prometheus.NewDesc(
|
c.messagesSubmittedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "messages_submitted_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "messages_submitted_total"),
|
||||||
"Total number of messages submitted to queuing for delivery",
|
"Total number of messages submitted to queuing for delivery",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NDRsGeneratedTotal = prometheus.NewDesc(
|
c.ndrsGeneratedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ndrs_generated_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "ndrs_generated_total"),
|
||||||
"Total number of non-delivery reports that have been generated",
|
"Total number of non-delivery reports that have been generated",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OutboundConnectionsCurrent = prometheus.NewDesc(
|
c.outboundConnectionsCurrent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "outbound_connections_current"),
|
prometheus.BuildFQName(types.Namespace, Name, "outbound_connections_current"),
|
||||||
"Number of connections currently outbound",
|
"Number of connections currently outbound",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OutboundConnectionsRefusedTotal = prometheus.NewDesc(
|
c.outboundConnectionsRefusedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "outbound_connections_refused_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "outbound_connections_refused_total"),
|
||||||
"Total number of connection attempts refused by remote sites",
|
"Total number of connection attempts refused by remote sites",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.OutboundConnectionsTotal = prometheus.NewDesc(
|
c.outboundConnectionsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "outbound_connections_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "outbound_connections_total"),
|
||||||
"Total number of outbound connections attempted",
|
"Total number of outbound connections attempted",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PickupDirectoryMessagesRetrievedTotal = prometheus.NewDesc(
|
c.pickupDirectoryMessagesRetrievedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pickup_directory_messages_retrieved_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "pickup_directory_messages_retrieved_total"),
|
||||||
"Total number of messages retrieved from the mail pick-up directory",
|
"Total number of messages retrieved from the mail pick-up directory",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.QueueFilesOpen = prometheus.NewDesc(
|
c.queueFilesOpen = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "queue_files_open"),
|
prometheus.BuildFQName(types.Namespace, Name, "queue_files_open"),
|
||||||
"Number of handles to open queue files",
|
"Number of handles to open queue files",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RemoteQueueLength = prometheus.NewDesc(
|
c.remoteQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "remote_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "remote_queue_length"),
|
||||||
"Number of messages in the remote queue",
|
"Number of messages in the remote queue",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RemoteRetryQueueLength = prometheus.NewDesc(
|
c.remoteRetryQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "remote_retry_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "remote_retry_queue_length"),
|
||||||
"Number of messages in the retry queue for remote delivery",
|
"Number of messages in the retry queue for remote delivery",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RoutingTableLookupsTotal = prometheus.NewDesc(
|
c.routingTableLookupsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "routing_table_lookups_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "routing_table_lookups_total"),
|
||||||
"Total number of routing table lookups",
|
"Total number of routing table lookups",
|
||||||
[]string{"site"},
|
[]string{"site"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
c.serverIncludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.serverInclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.serverExcludePattern, err = regexp.Compile(fmt.Sprintf("^(?:%s)$", *c.serverExclude))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting smtp metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting smtp metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -406,7 +417,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerflibSMTPServer Perflib: "SMTP Server"
|
// PerflibSMTPServer Perflib: "SMTP Server".
|
||||||
type PerflibSMTPServer struct {
|
type PerflibSMTPServer struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
@@ -454,7 +465,7 @@ type PerflibSMTPServer struct {
|
|||||||
RoutingTableLookupsTotal float64 `perflib:"Routing Table Lookups Total"`
|
RoutingTableLookupsTotal float64 `perflib:"Routing Table Lookups Total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []PerflibSMTPServer
|
var dst []PerflibSMTPServer
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMTP Server"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMTP Server"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -462,298 +473,297 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
|
|
||||||
for _, server := range dst {
|
for _, server := range dst {
|
||||||
if server.Name == "_Total" ||
|
if server.Name == "_Total" ||
|
||||||
c.serverExcludePattern.MatchString(server.Name) ||
|
c.config.ServerExclude.MatchString(server.Name) ||
|
||||||
!c.serverIncludePattern.MatchString(server.Name) {
|
!c.config.ServerInclude.MatchString(server.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BadmailedMessagesBadPickupFileTotal,
|
c.badMailedMessagesBadPickupFileTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BadmailedMessagesBadPickupFileTotal,
|
server.BadmailedMessagesBadPickupFileTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BadmailedMessagesHopCountExceededTotal,
|
c.badMailedMessagesHopCountExceededTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BadmailedMessagesHopCountExceededTotal,
|
server.BadmailedMessagesHopCountExceededTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BadmailedMessagesNDROfDSNTotal,
|
c.badMailedMessagesNDROfDSNTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BadmailedMessagesNDROfDSNTotal,
|
server.BadmailedMessagesNDROfDSNTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BadmailedMessagesNoRecipientsTotal,
|
c.badMailedMessagesNoRecipientsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BadmailedMessagesNoRecipientsTotal,
|
server.BadmailedMessagesNoRecipientsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BadmailedMessagesTriggeredViaEventTotal,
|
c.badMailedMessagesTriggeredViaEventTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BadmailedMessagesTriggeredViaEventTotal,
|
server.BadmailedMessagesTriggeredViaEventTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesSentTotal,
|
c.bytesSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BytesSentTotal,
|
server.BytesSentTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesReceivedTotal,
|
c.bytesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.BytesReceivedTotal,
|
server.BytesReceivedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CategorizerQueueLength,
|
c.categorizerQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.CategorizerQueueLength,
|
server.CategorizerQueueLength,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionErrorsTotal,
|
c.connectionErrorsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.ConnectionErrorsTotal,
|
server.ConnectionErrorsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CurrentMessagesInLocalDelivery,
|
c.currentMessagesInLocalDelivery,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.CurrentMessagesInLocalDelivery,
|
server.CurrentMessagesInLocalDelivery,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DirectoryDropsTotal,
|
c.directoryDropsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.DirectoryDropsTotal,
|
server.DirectoryDropsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DSNFailuresTotal,
|
c.dsnFailuresTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.DSNFailuresTotal,
|
server.DSNFailuresTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.DNSQueriesTotal,
|
c.dnsQueriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.DNSQueriesTotal,
|
server.DNSQueriesTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ETRNMessagesTotal,
|
c.etrnMessagesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.ETRNMessagesTotal,
|
server.ETRNMessagesTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InboundConnectionsTotal,
|
c.inboundConnectionsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.InboundConnectionsTotal,
|
server.InboundConnectionsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.InboundConnectionsCurrent,
|
c.inboundConnectionsCurrent,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.InboundConnectionsCurrent,
|
server.InboundConnectionsCurrent,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LocalQueueLength,
|
c.localQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.LocalQueueLength,
|
server.LocalQueueLength,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.LocalRetryQueueLength,
|
c.localRetryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.LocalRetryQueueLength,
|
server.LocalRetryQueueLength,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MailFilesOpen,
|
c.mailFilesOpen,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.MailFilesOpen,
|
server.MailFilesOpen,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessageBytesReceivedTotal,
|
c.messageBytesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessageBytesReceivedTotal,
|
server.MessageBytesReceivedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessageBytesSentTotal,
|
c.messageBytesSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessageBytesSentTotal,
|
server.MessageBytesSentTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessageDeliveryRetriesTotal,
|
c.messageDeliveryRetriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessageDeliveryRetriesTotal,
|
server.MessageDeliveryRetriesTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessageSendRetriesTotal,
|
c.messageSendRetriesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessageSendRetriesTotal,
|
server.MessageSendRetriesTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesCurrentlyUndeliverable,
|
c.messagesCurrentlyUndeliverable,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.MessagesCurrentlyUndeliverable,
|
server.MessagesCurrentlyUndeliverable,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesDeliveredTotal,
|
c.messagesDeliveredTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesDeliveredTotal,
|
server.MessagesDeliveredTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesPendingRouting,
|
c.messagesPendingRouting,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.MessagesPendingRouting,
|
server.MessagesPendingRouting,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesReceivedTotal,
|
c.messagesReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesReceivedTotal,
|
server.MessagesReceivedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesRefusedForAddressObjectsTotal,
|
c.messagesRefusedForAddressObjectsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesRefusedForAddressObjectsTotal,
|
server.MessagesRefusedForAddressObjectsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesRefusedForMailObjectsTotal,
|
c.messagesRefusedForMailObjectsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesRefusedForMailObjectsTotal,
|
server.MessagesRefusedForMailObjectsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesRefusedForSizeTotal,
|
c.messagesRefusedForSizeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesRefusedForSizeTotal,
|
server.MessagesRefusedForSizeTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesSentTotal,
|
c.messagesSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesSentTotal,
|
server.MessagesSentTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MessagesSubmittedTotal,
|
c.messagesSubmittedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.MessagesSubmittedTotal,
|
server.MessagesSubmittedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NDRsGeneratedTotal,
|
c.ndrsGeneratedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.NDRsGeneratedTotal,
|
server.NDRsGeneratedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OutboundConnectionsCurrent,
|
c.outboundConnectionsCurrent,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.OutboundConnectionsCurrent,
|
server.OutboundConnectionsCurrent,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OutboundConnectionsRefusedTotal,
|
c.outboundConnectionsRefusedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.OutboundConnectionsRefusedTotal,
|
server.OutboundConnectionsRefusedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.OutboundConnectionsTotal,
|
c.outboundConnectionsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.OutboundConnectionsTotal,
|
server.OutboundConnectionsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.QueueFilesOpen,
|
c.queueFilesOpen,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.QueueFilesOpen,
|
server.QueueFilesOpen,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PickupDirectoryMessagesRetrievedTotal,
|
c.pickupDirectoryMessagesRetrievedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.PickupDirectoryMessagesRetrievedTotal,
|
server.PickupDirectoryMessagesRetrievedTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RemoteQueueLength,
|
c.remoteQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.RemoteQueueLength,
|
server.RemoteQueueLength,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RemoteRetryQueueLength,
|
c.remoteRetryQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
server.RemoteRetryQueueLength,
|
server.RemoteRetryQueueLength,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RoutingTableLookupsTotal,
|
c.routingTableLookupsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
server.RoutingTableLookupsTotal,
|
server.RoutingTableLookupsTotal,
|
||||||
server.Name,
|
server.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,72 +17,85 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI metrics
|
// A Collector is a Prometheus Collector for WMI metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
ContextSwitchesTotal *prometheus.Desc
|
contextSwitchesTotal *prometheus.Desc
|
||||||
ExceptionDispatchesTotal *prometheus.Desc
|
exceptionDispatchesTotal *prometheus.Desc
|
||||||
ProcessorQueueLength *prometheus.Desc
|
processorQueueLength *prometheus.Desc
|
||||||
SystemCallsTotal *prometheus.Desc
|
systemCallsTotal *prometheus.Desc
|
||||||
SystemUpTime *prometheus.Desc
|
systemUpTime *prometheus.Desc
|
||||||
Threads *prometheus.Desc
|
threads *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"System"}, nil
|
return []string{"System"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.ContextSwitchesTotal = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.contextSwitchesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
||||||
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ExceptionDispatchesTotal = prometheus.NewDesc(
|
c.exceptionDispatchesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "exception_dispatches_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "exception_dispatches_total"),
|
||||||
"Total number of exceptions dispatched (WMI source: PerfOS_System.ExceptionDispatchesPersec)",
|
"Total number of exceptions dispatched (WMI source: PerfOS_System.ExceptionDispatchesPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ProcessorQueueLength = prometheus.NewDesc(
|
c.processorQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "processor_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "processor_queue_length"),
|
||||||
"Length of processor queue (WMI source: PerfOS_System.ProcessorQueueLength)",
|
"Length of processor queue (WMI source: PerfOS_System.ProcessorQueueLength)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemCallsTotal = prometheus.NewDesc(
|
c.systemCallsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_calls_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_calls_total"),
|
||||||
"Total number of system calls (WMI source: PerfOS_System.SystemCallsPersec)",
|
"Total number of system calls (WMI source: PerfOS_System.SystemCallsPersec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SystemUpTime = prometheus.NewDesc(
|
c.systemUpTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "system_up_time"),
|
prometheus.BuildFQName(types.Namespace, Name, "system_up_time"),
|
||||||
"System boot time (WMI source: PerfOS_System.SystemUpTime)",
|
"System boot time (WMI source: PerfOS_System.SystemUpTime)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.Threads = prometheus.NewDesc(
|
c.threads = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "threads"),
|
prometheus.BuildFQName(types.Namespace, Name, "threads"),
|
||||||
"Current number of threads (WMI source: PerfOS_System.Threads)",
|
"Current number of threads (WMI source: PerfOS_System.Threads)",
|
||||||
nil,
|
nil,
|
||||||
@@ -93,7 +106,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting system metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting system metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -112,39 +125,39 @@ type system struct {
|
|||||||
Threads float64 `perflib:"Threads"`
|
Threads float64 `perflib:"Threads"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []system
|
var dst []system
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["System"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["System"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContextSwitchesTotal,
|
c.contextSwitchesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ContextSwitchesPersec,
|
dst[0].ContextSwitchesPersec,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ExceptionDispatchesTotal,
|
c.exceptionDispatchesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ExceptionDispatchesPersec,
|
dst[0].ExceptionDispatchesPersec,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ProcessorQueueLength,
|
c.processorQueueLength,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].ProcessorQueueLength,
|
dst[0].ProcessorQueueLength,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemCallsTotal,
|
c.systemCallsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].SystemCallsPersec,
|
dst[0].SystemCallsPersec,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemUpTime,
|
c.systemUpTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].SystemUpTime,
|
dst[0].SystemUpTime,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Threads,
|
c.threads,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].Threads,
|
dst[0].Threads,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,93 +17,106 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Tcpip_TCPv{4,6} metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
ConnectionFailures *prometheus.Desc
|
connectionFailures *prometheus.Desc
|
||||||
ConnectionsActive *prometheus.Desc
|
connectionsActive *prometheus.Desc
|
||||||
ConnectionsEstablished *prometheus.Desc
|
connectionsEstablished *prometheus.Desc
|
||||||
ConnectionsPassive *prometheus.Desc
|
connectionsPassive *prometheus.Desc
|
||||||
ConnectionsReset *prometheus.Desc
|
connectionsReset *prometheus.Desc
|
||||||
SegmentsTotal *prometheus.Desc
|
segmentsTotal *prometheus.Desc
|
||||||
SegmentsReceivedTotal *prometheus.Desc
|
segmentsReceivedTotal *prometheus.Desc
|
||||||
SegmentsRetransmittedTotal *prometheus.Desc
|
segmentsRetransmittedTotal *prometheus.Desc
|
||||||
SegmentsSentTotal *prometheus.Desc
|
segmentsSentTotal *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"TCPv4"}, nil
|
return []string{"TCPv4"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.ConnectionFailures = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.connectionFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_failures_total"),
|
||||||
"(TCP.ConnectionFailures)",
|
"(TCP.ConnectionFailures)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConnectionsActive = prometheus.NewDesc(
|
c.connectionsActive = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connections_active_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connections_active_total"),
|
||||||
"(TCP.ConnectionsActive)",
|
"(TCP.ConnectionsActive)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConnectionsEstablished = prometheus.NewDesc(
|
c.connectionsEstablished = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connections_established"),
|
prometheus.BuildFQName(types.Namespace, Name, "connections_established"),
|
||||||
"(TCP.ConnectionsEstablished)",
|
"(TCP.ConnectionsEstablished)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConnectionsPassive = prometheus.NewDesc(
|
c.connectionsPassive = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connections_passive_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connections_passive_total"),
|
||||||
"(TCP.ConnectionsPassive)",
|
"(TCP.ConnectionsPassive)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConnectionsReset = prometheus.NewDesc(
|
c.connectionsReset = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connections_reset_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connections_reset_total"),
|
||||||
"(TCP.ConnectionsReset)",
|
"(TCP.ConnectionsReset)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SegmentsTotal = prometheus.NewDesc(
|
c.segmentsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "segments_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "segments_total"),
|
||||||
"(TCP.SegmentsTotal)",
|
"(TCP.SegmentsTotal)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SegmentsReceivedTotal = prometheus.NewDesc(
|
c.segmentsReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "segments_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "segments_received_total"),
|
||||||
"(TCP.SegmentsReceivedTotal)",
|
"(TCP.SegmentsReceivedTotal)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SegmentsRetransmittedTotal = prometheus.NewDesc(
|
c.segmentsRetransmittedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "segments_retransmitted_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "segments_retransmitted_total"),
|
||||||
"(TCP.SegmentsRetransmittedTotal)",
|
"(TCP.SegmentsRetransmittedTotal)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SegmentsSentTotal = prometheus.NewDesc(
|
c.segmentsSentTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "segments_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "segments_sent_total"),
|
||||||
"(TCP.SegmentsSentTotal)",
|
"(TCP.SegmentsSentTotal)",
|
||||||
[]string{"af"},
|
[]string{"af"},
|
||||||
@@ -114,7 +127,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting tcp metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting tcp metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -137,64 +150,64 @@ type tcp struct {
|
|||||||
SegmentsSentPersec float64 `perflib:"Segments Sent/sec"`
|
SegmentsSentPersec float64 `perflib:"Segments Sent/sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTCPCounters(metrics tcp, labels []string, c *collector, ch chan<- prometheus.Metric) {
|
func writeTCPCounters(metrics tcp, labels []string, c *Collector, ch chan<- prometheus.Metric) {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionFailures,
|
c.connectionFailures,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.ConnectionFailures,
|
metrics.ConnectionFailures,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsActive,
|
c.connectionsActive,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.ConnectionsActive,
|
metrics.ConnectionsActive,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsEstablished,
|
c.connectionsEstablished,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
metrics.ConnectionsEstablished,
|
metrics.ConnectionsEstablished,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsPassive,
|
c.connectionsPassive,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.ConnectionsPassive,
|
metrics.ConnectionsPassive,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionsReset,
|
c.connectionsReset,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.ConnectionsReset,
|
metrics.ConnectionsReset,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsTotal,
|
c.segmentsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.SegmentsPersec,
|
metrics.SegmentsPersec,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsReceivedTotal,
|
c.segmentsReceivedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.SegmentsReceivedPersec,
|
metrics.SegmentsReceivedPersec,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsRetransmittedTotal,
|
c.segmentsRetransmittedTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.SegmentsRetransmittedPersec,
|
metrics.SegmentsRetransmittedPersec,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SegmentsSentTotal,
|
c.segmentsSentTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
metrics.SegmentsSentPersec,
|
metrics.SegmentsSentPersec,
|
||||||
labels...,
|
labels...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []tcp
|
var dst []tcp
|
||||||
|
|
||||||
// TCPv4 counters
|
// TCPv4 counters
|
||||||
|
|||||||
@@ -19,218 +19,233 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// collector is a Prometheus collector for WMI metrics:
|
// Collector is a Prometheus Collector for WMI metrics:
|
||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics
|
||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
|
||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
|
||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
AudioBytesReceived *prometheus.Desc
|
audioBytesReceived *prometheus.Desc
|
||||||
AudioBytesSent *prometheus.Desc
|
audioBytesSent *prometheus.Desc
|
||||||
AudioRXBWkbitPersec *prometheus.Desc
|
audioRXBWKBitPerSec *prometheus.Desc
|
||||||
AudioTXBWkbitPersec *prometheus.Desc
|
audioTXBWKBitPerSec *prometheus.Desc
|
||||||
AudioTXBWLimitkbitPersec *prometheus.Desc
|
audioTXBWLimitKBitPerSec *prometheus.Desc
|
||||||
|
|
||||||
BytesReceived *prometheus.Desc
|
bytesReceived *prometheus.Desc
|
||||||
BytesSent *prometheus.Desc
|
bytesSent *prometheus.Desc
|
||||||
PacketsReceived *prometheus.Desc
|
packetsReceived *prometheus.Desc
|
||||||
PacketsSent *prometheus.Desc
|
packetsSent *prometheus.Desc
|
||||||
RXPacketsLost *prometheus.Desc
|
rxPacketsLost *prometheus.Desc
|
||||||
SessionDurationSeconds *prometheus.Desc
|
sessionDurationSeconds *prometheus.Desc
|
||||||
TXPacketsLost *prometheus.Desc
|
txPacketsLost *prometheus.Desc
|
||||||
|
|
||||||
ImagingActiveMinimumQuality *prometheus.Desc
|
imagingActiveMinimumQuality *prometheus.Desc
|
||||||
ImagingApex2800Offload *prometheus.Desc
|
imagingApex2800Offload *prometheus.Desc
|
||||||
ImagingBytesReceived *prometheus.Desc
|
imagingBytesReceived *prometheus.Desc
|
||||||
ImagingBytesSent *prometheus.Desc
|
imagingBytesSent *prometheus.Desc
|
||||||
ImagingDecoderCapabilitykbitPersec *prometheus.Desc
|
imagingDecoderCapabilityKBitPerSec *prometheus.Desc
|
||||||
ImagingEncodedFramesPersec *prometheus.Desc
|
imagingEncodedFramesPerSec *prometheus.Desc
|
||||||
ImagingMegapixelPersec *prometheus.Desc
|
imagingMegapixelPerSec *prometheus.Desc
|
||||||
ImagingNegativeAcknowledgements *prometheus.Desc
|
imagingNegativeAcknowledgements *prometheus.Desc
|
||||||
ImagingRXBWkbitPersec *prometheus.Desc
|
imagingRXBWKBitPerSec *prometheus.Desc
|
||||||
ImagingSVGAdevTapframesPersec *prometheus.Desc
|
imagingSVGAdevTapframesPerSec *prometheus.Desc
|
||||||
ImagingTXBWkbitPersec *prometheus.Desc
|
imagingTXBWKBitPerSec *prometheus.Desc
|
||||||
|
|
||||||
RoundTripLatencyms *prometheus.Desc
|
RoundTripLatencyms *prometheus.Desc
|
||||||
RXBWkbitPersec *prometheus.Desc
|
rxBWKBitPerSec *prometheus.Desc
|
||||||
RXBWPeakkbitPersec *prometheus.Desc
|
rxBWPeakKBitPerSec *prometheus.Desc
|
||||||
RXPacketLossPercent *prometheus.Desc
|
rxPacketLossPercent *prometheus.Desc
|
||||||
RXPacketLossPercent_Base *prometheus.Desc
|
rxPacketLossPercentBase *prometheus.Desc
|
||||||
TXBWActiveLimitkbitPersec *prometheus.Desc
|
txBWActiveLimitKBitPerSec *prometheus.Desc
|
||||||
TXBWkbitPersec *prometheus.Desc
|
txBWKBitPerSec *prometheus.Desc
|
||||||
TXBWLimitkbitPersec *prometheus.Desc
|
txBWLimitKBitPerSec *prometheus.Desc
|
||||||
TXPacketLossPercent *prometheus.Desc
|
txPacketLossPercent *prometheus.Desc
|
||||||
TXPacketLossPercent_Base *prometheus.Desc
|
txPacketLossPercentBase *prometheus.Desc
|
||||||
|
|
||||||
USBBytesReceived *prometheus.Desc
|
usbBytesReceived *prometheus.Desc
|
||||||
USBBytesSent *prometheus.Desc
|
usbBytesSent *prometheus.Desc
|
||||||
USBRXBWkbitPersec *prometheus.Desc
|
usbRXBWKBitPerSec *prometheus.Desc
|
||||||
USBTXBWkbitPersec *prometheus.Desc
|
usbTXBWKBitPerSec *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.AudioBytesReceived = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
_ = level.Warn(c.logger).Log("msg", "teradici_pcoip collector is deprecated and will be removed in the future.")
|
||||||
|
|
||||||
|
c.audioBytesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_bytes_received_total"),
|
||||||
"(AudioBytesReceived)",
|
"(AudioBytesReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AudioBytesSent = prometheus.NewDesc(
|
c.audioBytesSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_bytes_sent_total"),
|
||||||
"(AudioBytesSent)",
|
"(AudioBytesSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AudioRXBWkbitPersec = prometheus.NewDesc(
|
c.audioRXBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_rx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_rx_bw_KBit_persec"),
|
||||||
"(AudioRXBWkbitPersec)",
|
"(AudioRXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AudioTXBWkbitPersec = prometheus.NewDesc(
|
c.audioTXBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_tx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_tx_bw_KBit_persec"),
|
||||||
"(AudioTXBWkbitPersec)",
|
"(AudioTXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.AudioTXBWLimitkbitPersec = prometheus.NewDesc(
|
c.audioTXBWLimitKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_tx_bw_limit_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_tx_bw_limit_KBit_persec"),
|
||||||
"(AudioTXBWLimitkbitPersec)",
|
"(AudioTXBWLimitKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.BytesReceived = prometheus.NewDesc(
|
c.bytesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
||||||
"(BytesReceived)",
|
"(BytesReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.BytesSent = prometheus.NewDesc(
|
c.bytesSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_sent_total"),
|
||||||
"(BytesSent)",
|
"(BytesSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsReceived = prometheus.NewDesc(
|
c.packetsReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
||||||
"(PacketsReceived)",
|
"(PacketsReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PacketsSent = prometheus.NewDesc(
|
c.packetsSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_sent_total"),
|
||||||
"(PacketsSent)",
|
"(PacketsSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RXPacketsLost = prometheus.NewDesc(
|
c.rxPacketsLost = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "rx_packets_lost_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "rx_packets_lost_total"),
|
||||||
"(RXPacketsLost)",
|
"(RXPacketsLost)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.SessionDurationSeconds = prometheus.NewDesc(
|
c.sessionDurationSeconds = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "session_duration_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "session_duration_seconds_total"),
|
||||||
"(SessionDurationSeconds)",
|
"(SessionDurationSeconds)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TXPacketsLost = prometheus.NewDesc(
|
c.txPacketsLost = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "tx_packets_lost_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "tx_packets_lost_total"),
|
||||||
"(TXPacketsLost)",
|
"(TXPacketsLost)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.ImagingActiveMinimumQuality = prometheus.NewDesc(
|
c.imagingActiveMinimumQuality = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_active_min_quality"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_active_min_quality"),
|
||||||
"(ImagingActiveMinimumQuality)",
|
"(ImagingActiveMinimumQuality)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingApex2800Offload = prometheus.NewDesc(
|
c.imagingApex2800Offload = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_apex2800_offload"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_apex2800_offload"),
|
||||||
"(ImagingApex2800Offload)",
|
"(ImagingApex2800Offload)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingBytesReceived = prometheus.NewDesc(
|
c.imagingBytesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_bytes_received_total"),
|
||||||
"(ImagingBytesReceived)",
|
"(ImagingBytesReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingBytesSent = prometheus.NewDesc(
|
c.imagingBytesSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_bytes_sent_total"),
|
||||||
"(ImagingBytesSent)",
|
"(ImagingBytesSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingDecoderCapabilitykbitPersec = prometheus.NewDesc(
|
c.imagingDecoderCapabilityKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_decoder_capability_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_decoder_capability_KBit_persec"),
|
||||||
"(ImagingDecoderCapabilitykbitPersec)",
|
"(ImagingDecoderCapabilityKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingEncodedFramesPersec = prometheus.NewDesc(
|
c.imagingEncodedFramesPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_encoded_frames_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_encoded_frames_persec"),
|
||||||
"(ImagingEncodedFramesPersec)",
|
"(ImagingEncodedFramesPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingMegapixelPersec = prometheus.NewDesc(
|
c.imagingMegapixelPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_megapixel_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_megapixel_persec"),
|
||||||
"(ImagingMegapixelPersec)",
|
"(ImagingMegapixelPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingNegativeAcknowledgements = prometheus.NewDesc(
|
c.imagingNegativeAcknowledgements = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_negative_acks_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_negative_acks_total"),
|
||||||
"(ImagingNegativeAcknowledgements)",
|
"(ImagingNegativeAcknowledgements)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingRXBWkbitPersec = prometheus.NewDesc(
|
c.imagingRXBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_rx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_rx_bw_KBit_persec"),
|
||||||
"(ImagingRXBWkbitPersec)",
|
"(ImagingRXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingSVGAdevTapframesPersec = prometheus.NewDesc(
|
c.imagingSVGAdevTapframesPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_svga_devtap_frames_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_svga_devtap_frames_persec"),
|
||||||
"(ImagingSVGAdevTapframesPersec)",
|
"(ImagingSVGAdevTapframesPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ImagingTXBWkbitPersec = prometheus.NewDesc(
|
c.imagingTXBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "imaging_tx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "imaging_tx_bw_KBit_persec"),
|
||||||
"(ImagingTXBWkbitPersec)",
|
"(ImagingTXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
@@ -241,82 +256,82 @@ func (c *collector) Build() error {
|
|||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RXBWkbitPersec = prometheus.NewDesc(
|
c.rxBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "rx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "rx_bw_KBit_persec"),
|
||||||
"(RXBWkbitPersec)",
|
"(RXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RXBWPeakkbitPersec = prometheus.NewDesc(
|
c.rxBWPeakKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "rx_bw_peak_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "rx_bw_peak_KBit_persec"),
|
||||||
"(RXBWPeakkbitPersec)",
|
"(RXBWPeakKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RXPacketLossPercent = prometheus.NewDesc(
|
c.rxPacketLossPercent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "rx_packet_loss_percent"),
|
prometheus.BuildFQName(types.Namespace, Name, "rx_packet_loss_percent"),
|
||||||
"(RXPacketLossPercent)",
|
"(RXPacketLossPercent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.RXPacketLossPercent_Base = prometheus.NewDesc(
|
c.rxPacketLossPercentBase = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "rx_packet_loss_percent_base"),
|
prometheus.BuildFQName(types.Namespace, Name, "rx_packet_loss_percent_base"),
|
||||||
"(RXPacketLossPercent_Base)",
|
"(RXPacketLossPercent_Base)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TXBWActiveLimitkbitPersec = prometheus.NewDesc(
|
c.txBWActiveLimitKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "tx_bw_active_limit_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "tx_bw_active_limit_KBit_persec"),
|
||||||
"(TXBWActiveLimitkbitPersec)",
|
"(TXBWActiveLimitKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TXBWkbitPersec = prometheus.NewDesc(
|
c.txBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "tx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "tx_bw_KBit_persec"),
|
||||||
"(TXBWkbitPersec)",
|
"(TXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TXBWLimitkbitPersec = prometheus.NewDesc(
|
c.txBWLimitKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "tx_bw_limit_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "tx_bw_limit_KBit_persec"),
|
||||||
"(TXBWLimitkbitPersec)",
|
"(TXBWLimitKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TXPacketLossPercent = prometheus.NewDesc(
|
c.txPacketLossPercent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "tx_packet_loss_percent"),
|
prometheus.BuildFQName(types.Namespace, Name, "tx_packet_loss_percent"),
|
||||||
"(TXPacketLossPercent)",
|
"(TXPacketLossPercent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.TXPacketLossPercent_Base = prometheus.NewDesc(
|
c.txPacketLossPercentBase = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "tx_packet_loss_percent_base"),
|
prometheus.BuildFQName(types.Namespace, Name, "tx_packet_loss_percent_base"),
|
||||||
"(TXPacketLossPercent_Base)",
|
"(TXPacketLossPercent_Base)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.USBBytesReceived = prometheus.NewDesc(
|
c.usbBytesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "usb_bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "usb_bytes_received_total"),
|
||||||
"(USBBytesReceived)",
|
"(USBBytesReceived)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.USBBytesSent = prometheus.NewDesc(
|
c.usbBytesSent = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "usb_bytes_sent_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "usb_bytes_sent_total"),
|
||||||
"(USBBytesSent)",
|
"(USBBytesSent)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.USBRXBWkbitPersec = prometheus.NewDesc(
|
c.usbRXBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "usb_rx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "usb_rx_bw_KBit_persec"),
|
||||||
"(USBRXBWkbitPersec)",
|
"(USBRXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.USBTXBWkbitPersec = prometheus.NewDesc(
|
c.usbTXBWKBitPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "usb_tx_bw_kbit_persec"),
|
prometheus.BuildFQName(types.Namespace, Name, "usb_tx_bw_KBit_persec"),
|
||||||
"(USBTXBWkbitPersec)",
|
"(USBTXBWKBitPerSec)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
@@ -325,7 +340,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collectAudio(ch); err != nil {
|
if err := c.collectAudio(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting teradici session audio metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting teradici session audio metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -352,9 +367,9 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
type win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics struct {
|
type win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics struct {
|
||||||
AudioBytesReceived uint64
|
AudioBytesReceived uint64
|
||||||
AudioBytesSent uint64
|
AudioBytesSent uint64
|
||||||
AudioRXBWkbitPersec uint64
|
AudioRXBWKBitPerSec uint64
|
||||||
AudioTXBWkbitPersec uint64
|
AudioTXBWKBitPerSec uint64
|
||||||
AudioTXBWLimitkbitPersec uint64
|
AudioTXBWLimitKBitPerSec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics struct {
|
type win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics struct {
|
||||||
@@ -372,36 +387,36 @@ type win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics struct {
|
|||||||
ImagingApex2800Offload uint32
|
ImagingApex2800Offload uint32
|
||||||
ImagingBytesReceived uint64
|
ImagingBytesReceived uint64
|
||||||
ImagingBytesSent uint64
|
ImagingBytesSent uint64
|
||||||
ImagingDecoderCapabilitykbitPersec uint32
|
ImagingDecoderCapabilityKBitPerSec uint32
|
||||||
ImagingEncodedFramesPersec uint32
|
ImagingEncodedFramesPerSec uint32
|
||||||
ImagingMegapixelPersec uint32
|
ImagingMegapixelPerSec uint32
|
||||||
ImagingNegativeAcknowledgements uint32
|
ImagingNegativeAcknowledgements uint32
|
||||||
ImagingRXBWkbitPersec uint64
|
ImagingRXBWKBitPerSec uint64
|
||||||
ImagingSVGAdevTapframesPersec uint32
|
ImagingSVGAdevTapframesPerSec uint32
|
||||||
ImagingTXBWkbitPersec uint64
|
ImagingTXBWKBitPerSec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics struct {
|
type win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics struct {
|
||||||
RoundTripLatencyms uint32
|
RoundTripLatencyms uint32
|
||||||
RXBWkbitPersec uint64
|
RXBWKBitPerSec uint64
|
||||||
RXBWPeakkbitPersec uint32
|
RXBWPeakKBitPerSec uint32
|
||||||
RXPacketLossPercent uint32
|
RXPacketLossPercent uint32
|
||||||
RXPacketLossPercent_Base uint32
|
RXPacketLossPercentBase uint32
|
||||||
TXBWActiveLimitkbitPersec uint32
|
TXBWActiveLimitKBitPerSec uint32
|
||||||
TXBWkbitPersec uint64
|
TXBWKBitPerSec uint64
|
||||||
TXBWLimitkbitPersec uint32
|
TXBWLimitKBitPerSec uint32
|
||||||
TXPacketLossPercent uint32
|
TXPacketLossPercent uint32
|
||||||
TXPacketLossPercent_Base uint32
|
TXPacketLossPercentBase uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics struct {
|
type win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics struct {
|
||||||
USBBytesReceived uint64
|
USBBytesReceived uint64
|
||||||
USBBytesSent uint64
|
USBBytesSent uint64
|
||||||
USBRXBWkbitPersec uint64
|
USBRXBWKBitPerSec uint64
|
||||||
USBTXBWkbitPersec uint64
|
USBTXBWKBitPerSec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectAudio(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAudio(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -412,39 +427,39 @@ func (c *collector) collectAudio(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AudioBytesReceived,
|
c.audioBytesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AudioBytesReceived),
|
float64(dst[0].AudioBytesReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AudioBytesSent,
|
c.audioBytesSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].AudioBytesSent),
|
float64(dst[0].AudioBytesSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AudioRXBWkbitPersec,
|
c.audioRXBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].AudioRXBWkbitPersec),
|
float64(dst[0].AudioRXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AudioTXBWkbitPersec,
|
c.audioTXBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].AudioTXBWkbitPersec),
|
float64(dst[0].AudioTXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.AudioTXBWLimitkbitPersec,
|
c.audioTXBWLimitKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].AudioTXBWLimitkbitPersec),
|
float64(dst[0].AudioTXBWLimitKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectGeneral(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectGeneral(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -455,43 +470,43 @@ func (c *collector) collectGeneral(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesReceived,
|
c.bytesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].BytesReceived),
|
float64(dst[0].BytesReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.BytesSent,
|
c.bytesSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].BytesSent),
|
float64(dst[0].BytesSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsReceived,
|
c.packetsReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].PacketsReceived),
|
float64(dst[0].PacketsReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PacketsSent,
|
c.packetsSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].PacketsSent),
|
float64(dst[0].PacketsSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RXPacketsLost,
|
c.rxPacketsLost,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].RXPacketsLost),
|
float64(dst[0].RXPacketsLost),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SessionDurationSeconds,
|
c.sessionDurationSeconds,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].SessionDurationSeconds),
|
float64(dst[0].SessionDurationSeconds),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TXPacketsLost,
|
c.txPacketsLost,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].TXPacketsLost),
|
float64(dst[0].TXPacketsLost),
|
||||||
)
|
)
|
||||||
@@ -499,7 +514,7 @@ func (c *collector) collectGeneral(ch chan<- prometheus.Metric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectImaging(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectImaging(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -510,75 +525,75 @@ func (c *collector) collectImaging(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingActiveMinimumQuality,
|
c.imagingActiveMinimumQuality,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingActiveMinimumQuality),
|
float64(dst[0].ImagingActiveMinimumQuality),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingApex2800Offload,
|
c.imagingApex2800Offload,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingApex2800Offload),
|
float64(dst[0].ImagingApex2800Offload),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingBytesReceived,
|
c.imagingBytesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ImagingBytesReceived),
|
float64(dst[0].ImagingBytesReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingBytesSent,
|
c.imagingBytesSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ImagingBytesSent),
|
float64(dst[0].ImagingBytesSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingDecoderCapabilitykbitPersec,
|
c.imagingDecoderCapabilityKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingDecoderCapabilitykbitPersec),
|
float64(dst[0].ImagingDecoderCapabilityKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingEncodedFramesPersec,
|
c.imagingEncodedFramesPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingEncodedFramesPersec),
|
float64(dst[0].ImagingEncodedFramesPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingMegapixelPersec,
|
c.imagingMegapixelPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingMegapixelPersec),
|
float64(dst[0].ImagingMegapixelPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingNegativeAcknowledgements,
|
c.imagingNegativeAcknowledgements,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].ImagingNegativeAcknowledgements),
|
float64(dst[0].ImagingNegativeAcknowledgements),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingRXBWkbitPersec,
|
c.imagingRXBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingRXBWkbitPersec),
|
float64(dst[0].ImagingRXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingSVGAdevTapframesPersec,
|
c.imagingSVGAdevTapframesPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingSVGAdevTapframesPersec),
|
float64(dst[0].ImagingSVGAdevTapframesPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ImagingTXBWkbitPersec,
|
c.imagingTXBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].ImagingTXBWkbitPersec),
|
float64(dst[0].ImagingTXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -595,63 +610,63 @@ func (c *collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RXBWkbitPersec,
|
c.rxBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].RXBWkbitPersec),
|
float64(dst[0].RXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RXBWPeakkbitPersec,
|
c.rxBWPeakKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].RXBWPeakkbitPersec),
|
float64(dst[0].RXBWPeakKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RXPacketLossPercent,
|
c.rxPacketLossPercent,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].RXPacketLossPercent),
|
float64(dst[0].RXPacketLossPercent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.RXPacketLossPercent_Base,
|
c.rxPacketLossPercentBase,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].RXPacketLossPercent_Base),
|
float64(dst[0].RXPacketLossPercentBase),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TXBWActiveLimitkbitPersec,
|
c.txBWActiveLimitKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TXBWActiveLimitkbitPersec),
|
float64(dst[0].TXBWActiveLimitKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TXBWkbitPersec,
|
c.txBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TXBWkbitPersec),
|
float64(dst[0].TXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TXBWLimitkbitPersec,
|
c.txBWLimitKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TXBWLimitkbitPersec),
|
float64(dst[0].TXBWLimitKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TXPacketLossPercent,
|
c.txPacketLossPercent,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TXPacketLossPercent),
|
float64(dst[0].TXPacketLossPercent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.TXPacketLossPercent_Base,
|
c.txPacketLossPercentBase,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].TXPacketLossPercent_Base),
|
float64(dst[0].TXPacketLossPercentBase),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectUsb(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectUsb(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -662,27 +677,27 @@ func (c *collector) collectUsb(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.USBBytesReceived,
|
c.usbBytesReceived,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].USBBytesReceived),
|
float64(dst[0].USBBytesReceived),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.USBBytesSent,
|
c.usbBytesSent,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].USBBytesSent),
|
float64(dst[0].USBBytesSent),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.USBRXBWkbitPersec,
|
c.usbRXBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].USBRXBWkbitPersec),
|
float64(dst[0].USBRXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.USBTXBWkbitPersec,
|
c.usbTXBWKBitPerSec,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].USBTXBWkbitPersec),
|
float64(dst[0].USBTXBWKBitPerSec),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -46,148 +46,165 @@ func isConnectionBrokerServer(logger log.Logger) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI
|
// A Collector is a Prometheus Collector for WMI
|
||||||
// Win32_PerfRawData_LocalSessionManager_TerminalServices & Win32_PerfRawData_TermService_TerminalServicesSession metrics
|
// Win32_PerfRawData_LocalSessionManager_TerminalServices & Win32_PerfRawData_TermService_TerminalServicesSession metrics
|
||||||
// https://docs.microsoft.com/en-us/previous-versions/aa394344(v%3Dvs.85)
|
// https://docs.microsoft.com/en-us/previous-versions/aa394344(v%3Dvs.85)
|
||||||
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_localsessionmanager_terminalservices/
|
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_localsessionmanager_terminalservices/
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
connectionBrokerEnabled bool
|
connectionBrokerEnabled bool
|
||||||
|
|
||||||
hServer syscall.Handle
|
hServer syscall.Handle
|
||||||
|
|
||||||
SessionInfo *prometheus.Desc
|
sessionInfo *prometheus.Desc
|
||||||
LocalSessionCount *prometheus.Desc
|
connectionBrokerPerformance *prometheus.Desc
|
||||||
ConnectionBrokerPerformance *prometheus.Desc
|
handleCount *prometheus.Desc
|
||||||
HandleCount *prometheus.Desc
|
pageFaultsPerSec *prometheus.Desc
|
||||||
PageFaultsPersec *prometheus.Desc
|
pageFileBytes *prometheus.Desc
|
||||||
PageFileBytes *prometheus.Desc
|
pageFileBytesPeak *prometheus.Desc
|
||||||
PageFileBytesPeak *prometheus.Desc
|
percentCPUTime *prometheus.Desc
|
||||||
PercentCPUTime *prometheus.Desc
|
poolNonPagedBytes *prometheus.Desc
|
||||||
PoolNonpagedBytes *prometheus.Desc
|
poolPagedBytes *prometheus.Desc
|
||||||
PoolPagedBytes *prometheus.Desc
|
privateBytes *prometheus.Desc
|
||||||
PrivateBytes *prometheus.Desc
|
threadCount *prometheus.Desc
|
||||||
ThreadCount *prometheus.Desc
|
virtualBytes *prometheus.Desc
|
||||||
VirtualBytes *prometheus.Desc
|
virtualBytesPeak *prometheus.Desc
|
||||||
VirtualBytesPeak *prometheus.Desc
|
workingSet *prometheus.Desc
|
||||||
WorkingSet *prometheus.Desc
|
workingSetPeak *prometheus.Desc
|
||||||
WorkingSetPeak *prometheus.Desc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{
|
return []string{
|
||||||
"Terminal Services Session",
|
"Terminal Services Session",
|
||||||
"Remote Desktop Connection Broker Counterset",
|
"Remote Desktop Connection Broker Counterset",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
err := wtsapi32.WTSCloseServer(c.hServer)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to close WTS server: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
c.connectionBrokerEnabled = isConnectionBrokerServer(c.logger)
|
c.connectionBrokerEnabled = isConnectionBrokerServer(c.logger)
|
||||||
|
|
||||||
c.SessionInfo = prometheus.NewDesc(
|
c.sessionInfo = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "session_info"),
|
prometheus.BuildFQName(types.Namespace, Name, "session_info"),
|
||||||
"Terminal Services sessions info",
|
"Terminal Services sessions info",
|
||||||
[]string{"session_name", "user", "host", "state"},
|
[]string{"session_name", "user", "host", "state"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ConnectionBrokerPerformance = prometheus.NewDesc(
|
c.connectionBrokerPerformance = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_broker_performance_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_broker_performance_total"),
|
||||||
"The total number of connections handled by the Connection Brokers since the service started.",
|
"The total number of connections handled by the Connection Brokers since the service started.",
|
||||||
[]string{"connection"},
|
[]string{"connection"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.HandleCount = prometheus.NewDesc(
|
c.handleCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "handles"),
|
prometheus.BuildFQName(types.Namespace, Name, "handles"),
|
||||||
"Total number of handles currently opened by this process. This number is the sum of the handles currently opened by each thread in this process.",
|
"Total number of handles currently opened by this process. This number is the sum of the handles currently opened by each thread in this process.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PageFaultsPersec = prometheus.NewDesc(
|
c.pageFaultsPerSec = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "page_fault_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "page_fault_total"),
|
||||||
"Rate at which page faults occur in the threads executing in this process. A page fault occurs when a thread refers to a virtual memory page that is not in its working set in main memory. The page may not be retrieved from disk if it is on the standby list and therefore already in main memory. The page also may not be retrieved if it is in use by another process which shares the page.",
|
"Rate at which page faults occur in the threads executing in this process. A page fault occurs when a thread refers to a virtual memory page that is not in its working set in main memory. The page may not be retrieved from disk if it is on the standby list and therefore already in main memory. The page also may not be retrieved if it is in use by another process which shares the page.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PageFileBytes = prometheus.NewDesc(
|
c.pageFileBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "page_file_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "page_file_bytes"),
|
||||||
"Current number of bytes this process has used in the paging file(s). Paging files are used to store pages of memory used by the process that are not contained in other files. Paging files are shared by all processes, and lack of space in paging files can prevent other processes from allocating memory.",
|
"Current number of bytes this process has used in the paging file(s). Paging files are used to store pages of memory used by the process that are not contained in other files. Paging files are shared by all processes, and lack of space in paging files can prevent other processes from allocating memory.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PageFileBytesPeak = prometheus.NewDesc(
|
c.pageFileBytesPeak = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "page_file_bytes_peak"),
|
prometheus.BuildFQName(types.Namespace, Name, "page_file_bytes_peak"),
|
||||||
"Maximum number of bytes this process has used in the paging file(s). Paging files are used to store pages of memory used by the process that are not contained in other files. Paging files are shared by all processes, and lack of space in paging files can prevent other processes from allocating memory.",
|
"Maximum number of bytes this process has used in the paging file(s). Paging files are used to store pages of memory used by the process that are not contained in other files. Paging files are shared by all processes, and lack of space in paging files can prevent other processes from allocating memory.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PercentCPUTime = prometheus.NewDesc(
|
c.percentCPUTime = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_time_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_time_seconds_total"),
|
||||||
"Total elapsed time that this process's threads have spent executing code.",
|
"Total elapsed time that this process's threads have spent executing code.",
|
||||||
[]string{"mode", "session_name"},
|
[]string{"mode", "session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolNonpagedBytes = prometheus.NewDesc(
|
c.poolNonPagedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_non_paged_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_non_paged_bytes"),
|
||||||
"Number of bytes in the non-paged pool, an area of system memory (physical memory used by the operating system) for objects that cannot be written to disk, but must remain in physical memory as long as they are allocated. This property displays the last observed value only; it is not an average.",
|
"Number of bytes in the non-paged pool, an area of system memory (physical memory used by the operating system) for objects that cannot be written to disk, but must remain in physical memory as long as they are allocated. This property displays the last observed value only; it is not an average.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PoolPagedBytes = prometheus.NewDesc(
|
c.poolPagedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_bytes"),
|
||||||
"Number of bytes in the paged pool, an area of system memory (physical memory used by the operating system) for objects that can be written to disk when they are not being used. This property displays the last observed value only; it is not an average.",
|
"Number of bytes in the paged pool, an area of system memory (physical memory used by the operating system) for objects that can be written to disk when they are not being used. This property displays the last observed value only; it is not an average.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PrivateBytes = prometheus.NewDesc(
|
c.privateBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "private_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "private_bytes"),
|
||||||
"Current number of bytes this process has allocated that cannot be shared with other processes.",
|
"Current number of bytes this process has allocated that cannot be shared with other processes.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ThreadCount = prometheus.NewDesc(
|
c.threadCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "threads"),
|
prometheus.BuildFQName(types.Namespace, Name, "threads"),
|
||||||
"Number of threads currently active in this process. An instruction is the basic unit of execution in a processor, and a thread is the object that executes instructions. Every running process has at least one thread.",
|
"Number of threads currently active in this process. An instruction is the basic unit of execution in a processor, and a thread is the object that executes instructions. Every running process has at least one thread.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.VirtualBytes = prometheus.NewDesc(
|
c.virtualBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "virtual_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "virtual_bytes"),
|
||||||
"Current size, in bytes, of the virtual address space the process is using. Use of virtual address space does not necessarily imply corresponding use of either disk or main memory pages. Virtual space is finite and, by using too much, the process can limit its ability to load libraries.",
|
"Current size, in bytes, of the virtual address space the process is using. Use of virtual address space does not necessarily imply corresponding use of either disk or main memory pages. Virtual space is finite and, by using too much, the process can limit its ability to load libraries.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.VirtualBytesPeak = prometheus.NewDesc(
|
c.virtualBytesPeak = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "virtual_bytes_peak"),
|
prometheus.BuildFQName(types.Namespace, Name, "virtual_bytes_peak"),
|
||||||
"Maximum number of bytes of virtual address space the process has used at any one time. Use of virtual address space does not necessarily imply corresponding use of either disk or main memory pages. Virtual space is finite and, by using too much, the process might limit its ability to load libraries.",
|
"Maximum number of bytes of virtual address space the process has used at any one time. Use of virtual address space does not necessarily imply corresponding use of either disk or main memory pages. Virtual space is finite and, by using too much, the process might limit its ability to load libraries.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WorkingSet = prometheus.NewDesc(
|
c.workingSet = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "working_set_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "working_set_bytes"),
|
||||||
"Current number of bytes in the working set of this process. The working set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the working set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from working sets. If they are needed, they are then soft-faulted back into the working set before they leave main memory.",
|
"Current number of bytes in the working set of this process. The working set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the working set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from working sets. If they are needed, they are then soft-faulted back into the working set before they leave main memory.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.WorkingSetPeak = prometheus.NewDesc(
|
c.workingSetPeak = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "working_set_bytes_peak"),
|
prometheus.BuildFQName(types.Namespace, Name, "working_set_bytes_peak"),
|
||||||
"Maximum number of bytes in the working set of this process at any point in time. The working set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the working set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from working sets. If they are needed, they are then soft-faulted back into the working set before they leave main memory.",
|
"Maximum number of bytes in the working set of this process at any point in time. The working set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the working set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from working sets. If they are needed, they are then soft-faulted back into the working set before they leave main memory.",
|
||||||
[]string{"session_name"},
|
[]string{"session_name"},
|
||||||
@@ -206,7 +223,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collectWTSSessions(ch); err != nil {
|
if err := c.collectWTSSessions(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting terminal services session infos", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting terminal services session infos", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -245,7 +262,7 @@ type perflibTerminalServicesSession struct {
|
|||||||
WorkingSetPeak float64 `perflib:"Working Set Peak"`
|
WorkingSetPeak float64 `perflib:"Working Set Peak"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectTSSessionCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectTSSessionCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
dst := make([]perflibTerminalServicesSession, 0)
|
dst := make([]perflibTerminalServicesSession, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["Terminal Services Session"], &dst, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["Terminal Services Session"], &dst, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -266,94 +283,94 @@ func (c *collector) collectTSSessionCounters(ctx *types.ScrapeContext, ch chan<-
|
|||||||
names[n] = true
|
names[n] = true
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HandleCount,
|
c.handleCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.HandleCount,
|
d.HandleCount,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PageFaultsPersec,
|
c.pageFaultsPerSec,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.PageFaultsPersec,
|
d.PageFaultsPersec,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PageFileBytes,
|
c.pageFileBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.PageFileBytes,
|
d.PageFileBytes,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PageFileBytesPeak,
|
c.pageFileBytesPeak,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.PageFileBytesPeak,
|
d.PageFileBytesPeak,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PercentCPUTime,
|
c.percentCPUTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.PercentPrivilegedTime,
|
d.PercentPrivilegedTime,
|
||||||
d.Name,
|
d.Name,
|
||||||
"privileged",
|
"privileged",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PercentCPUTime,
|
c.percentCPUTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.PercentProcessorTime,
|
d.PercentProcessorTime,
|
||||||
d.Name,
|
d.Name,
|
||||||
"processor",
|
"processor",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PercentCPUTime,
|
c.percentCPUTime,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
d.PercentUserTime,
|
d.PercentUserTime,
|
||||||
d.Name,
|
d.Name,
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolNonpagedBytes,
|
c.poolNonPagedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.PoolNonpagedBytes,
|
d.PoolNonpagedBytes,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PoolPagedBytes,
|
c.poolPagedBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.PoolPagedBytes,
|
d.PoolPagedBytes,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PrivateBytes,
|
c.privateBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.PrivateBytes,
|
d.PrivateBytes,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ThreadCount,
|
c.threadCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.ThreadCount,
|
d.ThreadCount,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VirtualBytes,
|
c.virtualBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.VirtualBytes,
|
d.VirtualBytes,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.VirtualBytesPeak,
|
c.virtualBytesPeak,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.VirtualBytesPeak,
|
d.VirtualBytesPeak,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WorkingSet,
|
c.workingSet,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.WorkingSet,
|
d.WorkingSet,
|
||||||
d.Name,
|
d.Name,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.WorkingSetPeak,
|
c.workingSetPeak,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
d.WorkingSetPeak,
|
d.WorkingSetPeak,
|
||||||
d.Name,
|
d.Name,
|
||||||
@@ -368,7 +385,7 @@ type perflibRemoteDesktopConnectionBrokerCounterset struct {
|
|||||||
FailedConnections float64 `perflib:"Failed Connections"`
|
FailedConnections float64 `perflib:"Failed Connections"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectCollectionBrokerPerformanceCounter(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectCollectionBrokerPerformanceCounter(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
dst := make([]perflibRemoteDesktopConnectionBrokerCounterset, 0)
|
dst := make([]perflibRemoteDesktopConnectionBrokerCounterset, 0)
|
||||||
err := perflib.UnmarshalObject(ctx.PerfObjects["Remote Desktop Connection Broker Counterset"], &dst, c.logger)
|
err := perflib.UnmarshalObject(ctx.PerfObjects["Remote Desktop Connection Broker Counterset"], &dst, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -379,21 +396,21 @@ func (c *collector) collectCollectionBrokerPerformanceCounter(ctx *types.ScrapeC
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionBrokerPerformance,
|
c.connectionBrokerPerformance,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].SuccessfulConnections,
|
dst[0].SuccessfulConnections,
|
||||||
"Successful",
|
"Successful",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionBrokerPerformance,
|
c.connectionBrokerPerformance,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].PendingConnections,
|
dst[0].PendingConnections,
|
||||||
"Pending",
|
"Pending",
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ConnectionBrokerPerformance,
|
c.connectionBrokerPerformance,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].FailedConnections,
|
dst[0].FailedConnections,
|
||||||
"Failed",
|
"Failed",
|
||||||
@@ -402,7 +419,7 @@ func (c *collector) collectCollectionBrokerPerformanceCounter(ctx *types.ScrapeC
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectWTSSessions(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectWTSSessions(ch chan<- prometheus.Metric) error {
|
||||||
sessions, err := wtsapi32.WTSEnumerateSessionsEx(c.hServer, c.logger)
|
sessions, err := wtsapi32.WTSEnumerateSessionsEx(c.hServer, c.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to enumerate WTS sessions: %w", err)
|
return fmt.Errorf("failed to enumerate WTS sessions: %w", err)
|
||||||
@@ -421,10 +438,10 @@ func (c *collector) collectWTSSessions(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SessionInfo,
|
c.sessionInfo,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
isState,
|
isState,
|
||||||
strings.Replace(session.SessionName, "#", " ", -1),
|
strings.ReplaceAll(session.SessionName, "#", " "),
|
||||||
userName,
|
userName,
|
||||||
session.HostName,
|
session.HostName,
|
||||||
stateName,
|
stateName,
|
||||||
|
|||||||
@@ -8,7 +8,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
|
|
||||||
testutils.FuncBenchmarkCollector(b, terminal_services.Name, terminal_services.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, terminal_services.Name, terminal_services.NewWithFlags)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,79 +31,91 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"github.com/prometheus/common/expfmt"
|
"github.com/prometheus/common/expfmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const Name = "textfile"
|
||||||
Name = "textfile"
|
|
||||||
FlagTextFileDirectories = "collector.textfile.directories"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
TextFileDirectories string `yaml:"text_file_directories"`
|
TextFileDirectories []string `yaml:"text_file_directories"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
TextFileDirectories: getDefaultPath(),
|
TextFileDirectories: []string{getDefaultPath()},
|
||||||
}
|
}
|
||||||
|
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
textFileDirectories *string
|
|
||||||
|
|
||||||
directories string
|
|
||||||
// Only set for testing to get predictable output.
|
// Only set for testing to get predictable output.
|
||||||
mtime *float64
|
mTime *float64
|
||||||
|
|
||||||
MtimeDesc *prometheus.Desc
|
mTimeDesc *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, config *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &ConfigDefaults
|
config = &ConfigDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &collector{
|
if config.TextFileDirectories == nil {
|
||||||
textFileDirectories: &config.TextFileDirectories,
|
config.TextFileDirectories = ConfigDefaults.TextFileDirectories
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(app *kingpin.Application) types.Collector {
|
func NewWithFlags(app *kingpin.Application) *Collector {
|
||||||
return &collector{
|
c := &Collector{
|
||||||
textFileDirectories: app.Flag(
|
config: ConfigDefaults,
|
||||||
FlagTextFileDirectories,
|
|
||||||
"Directory or Directories to read text files with metrics from.",
|
|
||||||
).Default(ConfigDefaults.TextFileDirectories).String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var textFileDirectories string
|
||||||
|
|
||||||
|
app.Flag(
|
||||||
|
"collector.textfile.directories",
|
||||||
|
"Directory or Directories to read text files with metrics from.",
|
||||||
|
).Default(strings.Join(ConfigDefaults.TextFileDirectories, ",")).StringVar(&textFileDirectories)
|
||||||
|
|
||||||
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
|
c.config.TextFileDirectories = strings.Split(textFileDirectories, ",")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.directories = ""
|
return nil
|
||||||
if utils.HasValue(c.textFileDirectories) {
|
}
|
||||||
c.directories = strings.Trim(*c.textFileDirectories, ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = level.Info(c.logger).Log("msg", "textfile collector directories: "+c.directories)
|
func (c *Collector) Build() error {
|
||||||
|
_ = level.Info(c.logger).
|
||||||
|
Log("msg", "textfile Collector directories: "+strings.Join(c.config.TextFileDirectories, ","))
|
||||||
|
|
||||||
c.MtimeDesc = prometheus.NewDesc(
|
c.mTimeDesc = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, "textfile", "mtime_seconds"),
|
prometheus.BuildFQName(types.Namespace, "textfile", "mtime_seconds"),
|
||||||
"Unixtime mtime of textfiles successfully read.",
|
"Unixtime mtime of textfiles successfully read.",
|
||||||
[]string{"file"},
|
[]string{"file"},
|
||||||
@@ -118,32 +130,32 @@ func (c *collector) Build() error {
|
|||||||
func duplicateMetricEntry(metricFamilies []*dto.MetricFamily) bool {
|
func duplicateMetricEntry(metricFamilies []*dto.MetricFamily) bool {
|
||||||
uniqueMetrics := make(map[string]map[string]string)
|
uniqueMetrics := make(map[string]map[string]string)
|
||||||
for _, metricFamily := range metricFamilies {
|
for _, metricFamily := range metricFamilies {
|
||||||
metric_name := *metricFamily.Name
|
metricName := metricFamily.GetName()
|
||||||
for _, metric := range metricFamily.Metric {
|
for _, metric := range metricFamily.GetMetric() {
|
||||||
metric_labels := metric.GetLabel()
|
metricLabels := metric.GetLabel()
|
||||||
labels := make(map[string]string)
|
labels := make(map[string]string)
|
||||||
for _, label := range metric_labels {
|
for _, label := range metricLabels {
|
||||||
labels[label.GetName()] = label.GetValue()
|
labels[label.GetName()] = label.GetValue()
|
||||||
}
|
}
|
||||||
// Check if key is present before appending
|
// Check if key is present before appending
|
||||||
_, mapContainsKey := uniqueMetrics[metric_name]
|
_, mapContainsKey := uniqueMetrics[metricName]
|
||||||
|
|
||||||
// Duplicate metric found with identical labels & label values
|
// Duplicate metric found with identical labels & label values
|
||||||
if mapContainsKey == true && reflect.DeepEqual(uniqueMetrics[metric_name], labels) {
|
if mapContainsKey && reflect.DeepEqual(uniqueMetrics[metricName], labels) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
uniqueMetrics[metric_name] = labels
|
uniqueMetrics[metricName] = labels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric) {
|
func (c *Collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric) {
|
||||||
var valType prometheus.ValueType
|
var valType prometheus.ValueType
|
||||||
var val float64
|
var val float64
|
||||||
|
|
||||||
allLabelNames := map[string]struct{}{}
|
allLabelNames := map[string]struct{}{}
|
||||||
for _, metric := range metricFamily.Metric {
|
for _, metric := range metricFamily.GetMetric() {
|
||||||
labels := metric.GetLabel()
|
labels := metric.GetLabel()
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
if _, ok := allLabelNames[label.GetName()]; !ok {
|
if _, ok := allLabelNames[label.GetName()]; !ok {
|
||||||
@@ -152,9 +164,9 @@ func (c *collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range metricFamily.Metric {
|
for _, metric := range metricFamily.GetMetric() {
|
||||||
if metric.TimestampMs != nil {
|
if metric.TimestampMs != nil {
|
||||||
_ = level.Warn(c.logger).Log("msg", fmt.Sprintf("Ignoring unsupported custom timestamp on textfile collector metric %v", metric))
|
_ = level.Warn(c.logger).Log("msg", fmt.Sprintf("Ignoring unsupported custom timestamp on textfile Collector metric %v", metric))
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := metric.GetLabel()
|
labels := metric.GetLabel()
|
||||||
@@ -173,7 +185,7 @@ func (c *collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if present == false {
|
if !present {
|
||||||
names = append(names, k)
|
names = append(names, k)
|
||||||
values = append(values, "")
|
values = append(values, "")
|
||||||
}
|
}
|
||||||
@@ -183,44 +195,44 @@ func (c *collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
|
|||||||
switch metricType {
|
switch metricType {
|
||||||
case dto.MetricType_COUNTER:
|
case dto.MetricType_COUNTER:
|
||||||
valType = prometheus.CounterValue
|
valType = prometheus.CounterValue
|
||||||
val = metric.Counter.GetValue()
|
val = metric.GetCounter().GetValue()
|
||||||
|
|
||||||
case dto.MetricType_GAUGE:
|
case dto.MetricType_GAUGE:
|
||||||
valType = prometheus.GaugeValue
|
valType = prometheus.GaugeValue
|
||||||
val = metric.Gauge.GetValue()
|
val = metric.GetGauge().GetValue()
|
||||||
|
|
||||||
case dto.MetricType_UNTYPED:
|
case dto.MetricType_UNTYPED:
|
||||||
valType = prometheus.UntypedValue
|
valType = prometheus.UntypedValue
|
||||||
val = metric.Untyped.GetValue()
|
val = metric.GetUntyped().GetValue()
|
||||||
|
|
||||||
case dto.MetricType_SUMMARY:
|
case dto.MetricType_SUMMARY:
|
||||||
quantiles := map[float64]float64{}
|
quantiles := map[float64]float64{}
|
||||||
for _, q := range metric.Summary.Quantile {
|
for _, q := range metric.GetSummary().GetQuantile() {
|
||||||
quantiles[q.GetQuantile()] = q.GetValue()
|
quantiles[q.GetQuantile()] = q.GetValue()
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstSummary(
|
ch <- prometheus.MustNewConstSummary(
|
||||||
prometheus.NewDesc(
|
prometheus.NewDesc(
|
||||||
*metricFamily.Name,
|
metricFamily.GetName(),
|
||||||
metricFamily.GetHelp(),
|
metricFamily.GetHelp(),
|
||||||
names, nil,
|
names, nil,
|
||||||
),
|
),
|
||||||
metric.Summary.GetSampleCount(),
|
metric.GetSummary().GetSampleCount(),
|
||||||
metric.Summary.GetSampleSum(),
|
metric.GetSummary().GetSampleSum(),
|
||||||
quantiles, values...,
|
quantiles, values...,
|
||||||
)
|
)
|
||||||
case dto.MetricType_HISTOGRAM:
|
case dto.MetricType_HISTOGRAM:
|
||||||
buckets := map[float64]uint64{}
|
buckets := map[float64]uint64{}
|
||||||
for _, b := range metric.Histogram.Bucket {
|
for _, b := range metric.GetHistogram().GetBucket() {
|
||||||
buckets[b.GetUpperBound()] = b.GetCumulativeCount()
|
buckets[b.GetUpperBound()] = b.GetCumulativeCount()
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstHistogram(
|
ch <- prometheus.MustNewConstHistogram(
|
||||||
prometheus.NewDesc(
|
prometheus.NewDesc(
|
||||||
*metricFamily.Name,
|
metricFamily.GetName(),
|
||||||
metricFamily.GetHelp(),
|
metricFamily.GetHelp(),
|
||||||
names, nil,
|
names, nil,
|
||||||
),
|
),
|
||||||
metric.Histogram.GetSampleCount(),
|
metric.GetHistogram().GetSampleCount(),
|
||||||
metric.Histogram.GetSampleSum(),
|
metric.GetHistogram().GetSampleSum(),
|
||||||
buckets, values...,
|
buckets, values...,
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
@@ -230,7 +242,7 @@ func (c *collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
|
|||||||
if metricType == dto.MetricType_GAUGE || metricType == dto.MetricType_COUNTER || metricType == dto.MetricType_UNTYPED {
|
if metricType == dto.MetricType_GAUGE || metricType == dto.MetricType_COUNTER || metricType == dto.MetricType_UNTYPED {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
prometheus.NewDesc(
|
prometheus.NewDesc(
|
||||||
*metricFamily.Name,
|
metricFamily.GetName(),
|
||||||
metricFamily.GetHelp(),
|
metricFamily.GetHelp(),
|
||||||
names, nil,
|
names, nil,
|
||||||
),
|
),
|
||||||
@@ -240,22 +252,22 @@ func (c *collector) convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) exportMTimes(mtimes map[string]time.Time, ch chan<- prometheus.Metric) {
|
func (c *Collector) exportMTimes(mTimes map[string]time.Time, ch chan<- prometheus.Metric) {
|
||||||
// Export the mtimes of the successful files.
|
// Export the mtimes of the successful files.
|
||||||
if len(mtimes) > 0 {
|
if len(mTimes) > 0 {
|
||||||
// Sorting is needed for predictable output comparison in tests.
|
// Sorting is needed for predictable output comparison in tests.
|
||||||
filenames := make([]string, 0, len(mtimes))
|
filenames := make([]string, 0, len(mTimes))
|
||||||
for filename := range mtimes {
|
for filename := range mTimes {
|
||||||
filenames = append(filenames, filename)
|
filenames = append(filenames, filename)
|
||||||
}
|
}
|
||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
|
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
mtime := float64(mtimes[filename].UnixNano() / 1e9)
|
mtime := float64(mTimes[filename].UnixNano() / 1e9)
|
||||||
if c.mtime != nil {
|
if c.mTime != nil {
|
||||||
mtime = *c.mtime
|
mtime = *c.mTime
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(c.MtimeDesc, prometheus.GaugeValue, mtime, filename)
|
ch <- prometheus.MustNewConstMetric(c.mTimeDesc, prometheus.GaugeValue, mtime, filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +276,7 @@ type carriageReturnFilteringReader struct {
|
|||||||
r io.Reader
|
r io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read returns data from the underlying io.Reader, but with \r filtered out
|
// Read returns data from the underlying io.Reader, but with \r filtered out.
|
||||||
func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
|
func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
|
||||||
buf := make([]byte, len(p))
|
buf := make([]byte, len(p))
|
||||||
n, err := cr.r.Read(buf)
|
n, err := cr.r.Read(buf)
|
||||||
@@ -274,7 +286,7 @@ func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pi := 0
|
pi := 0
|
||||||
for i := 0; i < n; i++ {
|
for i := range n {
|
||||||
if buf[i] != '\r' {
|
if buf[i] != '\r' {
|
||||||
p[pi] = buf[i]
|
p[pi] = buf[i]
|
||||||
pi++
|
pi++
|
||||||
@@ -285,16 +297,17 @@ func (cr carriageReturnFilteringReader) Read(p []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Collect implements the Collector interface.
|
// Collect implements the Collector interface.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
errorMetric := 0.0
|
errorMetric := 0.0
|
||||||
mtimes := map[string]time.Time{}
|
mTimes := map[string]time.Time{}
|
||||||
|
|
||||||
// Create empty metricFamily slice here and append parsedFamilies to it inside the loop.
|
// Create empty metricFamily slice here and append parsedFamilies to it inside the loop.
|
||||||
// Once loop is complete, raise error if any duplicates are present.
|
// Once loop is complete, raise error if any duplicates are present.
|
||||||
// This will ensure that duplicate metrics are correctly detected between multiple .prom files.
|
// This will ensure that duplicate metrics are correctly detected between multiple .prom files.
|
||||||
metricFamilies := []*dto.MetricFamily{}
|
var metricFamilies []*dto.MetricFamily
|
||||||
|
|
||||||
// Iterate over files and accumulate their metrics.
|
// Iterate over files and accumulate their metrics.
|
||||||
for _, directory := range strings.Split(c.directories, ",") {
|
for _, directory := range c.config.TextFileDirectories {
|
||||||
err := filepath.WalkDir(directory, func(path string, dirEntry os.DirEntry, err error) error {
|
err := filepath.WalkDir(directory, func(path string, dirEntry os.DirEntry, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "Error reading directory: "+path, "err", err)
|
_ = level.Error(c.logger).Log("msg", "Error reading directory: "+path, "err", err)
|
||||||
@@ -315,18 +328,18 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
errorMetric = 1.0
|
errorMetric = 1.0
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, hasName := mtimes[fileInfo.Name()]; hasName {
|
if _, hasName := mTimes[fileInfo.Name()]; hasName {
|
||||||
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("Duplicate filename detected: %q. Skip File.", path))
|
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("Duplicate filename detected: %q. Skip File.", path))
|
||||||
errorMetric = 1.0
|
errorMetric = 1.0
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
mtimes[fileInfo.Name()] = fileInfo.ModTime()
|
mTimes[fileInfo.Name()] = fileInfo.ModTime()
|
||||||
metricFamilies = append(metricFamilies, families_array...)
|
metricFamilies = append(metricFamilies, families_array...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && directory != "" {
|
if err != nil && directory != "" {
|
||||||
_ = level.Error(c.logger).Log("msg", "Error reading textfile collector directory: "+c.directories, "err", err)
|
_ = level.Error(c.logger).Log("msg", "Error reading textfile Collector directory: "+directory, "err", err)
|
||||||
errorMetric = 1.0
|
errorMetric = 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,7 +354,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.exportMTimes(mtimes, ch)
|
c.exportMTimes(mTimes, ch)
|
||||||
// Export if there were errors.
|
// Export if there were errors.
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
prometheus.NewDesc(
|
prometheus.NewDesc(
|
||||||
@@ -378,7 +391,7 @@ func scrapeFile(path string, log log.Logger) ([]*dto.MetricFamily, error) {
|
|||||||
|
|
||||||
for _, mf := range parsedFamilies {
|
for _, mf := range parsedFamilies {
|
||||||
families_array = append(families_array, mf)
|
families_array = append(families_array, mf)
|
||||||
for _, m := range mf.Metric {
|
for _, m := range mf.GetMetric() {
|
||||||
if m.TimestampMs != nil {
|
if m.TimestampMs != nil {
|
||||||
return nil, errors.New("textfile contains unsupported client-side timestamps")
|
return nil, errors.New("textfile contains unsupported client-side timestamps")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCRFilter(t *testing.T) {
|
func TestCRFilter(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
sr := strings.NewReader("line 1\r\nline 2")
|
sr := strings.NewReader("line 1\r\nline 2")
|
||||||
cr := carriageReturnFilteringReader{r: sr}
|
cr := carriageReturnFilteringReader{r: sr}
|
||||||
b, err := io.ReadAll(cr)
|
b, err := io.ReadAll(cr)
|
||||||
@@ -23,6 +25,8 @@ func TestCRFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckBOM(t *testing.T) {
|
func TestCheckBOM(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
testdata := []struct {
|
testdata := []struct {
|
||||||
encoding utfbom.Encoding
|
encoding utfbom.Encoding
|
||||||
err string
|
err string
|
||||||
@@ -49,6 +53,8 @@ func TestCheckBOM(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDuplicateMetricEntry(t *testing.T) {
|
func TestDuplicateMetricEntry(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
metric_name := "windows_sometest"
|
metric_name := "windows_sometest"
|
||||||
metric_help := "This is a Test."
|
metric_help := "This is a Test."
|
||||||
metric_type := dto.MetricType_GAUGE
|
metric_type := dto.MetricType_GAUGE
|
||||||
|
|||||||
@@ -6,28 +6,27 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/go-kit/log"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector"
|
"github.com/prometheus-community/windows_exporter/pkg/collector"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/textfile"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/textfile"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var baseDir = "../../../tools/textfile-test"
|
var baseDir = "../../../tools/textfile-test"
|
||||||
|
|
||||||
func TestMultipleDirectories(t *testing.T) {
|
func TestMultipleDirectories(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
testDir := baseDir + "/multiple-dirs"
|
testDir := baseDir + "/multiple-dirs"
|
||||||
testDirs := fmt.Sprintf("%[1]s/dir1,%[1]s/dir2,%[1]s/dir3", testDir)
|
testDirs := fmt.Sprintf("%[1]s/dir1,%[1]s/dir2,%[1]s/dir3", testDir)
|
||||||
|
|
||||||
textfileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
|
textFileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
|
||||||
TextFileDirectories: testDirs,
|
TextFileDirectories: strings.Split(testDirs, ","),
|
||||||
})
|
})
|
||||||
|
|
||||||
collectors := collector.New(map[string]types.Collector{textfile.Name: textfileCollector})
|
collectors := collector.New(map[string]collector.Collector{textfile.Name: textFileCollector})
|
||||||
require.NoError(t, collectors.Build())
|
require.NoError(t, collectors.Build())
|
||||||
|
|
||||||
scrapeContext, err := collectors.PrepareScrapeContext()
|
scrapeContext, err := collectors.PrepareScrapeContext()
|
||||||
@@ -48,7 +47,7 @@ func TestMultipleDirectories(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = textfileCollector.Collect(scrapeContext, metrics)
|
err = textFileCollector.Collect(scrapeContext, metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error %s", err)
|
t.Errorf("Unexpected error %s", err)
|
||||||
}
|
}
|
||||||
@@ -61,12 +60,14 @@ func TestMultipleDirectories(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDuplicateFileName(t *testing.T) {
|
func TestDuplicateFileName(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
testDir := baseDir + "/duplicate-filename"
|
testDir := baseDir + "/duplicate-filename"
|
||||||
textfileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
|
textFileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
|
||||||
TextFileDirectories: testDir,
|
TextFileDirectories: []string{testDir},
|
||||||
})
|
})
|
||||||
|
|
||||||
collectors := collector.New(map[string]types.Collector{textfile.Name: textfileCollector})
|
collectors := collector.New(map[string]collector.Collector{textfile.Name: textFileCollector})
|
||||||
require.NoError(t, collectors.Build())
|
require.NoError(t, collectors.Build())
|
||||||
|
|
||||||
scrapeContext, err := collectors.PrepareScrapeContext()
|
scrapeContext, err := collectors.PrepareScrapeContext()
|
||||||
@@ -86,13 +87,15 @@ func TestDuplicateFileName(t *testing.T) {
|
|||||||
got += metric.String()
|
got += metric.String()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
err = textfileCollector.Collect(scrapeContext, metrics)
|
err = textFileCollector.Collect(scrapeContext, metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error %s", err)
|
t.Errorf("Unexpected error %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(got, "file") {
|
if !strings.Contains(got, "file") {
|
||||||
t.Errorf("Unexpected output %q", got)
|
t.Errorf("Unexpected output %q", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(got, "sub_file") {
|
if strings.Contains(got, "sub_file") {
|
||||||
t.Errorf("Unexpected output %q", got)
|
t.Errorf("Unexpected output %q", got)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,39 +19,52 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
PercentPassiveLimit *prometheus.Desc
|
percentPassiveLimit *prometheus.Desc
|
||||||
Temperature *prometheus.Desc
|
temperature *prometheus.Desc
|
||||||
ThrottleReasons *prometheus.Desc
|
throttleReasons *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.Temperature = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.temperature = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "temperature_celsius"),
|
prometheus.BuildFQName(types.Namespace, Name, "temperature_celsius"),
|
||||||
"(Temperature)",
|
"(Temperature)",
|
||||||
[]string{
|
[]string{
|
||||||
@@ -59,7 +72,7 @@ func (c *collector) Build() error {
|
|||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.PercentPassiveLimit = prometheus.NewDesc(
|
c.percentPassiveLimit = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "percent_passive_limit"),
|
prometheus.BuildFQName(types.Namespace, Name, "percent_passive_limit"),
|
||||||
"(PercentPassiveLimit)",
|
"(PercentPassiveLimit)",
|
||||||
[]string{
|
[]string{
|
||||||
@@ -67,7 +80,7 @@ func (c *collector) Build() error {
|
|||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ThrottleReasons = prometheus.NewDesc(
|
c.throttleReasons = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "throttle_reasons"),
|
prometheus.BuildFQName(types.Namespace, Name, "throttle_reasons"),
|
||||||
"(ThrottleReasons)",
|
"(ThrottleReasons)",
|
||||||
[]string{
|
[]string{
|
||||||
@@ -80,7 +93,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting thermalzone metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting thermalzone metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -98,7 +111,7 @@ type Win32_PerfRawData_Counters_ThermalZoneInformation struct {
|
|||||||
ThrottleReasons uint32
|
ThrottleReasons uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_Counters_ThermalZoneInformation
|
var dst []Win32_PerfRawData_Counters_ThermalZoneInformation
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -113,21 +126,21 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
for _, info := range dst {
|
for _, info := range dst {
|
||||||
// Divide by 10 and subtract 273.15 to convert decikelvin to celsius
|
// Divide by 10 and subtract 273.15 to convert decikelvin to celsius
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Temperature,
|
c.temperature,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
(float64(info.HighPrecisionTemperature)/10.0)-273.15,
|
(float64(info.HighPrecisionTemperature)/10.0)-273.15,
|
||||||
info.Name,
|
info.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PercentPassiveLimit,
|
c.percentPassiveLimit,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(info.PercentPassiveLimit),
|
float64(info.PercentPassiveLimit),
|
||||||
info.Name,
|
info.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ThrottleReasons,
|
c.throttleReasons,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(info.ThrottleReasons),
|
float64(info.ThrottleReasons),
|
||||||
info.Name,
|
info.Name,
|
||||||
|
|||||||
@@ -20,76 +20,89 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// collector is a Prometheus collector for Perflib counter metrics
|
// Collector is a Prometheus Collector for Perflib counter metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
ClockFrequencyAdjustmentPPBTotal *prometheus.Desc
|
clockFrequencyAdjustmentPPBTotal *prometheus.Desc
|
||||||
ComputedTimeOffset *prometheus.Desc
|
computedTimeOffset *prometheus.Desc
|
||||||
NTPClientTimeSourceCount *prometheus.Desc
|
ntpClientTimeSourceCount *prometheus.Desc
|
||||||
NTPRoundtripDelay *prometheus.Desc
|
ntpRoundTripDelay *prometheus.Desc
|
||||||
NTPServerIncomingRequestsTotal *prometheus.Desc
|
ntpServerIncomingRequestsTotal *prometheus.Desc
|
||||||
NTPServerOutgoingResponsesTotal *prometheus.Desc
|
ntpServerOutgoingResponsesTotal *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{"Windows Time Service"}, nil
|
return []string{"Windows Time Service"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
if winversion.WindowsVersionFloat <= 6.1 {
|
if winversion.WindowsVersionFloat <= 6.1 {
|
||||||
return errors.New("Windows version older than Server 2016 detected. The time collector will not run and should be disabled via CLI flags or configuration file")
|
return errors.New("Windows version older than Server 2016 detected. The time collector will not run and should be disabled via CLI flags or configuration file")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ClockFrequencyAdjustmentPPBTotal = prometheus.NewDesc(
|
c.clockFrequencyAdjustmentPPBTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "clock_frequency_adjustment_ppb_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "clock_frequency_adjustment_ppb_total"),
|
||||||
"Total adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units.",
|
"Total adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.ComputedTimeOffset = prometheus.NewDesc(
|
c.computedTimeOffset = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "computed_time_offset_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "computed_time_offset_seconds"),
|
||||||
"Absolute time offset between the system clock and the chosen time source, in seconds",
|
"Absolute time offset between the system clock and the chosen time source, in seconds",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NTPClientTimeSourceCount = prometheus.NewDesc(
|
c.ntpClientTimeSourceCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ntp_client_time_sources"),
|
prometheus.BuildFQName(types.Namespace, Name, "ntp_client_time_sources"),
|
||||||
"Active number of NTP Time sources being used by the client",
|
"Active number of NTP Time sources being used by the client",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NTPRoundtripDelay = prometheus.NewDesc(
|
c.ntpRoundTripDelay = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ntp_round_trip_delay_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "ntp_round_trip_delay_seconds"),
|
||||||
"Roundtrip delay experienced by the NTP client in receiving a response from the server for the most recent request, in seconds",
|
"Roundtrip delay experienced by the NTP client in receiving a response from the server for the most recent request, in seconds",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NTPServerOutgoingResponsesTotal = prometheus.NewDesc(
|
c.ntpServerOutgoingResponsesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ntp_server_outgoing_responses_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "ntp_server_outgoing_responses_total"),
|
||||||
"Total number of requests responded to by NTP server",
|
"Total number of requests responded to by NTP server",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.NTPServerIncomingRequestsTotal = prometheus.NewDesc(
|
c.ntpServerIncomingRequestsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ntp_server_incoming_requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "ntp_server_incoming_requests_total"),
|
||||||
"Total number of requests received by NTP server",
|
"Total number of requests received by NTP server",
|
||||||
nil,
|
nil,
|
||||||
@@ -100,7 +113,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collect(ctx, ch); err != nil {
|
if err := c.collect(ctx, ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting time metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting time metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -108,7 +121,7 @@ func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perflib "Windows Time Service"
|
// Perflib "Windows Time Service".
|
||||||
type windowsTime struct {
|
type windowsTime struct {
|
||||||
ClockFrequencyAdjustmentPPBTotal float64 `perflib:"Clock Frequency Adjustment (ppb)"`
|
ClockFrequencyAdjustmentPPBTotal float64 `perflib:"Clock Frequency Adjustment (ppb)"`
|
||||||
ComputedTimeOffset float64 `perflib:"Computed Time Offset"`
|
ComputedTimeOffset float64 `perflib:"Computed Time Offset"`
|
||||||
@@ -118,39 +131,39 @@ type windowsTime struct {
|
|||||||
NTPServerOutgoingResponsesTotal float64 `perflib:"NTP Server Outgoing Responses"`
|
NTPServerOutgoingResponsesTotal float64 `perflib:"NTP Server Outgoing Responses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
var dst []windowsTime // Single-instance class, array is required but will have single entry.
|
var dst []windowsTime // Single-instance class, array is required but will have single entry.
|
||||||
if err := perflib.UnmarshalObject(ctx.PerfObjects["Windows Time Service"], &dst, c.logger); err != nil {
|
if err := perflib.UnmarshalObject(ctx.PerfObjects["Windows Time Service"], &dst, c.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ClockFrequencyAdjustmentPPBTotal,
|
c.clockFrequencyAdjustmentPPBTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].ClockFrequencyAdjustmentPPBTotal,
|
dst[0].ClockFrequencyAdjustmentPPBTotal,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ComputedTimeOffset,
|
c.computedTimeOffset,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].ComputedTimeOffset/1000000, // microseconds -> seconds
|
dst[0].ComputedTimeOffset/1000000, // microseconds -> seconds
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NTPClientTimeSourceCount,
|
c.ntpClientTimeSourceCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].NTPClientTimeSourceCount,
|
dst[0].NTPClientTimeSourceCount,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NTPRoundtripDelay,
|
c.ntpRoundTripDelay,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
dst[0].NTPRoundtripDelay/1000000, // microseconds -> seconds
|
dst[0].NTPRoundtripDelay/1000000, // microseconds -> seconds
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NTPServerIncomingRequestsTotal,
|
c.ntpServerIncomingRequestsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].NTPServerIncomingRequestsTotal,
|
dst[0].NTPServerIncomingRequestsTotal,
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.NTPServerOutgoingResponsesTotal,
|
c.ntpServerOutgoingResponsesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
dst[0].NTPServerOutgoingResponsesTotal,
|
dst[0].NTPServerOutgoingResponsesTotal,
|
||||||
)
|
)
|
||||||
|
|||||||
36
pkg/collector/types.go
Normal file
36
pkg/collector/types.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/alecthomas/kingpin/v2"
|
||||||
|
"github.com/go-kit/log"
|
||||||
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Collectors struct {
|
||||||
|
logger log.Logger
|
||||||
|
|
||||||
|
collectors Map
|
||||||
|
perfCounterQuery string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Map map[string]Collector
|
||||||
|
|
||||||
|
type (
|
||||||
|
Builder func(logger log.Logger) Collector
|
||||||
|
BuilderWithFlags[C Collector] func(*kingpin.Application) C
|
||||||
|
)
|
||||||
|
|
||||||
|
// Collector interface that a collector has to implement.
|
||||||
|
type Collector interface {
|
||||||
|
Build() error
|
||||||
|
// Close closes the collector
|
||||||
|
Close() error
|
||||||
|
// GetName get the name of the collector
|
||||||
|
GetName() string
|
||||||
|
// GetPerfCounter returns the perf counter required by the collector
|
||||||
|
GetPerfCounter() ([]string, error)
|
||||||
|
// Collect Get new metrics and expose them via prometheus registry.
|
||||||
|
Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) (err error)
|
||||||
|
SetLogger(logger log.Logger)
|
||||||
|
}
|
||||||
@@ -20,165 +20,178 @@ type Config struct{}
|
|||||||
|
|
||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
// A collector is a Prometheus collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics.
|
||||||
type collector struct {
|
type Collector struct {
|
||||||
|
config Config
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
MemActive *prometheus.Desc
|
memActive *prometheus.Desc
|
||||||
MemBallooned *prometheus.Desc
|
memBallooned *prometheus.Desc
|
||||||
MemLimit *prometheus.Desc
|
memLimit *prometheus.Desc
|
||||||
MemMapped *prometheus.Desc
|
memMapped *prometheus.Desc
|
||||||
MemOverhead *prometheus.Desc
|
memOverhead *prometheus.Desc
|
||||||
MemReservation *prometheus.Desc
|
memReservation *prometheus.Desc
|
||||||
MemShared *prometheus.Desc
|
memShared *prometheus.Desc
|
||||||
MemSharedSaved *prometheus.Desc
|
memSharedSaved *prometheus.Desc
|
||||||
MemShares *prometheus.Desc
|
memShares *prometheus.Desc
|
||||||
MemSwapped *prometheus.Desc
|
memSwapped *prometheus.Desc
|
||||||
MemTargetSize *prometheus.Desc
|
memTargetSize *prometheus.Desc
|
||||||
MemUsed *prometheus.Desc
|
memUsed *prometheus.Desc
|
||||||
|
|
||||||
CpuLimitMHz *prometheus.Desc
|
cpuLimitMHz *prometheus.Desc
|
||||||
CpuReservationMHz *prometheus.Desc
|
cpuReservationMHz *prometheus.Desc
|
||||||
CpuShares *prometheus.Desc
|
cpuShares *prometheus.Desc
|
||||||
CpuStolenTotal *prometheus.Desc
|
cpuStolenTotal *prometheus.Desc
|
||||||
CpuTimeTotal *prometheus.Desc
|
cpuTimeTotal *prometheus.Desc
|
||||||
EffectiveVMSpeedMHz *prometheus.Desc
|
effectiveVMSpeedMHz *prometheus.Desc
|
||||||
HostProcessorSpeedMHz *prometheus.Desc
|
hostProcessorSpeedMHz *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger log.Logger, _ *Config) types.Collector {
|
func New(logger log.Logger, config *Config) *Collector {
|
||||||
c := &collector{}
|
if config == nil {
|
||||||
|
config = &ConfigDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &Collector{
|
||||||
|
config: *config,
|
||||||
|
}
|
||||||
|
|
||||||
c.SetLogger(logger)
|
c.SetLogger(logger)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithFlags(_ *kingpin.Application) types.Collector {
|
func NewWithFlags(_ *kingpin.Application) *Collector {
|
||||||
return &collector{}
|
return &Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetName() string {
|
func (c *Collector) GetName() string {
|
||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) SetLogger(logger log.Logger) {
|
func (c *Collector) SetLogger(logger log.Logger) {
|
||||||
c.logger = log.With(logger, "collector", Name)
|
c.logger = log.With(logger, "collector", Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) GetPerfCounter() ([]string, error) {
|
func (c *Collector) GetPerfCounter() ([]string, error) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) Build() error {
|
func (c *Collector) Close() error {
|
||||||
c.MemActive = prometheus.NewDesc(
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Collector) Build() error {
|
||||||
|
c.memActive = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_active_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_active_bytes"),
|
||||||
"(MemActiveMB)",
|
"(MemActiveMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemBallooned = prometheus.NewDesc(
|
c.memBallooned = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_ballooned_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_ballooned_bytes"),
|
||||||
"(MemBalloonedMB)",
|
"(MemBalloonedMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemLimit = prometheus.NewDesc(
|
c.memLimit = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_limit_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_limit_bytes"),
|
||||||
"(MemLimitMB)",
|
"(MemLimitMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemMapped = prometheus.NewDesc(
|
c.memMapped = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_mapped_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_mapped_bytes"),
|
||||||
"(MemMappedMB)",
|
"(MemMappedMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemOverhead = prometheus.NewDesc(
|
c.memOverhead = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_overhead_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_overhead_bytes"),
|
||||||
"(MemOverheadMB)",
|
"(MemOverheadMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemReservation = prometheus.NewDesc(
|
c.memReservation = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_reservation_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_reservation_bytes"),
|
||||||
"(MemReservationMB)",
|
"(MemReservationMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemShared = prometheus.NewDesc(
|
c.memShared = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_shared_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_shared_bytes"),
|
||||||
"(MemSharedMB)",
|
"(MemSharedMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemSharedSaved = prometheus.NewDesc(
|
c.memSharedSaved = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_shared_saved_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_shared_saved_bytes"),
|
||||||
"(MemSharedSavedMB)",
|
"(MemSharedSavedMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemShares = prometheus.NewDesc(
|
c.memShares = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_shares"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_shares"),
|
||||||
"(MemShares)",
|
"(MemShares)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemSwapped = prometheus.NewDesc(
|
c.memSwapped = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_swapped_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_swapped_bytes"),
|
||||||
"(MemSwappedMB)",
|
"(MemSwappedMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemTargetSize = prometheus.NewDesc(
|
c.memTargetSize = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_target_size_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_target_size_bytes"),
|
||||||
"(MemTargetSizeMB)",
|
"(MemTargetSizeMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.MemUsed = prometheus.NewDesc(
|
c.memUsed = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_used_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_used_bytes"),
|
||||||
"(MemUsedMB)",
|
"(MemUsedMB)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.CpuLimitMHz = prometheus.NewDesc(
|
c.cpuLimitMHz = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_limit_mhz"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_limit_mhz"),
|
||||||
"(CpuLimitMHz)",
|
"(CpuLimitMHz)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CpuReservationMHz = prometheus.NewDesc(
|
c.cpuReservationMHz = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_reservation_mhz"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_reservation_mhz"),
|
||||||
"(CpuReservationMHz)",
|
"(CpuReservationMHz)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CpuShares = prometheus.NewDesc(
|
c.cpuShares = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_shares"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_shares"),
|
||||||
"(CpuShares)",
|
"(CpuShares)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CpuStolenTotal = prometheus.NewDesc(
|
c.cpuStolenTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_stolen_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_stolen_seconds_total"),
|
||||||
"(CpuStolenMs)",
|
"(CpuStolenMs)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.CpuTimeTotal = prometheus.NewDesc(
|
c.cpuTimeTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cpu_time_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cpu_time_seconds_total"),
|
||||||
"(CpuTimePercents)",
|
"(CpuTimePercents)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.EffectiveVMSpeedMHz = prometheus.NewDesc(
|
c.effectiveVMSpeedMHz = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "effective_vm_speed_mhz"),
|
prometheus.BuildFQName(types.Namespace, Name, "effective_vm_speed_mhz"),
|
||||||
"(EffectiveVMSpeedMHz)",
|
"(EffectiveVMSpeedMHz)",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
c.HostProcessorSpeedMHz = prometheus.NewDesc(
|
c.hostProcessorSpeedMHz = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "host_processor_speed_mhz"),
|
prometheus.BuildFQName(types.Namespace, Name, "host_processor_speed_mhz"),
|
||||||
"(HostProcessorSpeedMHz)",
|
"(HostProcessorSpeedMHz)",
|
||||||
nil,
|
nil,
|
||||||
@@ -189,7 +202,7 @@ func (c *collector) Build() error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
if err := c.collectMem(ch); err != nil {
|
if err := c.collectMem(ch); err != nil {
|
||||||
_ = level.Error(c.logger).Log("msg", "failed collecting vmware memory metrics", "err", err)
|
_ = level.Error(c.logger).Log("msg", "failed collecting vmware memory metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -226,7 +239,7 @@ type Win32_PerfRawData_vmGuestLib_VCPU struct {
|
|||||||
HostProcessorSpeedMHz uint64
|
HostProcessorSpeedMHz uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectMem(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectMem(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -237,73 +250,73 @@ func (c *collector) collectMem(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemActive,
|
c.memActive,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemActiveMB),
|
mbToBytes(dst[0].MemActiveMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemBallooned,
|
c.memBallooned,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemBalloonedMB),
|
mbToBytes(dst[0].MemBalloonedMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemLimit,
|
c.memLimit,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemLimitMB),
|
mbToBytes(dst[0].MemLimitMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemMapped,
|
c.memMapped,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemMappedMB),
|
mbToBytes(dst[0].MemMappedMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemOverhead,
|
c.memOverhead,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemOverheadMB),
|
mbToBytes(dst[0].MemOverheadMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemReservation,
|
c.memReservation,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemReservationMB),
|
mbToBytes(dst[0].MemReservationMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemShared,
|
c.memShared,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemSharedMB),
|
mbToBytes(dst[0].MemSharedMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemSharedSaved,
|
c.memSharedSaved,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemSharedSavedMB),
|
mbToBytes(dst[0].MemSharedSavedMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemShares,
|
c.memShares,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].MemShares),
|
float64(dst[0].MemShares),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemSwapped,
|
c.memSwapped,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemSwappedMB),
|
mbToBytes(dst[0].MemSwappedMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemTargetSize,
|
c.memTargetSize,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemTargetSizeMB),
|
mbToBytes(dst[0].MemTargetSizeMB),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.MemUsed,
|
c.memUsed,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
mbToBytes(dst[0].MemUsedMB),
|
mbToBytes(dst[0].MemUsedMB),
|
||||||
)
|
)
|
||||||
@@ -315,7 +328,7 @@ func mbToBytes(mb uint64) float64 {
|
|||||||
return float64(mb * 1024 * 1024)
|
return float64(mb * 1024 * 1024)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) collectCpu(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectCpu(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
||||||
q := wmi.QueryAll(&dst, c.logger)
|
q := wmi.QueryAll(&dst, c.logger)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
@@ -326,43 +339,43 @@ func (c *collector) collectCpu(ch chan<- prometheus.Metric) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CpuLimitMHz,
|
c.cpuLimitMHz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].CpuLimitMHz),
|
float64(dst[0].CpuLimitMHz),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CpuReservationMHz,
|
c.cpuReservationMHz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].CpuReservationMHz),
|
float64(dst[0].CpuReservationMHz),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CpuShares,
|
c.cpuShares,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].CpuShares),
|
float64(dst[0].CpuShares),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CpuStolenTotal,
|
c.cpuStolenTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].CpuStolenMs)*perflib.TicksToSecondScaleFactor,
|
float64(dst[0].CpuStolenMs)*perflib.TicksToSecondScaleFactor,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.CpuTimeTotal,
|
c.cpuTimeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(dst[0].CpuTimePercents)*perflib.TicksToSecondScaleFactor,
|
float64(dst[0].CpuTimePercents)*perflib.TicksToSecondScaleFactor,
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.EffectiveVMSpeedMHz,
|
c.effectiveVMSpeedMHz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].EffectiveVMSpeedMHz),
|
float64(dst[0].EffectiveVMSpeedMHz),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.HostProcessorSpeedMHz,
|
c.hostProcessorSpeedMHz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].HostProcessorSpeedMHz),
|
float64(dst[0].HostProcessorSpeedMHz),
|
||||||
)
|
)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -37,44 +37,29 @@ type Resolver struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewResolver returns a Resolver structure.
|
// NewResolver returns a Resolver structure.
|
||||||
func NewResolver(file string, logger log.Logger, insecure_skip_verify bool) (*Resolver, error) {
|
func NewResolver(file string, logger log.Logger, insecureSkipVerify bool) (*Resolver, error) {
|
||||||
flags := map[string]string{}
|
flags := map[string]string{}
|
||||||
var fileBytes []byte
|
var fileBytes []byte
|
||||||
var err error
|
var err error
|
||||||
if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") {
|
if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") {
|
||||||
_ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file from URL: %v", file))
|
fileBytes, err = readFromURL(file, logger, insecureSkipVerify)
|
||||||
tr := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure_skip_verify},
|
|
||||||
}
|
|
||||||
if insecure_skip_verify {
|
|
||||||
_ = level.Warn(logger).Log("msg", "Loading configuration file with TLS verification disabled")
|
|
||||||
}
|
|
||||||
client := &http.Client{Transport: tr}
|
|
||||||
resp, err := client.Get(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
fileBytes, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file: %v", file))
|
fileBytes, err = readFromFile(file, logger)
|
||||||
if _, err := os.Stat(file); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
fileBytes, err = os.ReadFile(file)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var rawValues map[string]interface{}
|
var rawValues map[string]interface{}
|
||||||
|
|
||||||
err = yaml.Unmarshal(fileBytes, &rawValues)
|
err = yaml.Unmarshal(fileBytes, &rawValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flatten nested YAML values
|
// Flatten nested YAML values
|
||||||
flattenedValues := flatten(rawValues)
|
flattenedValues := flatten(rawValues)
|
||||||
for k, v := range flattenedValues {
|
for k, v := range flattenedValues {
|
||||||
@@ -82,9 +67,51 @@ func NewResolver(file string, logger log.Logger, insecure_skip_verify bool) (*Re
|
|||||||
flags[k] = v
|
flags[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Resolver{flags: flags}, nil
|
return &Resolver{flags: flags}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readFromFile(file string, logger log.Logger) ([]byte, error) {
|
||||||
|
_ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file: %v", file))
|
||||||
|
if _, err := os.Stat(file); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fileBytes, err := os.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileBytes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func readFromURL(file string, logger log.Logger, insecureSkipVerify bool) ([]byte, error) {
|
||||||
|
_ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file from URL: %v", file))
|
||||||
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify}, //nolint:gosec
|
||||||
|
}
|
||||||
|
|
||||||
|
if insecureSkipVerify {
|
||||||
|
_ = level.Warn(logger).Log("msg", "Loading configuration file with TLS verification disabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{Transport: tr}
|
||||||
|
|
||||||
|
resp, err := client.Get(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
fileBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileBytes, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Resolver) setDefault(v getFlagger) {
|
func (c *Resolver) setDefault(v getFlagger) {
|
||||||
for name, value := range c.flags {
|
for name, value := range c.flags {
|
||||||
f := v.GetFlag(name)
|
f := v.GetFlag(name)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
//
|
//
|
||||||
// All keys will be joined by dot
|
// All keys will be joined by dot
|
||||||
// e.g. {"a": {"b":"c"}} => {"a.b":"c"}
|
// e.g. {"a": {"b":"c"}} => {"a.b":"c"}
|
||||||
// or {"a": {"b":[1,2]}} => {"a.b.0":1, "a.b.1": 2}
|
// or {"a": {"b":[1,2]}} => {"a.b.0":1, "a.b.1": 2}.
|
||||||
func flatten(data map[string]interface{}) map[string]string {
|
func flatten(data map[string]interface{}) map[string]string {
|
||||||
ret := make(map[string]string)
|
ret := make(map[string]string)
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
@@ -32,6 +32,7 @@ func flatten(data map[string]interface{}) map[string]string {
|
|||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func flattenSlice(data []interface{}) map[string]string {
|
func flattenSlice(data []interface{}) map[string]string {
|
||||||
ret := make(map[string]string)
|
ret := make(map[string]string)
|
||||||
for idx, v := range data {
|
for idx, v := range data {
|
||||||
@@ -58,7 +59,9 @@ func flattenSlice(data []interface{}) map[string]string {
|
|||||||
func convertMap(originalMap map[interface{}]interface{}) map[string]interface{} {
|
func convertMap(originalMap map[interface{}]interface{}) map[string]interface{} {
|
||||||
convertedMap := map[string]interface{}{}
|
convertedMap := map[string]interface{}{}
|
||||||
for key, value := range originalMap {
|
for key, value := range originalMap {
|
||||||
convertedMap[key.(string)] = value
|
if keyString, ok := key.(string); ok {
|
||||||
|
convertedMap[keyString] = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return convertedMap
|
return convertedMap
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unmarshal good configuration file and confirm data is flattened correctly
|
// Unmarshal good configuration file and confirm data is flattened correctly.
|
||||||
func TestConfigFlattening(t *testing.T) {
|
func TestConfigFlattening(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
goodYamlConfig := []byte(`---
|
goodYamlConfig := []byte(`---
|
||||||
|
|
||||||
collectors:
|
collectors:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type wKSTAInfo102 struct {
|
|||||||
wki102_logged_on_users uint32
|
wki102_logged_on_users uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkstationInfo is an idiomatic wrapper of WKSTAInfo102
|
// WorkstationInfo is an idiomatic wrapper of WKSTAInfo102.
|
||||||
type WorkstationInfo struct {
|
type WorkstationInfo struct {
|
||||||
PlatformId uint32
|
PlatformId uint32
|
||||||
ComputerName string
|
ComputerName string
|
||||||
@@ -89,7 +89,7 @@ func netWkstaGetInfo() (wKSTAInfo102, uint32, error) {
|
|||||||
return deref, 0, nil
|
return deref, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWorkstationInfo is an idiomatic wrapper for netWkstaGetInfo
|
// GetWorkstationInfo is an idiomatic wrapper for netWkstaGetInfo.
|
||||||
func GetWorkstationInfo() (WorkstationInfo, error) {
|
func GetWorkstationInfo() (WorkstationInfo, error) {
|
||||||
info, _, err := netWkstaGetInfo()
|
info, _, err := netWkstaGetInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const (
|
|||||||
SL_GEN_STATE_LAST
|
SL_GEN_STATE_LAST
|
||||||
)
|
)
|
||||||
|
|
||||||
// SLIsWindowsGenuineLocal function wrapper
|
// SLIsWindowsGenuineLocal function wrapper.
|
||||||
func SLIsWindowsGenuineLocal() (SL_GENUINE_STATE, error) {
|
func SLIsWindowsGenuineLocal() (SL_GENUINE_STATE, error) {
|
||||||
var genuineState SL_GENUINE_STATE
|
var genuineState SL_GENUINE_STATE
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ type memoryStatusEx struct {
|
|||||||
UllAvailExtendedVirtual uint64
|
UllAvailExtendedVirtual uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemoryStatus is an idiomatic wrapper for MemoryStatusEx
|
// MemoryStatus is an idiomatic wrapper for MemoryStatusEx.
|
||||||
type MemoryStatus struct {
|
type MemoryStatus struct {
|
||||||
MemoryLoad uint32
|
MemoryLoad uint32
|
||||||
TotalPhys uint64
|
TotalPhys uint64
|
||||||
@@ -40,17 +40,17 @@ type wProcessorArchitecture struct {
|
|||||||
WReserved uint16
|
WReserved uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessorArchitecture is an idiomatic wrapper for wProcessorArchitecture
|
// ProcessorArchitecture is an idiomatic wrapper for wProcessorArchitecture.
|
||||||
type ProcessorArchitecture uint16
|
type ProcessorArchitecture uint16
|
||||||
|
|
||||||
// Idiomatic values for wProcessorArchitecture
|
// Idiomatic values for wProcessorArchitecture.
|
||||||
const (
|
const (
|
||||||
AMD64 ProcessorArchitecture = 9
|
AMD64 ProcessorArchitecture = 9
|
||||||
ARM = 5
|
ARM ProcessorArchitecture = 5
|
||||||
ARM64 = 12
|
ARM64 ProcessorArchitecture = 12
|
||||||
IA64 = 6
|
IA64 ProcessorArchitecture = 6
|
||||||
INTEL = 0
|
INTEL ProcessorArchitecture = 0
|
||||||
UNKNOWN = 0xffff
|
UNKNOWN ProcessorArchitecture = 0xffff
|
||||||
)
|
)
|
||||||
|
|
||||||
// LpSystemInfo is a wrapper for LPSYSTEM_INFO
|
// LpSystemInfo is a wrapper for LPSYSTEM_INFO
|
||||||
@@ -68,7 +68,7 @@ type lpSystemInfo struct {
|
|||||||
WProcessorRevision uint16
|
WProcessorRevision uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemInfo is an idiomatic wrapper for LpSystemInfo
|
// SystemInfo is an idiomatic wrapper for LpSystemInfo.
|
||||||
type SystemInfo struct {
|
type SystemInfo struct {
|
||||||
Arch ProcessorArchitecture
|
Arch ProcessorArchitecture
|
||||||
PageSize uint32
|
PageSize uint32
|
||||||
@@ -82,10 +82,10 @@ type SystemInfo struct {
|
|||||||
ProcessorRevision uint16
|
ProcessorRevision uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// WinComputerNameFormat is a wrapper for COMPUTER_NAME_FORMAT
|
// WinComputerNameFormat is a wrapper for COMPUTER_NAME_FORMAT.
|
||||||
type WinComputerNameFormat int
|
type WinComputerNameFormat int
|
||||||
|
|
||||||
// Definitions for WinComputerNameFormat constants
|
// Definitions for WinComputerNameFormat constants.
|
||||||
const (
|
const (
|
||||||
ComputerNameNetBIOS WinComputerNameFormat = iota
|
ComputerNameNetBIOS WinComputerNameFormat = iota
|
||||||
ComputerNameDNSHostname
|
ComputerNameDNSHostname
|
||||||
@@ -112,7 +112,7 @@ func GlobalMemoryStatusEx() (MemoryStatus, error) {
|
|||||||
mse.dwLength = (uint32)(unsafe.Sizeof(mse))
|
mse.dwLength = (uint32)(unsafe.Sizeof(mse))
|
||||||
r1, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mse)))
|
r1, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mse)))
|
||||||
|
|
||||||
if ret := *(*bool)(unsafe.Pointer(&r1)); ret == false {
|
if ret := *(*bool)(unsafe.Pointer(&r1)); !ret {
|
||||||
return MemoryStatus{}, err
|
return MemoryStatus{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type WTSTypeClass int
|
type WTSTypeClass int
|
||||||
|
|
||||||
// The valid values for the WTSTypeClass enumeration
|
// The valid values for the WTSTypeClass enumeration.
|
||||||
const (
|
const (
|
||||||
WTSTypeProcessInfoLevel0 WTSTypeClass = iota
|
WTSTypeProcessInfoLevel0 WTSTypeClass = iota
|
||||||
WTSTypeProcessInfoLevel1
|
WTSTypeProcessInfoLevel1
|
||||||
@@ -129,19 +129,20 @@ func WTSOpenServer(server string) (syscall.Handle, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WTSCloseServer(server syscall.Handle) error {
|
func WTSCloseServer(server syscall.Handle) error {
|
||||||
_, _, err := procWTSCloseServer.Call(uintptr(server))
|
r1, _, err := procWTSCloseServer.Call(uintptr(server))
|
||||||
if err != nil {
|
|
||||||
|
if r1 != 1 {
|
||||||
return fmt.Errorf("failed to close server: %w", err)
|
return fmt.Errorf("failed to close server: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WTSFreeMemoryEx(class WTSTypeClass, pMemory uintptr, NumberOfEntries uint32) error {
|
func WTSFreeMemoryEx(class WTSTypeClass, pMemory uintptr, numberOfEntries uint32) error {
|
||||||
r1, _, err := procWTSFreeMemoryEx.Call(
|
r1, _, err := procWTSFreeMemoryEx.Call(
|
||||||
uintptr(class),
|
uintptr(class),
|
||||||
pMemory,
|
pMemory,
|
||||||
uintptr(NumberOfEntries),
|
uintptr(numberOfEntries),
|
||||||
)
|
)
|
||||||
|
|
||||||
if r1 != 1 {
|
if r1 != 1 {
|
||||||
@@ -181,7 +182,7 @@ func WTSEnumerateSessionsEx(server syscall.Handle, logger log.Logger) ([]WTSSess
|
|||||||
sessionSize := unsafe.Sizeof(sizeTest)
|
sessionSize := unsafe.Sizeof(sizeTest)
|
||||||
|
|
||||||
sessions := make([]WTSSession, 0, count)
|
sessions := make([]WTSSession, 0, count)
|
||||||
for i := uint32(0); i < count; i++ {
|
for i := range count {
|
||||||
curPtr := unsafe.Pointer(sessionInfoPointer + (uintptr(i) * sessionSize))
|
curPtr := unsafe.Pointer(sessionInfoPointer + (uintptr(i) * sessionSize))
|
||||||
data := (*wtsSessionInfo1)(curPtr)
|
data := (*wtsSessionInfo1)(curPtr)
|
||||||
|
|
||||||
|
|||||||
@@ -17,31 +17,32 @@ type windowsExporterService struct{}
|
|||||||
|
|
||||||
var logger *eventlog.Log
|
var logger *eventlog.Log
|
||||||
|
|
||||||
|
//nolint:nonamedreturns
|
||||||
func (s *windowsExporterService) Execute(_ []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
|
func (s *windowsExporterService) Execute(_ []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
|
||||||
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
|
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
|
||||||
changes <- svc.Status{State: svc.StartPending}
|
changes <- svc.Status{State: svc.StartPending}
|
||||||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||||
loop:
|
|
||||||
for {
|
for c := range r {
|
||||||
select {
|
switch c.Cmd {
|
||||||
case c := <-r:
|
case svc.Interrogate:
|
||||||
switch c.Cmd {
|
changes <- c.CurrentStatus
|
||||||
case svc.Interrogate:
|
case svc.Stop, svc.Shutdown:
|
||||||
changes <- c.CurrentStatus
|
_ = logger.Info(100, "Service Stop Received")
|
||||||
case svc.Stop, svc.Shutdown:
|
changes <- svc.Status{State: svc.StopPending}
|
||||||
_ = logger.Info(100, "Service Stop Received")
|
|
||||||
changes <- svc.Status{State: svc.StopPending}
|
return
|
||||||
break loop
|
default:
|
||||||
default:
|
_ = logger.Error(102, fmt.Sprintf("unexpected control request #%d", c))
|
||||||
_ = logger.Error(102, fmt.Sprintf("unexpected control request #%d", c))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var StopCh = make(chan bool)
|
var StopCh = make(chan bool)
|
||||||
|
|
||||||
|
//nolint:gochecknoinits
|
||||||
func init() {
|
func init() {
|
||||||
isService, err := svc.IsWindowsService()
|
isService, err := svc.IsWindowsService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package eventlog
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -54,7 +55,11 @@ type eventlogLogger struct {
|
|||||||
func (l *eventlogLogger) Log(keyvals ...interface{}) error {
|
func (l *eventlogLogger) Log(keyvals ...interface{}) error {
|
||||||
priority := l.prioritySelector(keyvals...)
|
priority := l.prioritySelector(keyvals...)
|
||||||
|
|
||||||
lb := l.getLoggerBuf()
|
lb, err := l.getLoggerBuf()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
defer l.putLoggerBuf(lb)
|
defer l.putLoggerBuf(lb)
|
||||||
if err := lb.logger.Log(keyvals...); err != nil {
|
if err := lb.logger.Log(keyvals...); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -65,7 +70,7 @@ func (l *eventlogLogger) Log(keyvals ...interface{}) error {
|
|||||||
|
|
||||||
msg, err := syscall.UTF16PtrFromString(lb.buf.String())
|
msg, err := syscall.UTF16PtrFromString(lb.buf.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error convert string to UTF-16: %v", err)
|
return fmt.Errorf("error convert string to UTF-16: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ss := []*uint16{msg, nil, nil, nil, nil, nil, nil, nil, nil}
|
ss := []*uint16{msg, nil, nil, nil, nil, nil, nil, nil, nil}
|
||||||
@@ -77,15 +82,19 @@ type loggerBuf struct {
|
|||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *eventlogLogger) getLoggerBuf() *loggerBuf {
|
func (l *eventlogLogger) getLoggerBuf() (*loggerBuf, error) {
|
||||||
lb := l.bufPool.Get().(*loggerBuf)
|
lb, ok := l.bufPool.Get().(*loggerBuf)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("failed to get loggerBuf from pool")
|
||||||
|
}
|
||||||
|
|
||||||
if lb.buf == nil {
|
if lb.buf == nil {
|
||||||
lb.buf = &bytes.Buffer{}
|
lb.buf = &bytes.Buffer{}
|
||||||
lb.logger = l.newLogger(lb.buf)
|
lb.logger = l.newLogger(lb.buf)
|
||||||
} else {
|
} else {
|
||||||
lb.buf.Reset()
|
lb.buf.Reset()
|
||||||
}
|
}
|
||||||
return lb
|
return lb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *eventlogLogger) putLoggerBuf(lb *loggerBuf) {
|
func (l *eventlogLogger) putLoggerBuf(lb *loggerBuf) {
|
||||||
@@ -95,7 +104,7 @@ func (l *eventlogLogger) putLoggerBuf(lb *loggerBuf) {
|
|||||||
// PrioritySelector inspects the list of keyvals and selects an eventlog priority.
|
// PrioritySelector inspects the list of keyvals and selects an eventlog priority.
|
||||||
type PrioritySelector func(keyvals ...interface{}) Priority
|
type PrioritySelector func(keyvals ...interface{}) Priority
|
||||||
|
|
||||||
// defaultPrioritySelector convert a kit/log level into a Windows Eventlog level
|
// defaultPrioritySelector convert a kit/log level into a Windows Eventlog level.
|
||||||
func defaultPrioritySelector(keyvals ...interface{}) Priority {
|
func defaultPrioritySelector(keyvals ...interface{}) Priority {
|
||||||
l := len(keyvals)
|
l := len(keyvals)
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ import (
|
|||||||
promlogflag "github.com/prometheus/common/promlog/flag"
|
promlogflag "github.com/prometheus/common/promlog/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileFlagName is the canonical flag name to configure the log file
|
// FileFlagName is the canonical flag name to configure the log file.
|
||||||
const FileFlagName = "log.file"
|
const FileFlagName = "log.file"
|
||||||
|
|
||||||
// FileFlagHelp is the help description for the log.file flag.
|
// FileFlagHelp is the help description for the log.file flag.
|
||||||
const FileFlagHelp = "Output file of log messages. One of [stdout, stderr, eventlog, <path to log file>]"
|
const FileFlagHelp = "Output file of log messages. One of [stdout, stderr, eventlog, <path to log file>]"
|
||||||
|
|
||||||
// AddFlags adds the flags used by this package to the Kingpin application.
|
// AddFlags adds the flags used by this package to the Kingpin application.
|
||||||
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine)
|
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine).
|
||||||
func AddFlags(a *kingpin.Application, config *log.Config) {
|
func AddFlags(a *kingpin.Application, config *log.Config) {
|
||||||
config.Level = &promlog.AllowedLevel{}
|
config.Level = &promlog.AllowedLevel{}
|
||||||
a.Flag(promlogflag.LevelFlagName, promlogflag.LevelFlagHelp).
|
a.Flag(promlogflag.LevelFlagName, promlogflag.LevelFlagHelp).
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user