Skip to content

Commit

Permalink
logical_disk: Implement Perfdata collector (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke authored Oct 6, 2024
1 parent efb20b1 commit 2ef1a5f
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 88 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
- goconst
- gocyclo
- gomnd
- paralleltest
- lll
- maintidx
- mnd
Expand Down
4 changes: 4 additions & 0 deletions internal/collector/cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ import (
func BenchmarkCollector(b *testing.B) {
testutils.FuncBenchmarkCollector(b, cpu.Name, cpu.NewWithFlags)
}

func TestCollector(t *testing.T) {
testutils.TestCollector(t, cpu.New, nil)
}
4 changes: 4 additions & 0 deletions internal/collector/cpu_info/cpu_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ import (
func BenchmarkCollector(b *testing.B) {
testutils.FuncBenchmarkCollector(b, cpu_info.Name, cpu_info.NewWithFlags)
}

func TestCollector(t *testing.T) {
testutils.TestCollector(t, cpu_info.New, nil)
}
4 changes: 4 additions & 0 deletions internal/collector/dhcp/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (c *Collector) GetName() string {
}

func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
if utils.PDHEnabled() {
return []string{}, nil
}

return []string{"DHCP Server"}, nil
}

Expand Down
18 changes: 9 additions & 9 deletions internal/collector/filetime/filetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
const Name = "filetime"

type Config struct {
filePatterns []string
FilePatterns []string
}

var ConfigDefaults = Config{
filePatterns: []string{},
FilePatterns: []string{},
}

// A Collector is a Prometheus Collector for collecting file times.
Expand All @@ -39,8 +39,8 @@ func New(config *Config) *Collector {
config = &ConfigDefaults
}

if config.filePatterns == nil {
config.filePatterns = ConfigDefaults.filePatterns
if config.FilePatterns == nil {
config.FilePatterns = ConfigDefaults.FilePatterns
}

c := &Collector{
Expand All @@ -54,18 +54,18 @@ func NewWithFlags(app *kingpin.Application) *Collector {
c := &Collector{
config: ConfigDefaults,
}
c.config.filePatterns = make([]string, 0)
c.config.FilePatterns = make([]string, 0)

var filePatterns string

app.Flag(
"collector.filetime.file-patterns",
"Comma-separated list of file patterns. Each pattern is a glob pattern that can contain `*`, `?`, and `**` (recursive). See https://github.com/bmatcuk/doublestar#patterns",
).Default(strings.Join(ConfigDefaults.filePatterns, ",")).StringVar(&filePatterns)
).Default(strings.Join(ConfigDefaults.FilePatterns, ",")).StringVar(&filePatterns)

app.Action(func(*kingpin.ParseContext) error {
// doublestar.Glob() requires forward slashes
c.config.filePatterns = strings.Split(filepath.ToSlash(filePatterns), ",")
c.config.FilePatterns = strings.Split(filepath.ToSlash(filePatterns), ",")

return nil
})
Expand Down Expand Up @@ -97,7 +97,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
nil,
)

for _, filePattern := range c.config.filePatterns {
for _, filePattern := range c.config.FilePatterns {
basePath, pattern := doublestar.SplitPattern(filePattern)

_, err := doublestar.Glob(os.DirFS(basePath), pattern, doublestar.WithFilesOnly())
Expand All @@ -121,7 +121,7 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
func (c *Collector) collectGlob(logger *slog.Logger, ch chan<- prometheus.Metric) error {
wg := sync.WaitGroup{}

for _, filePattern := range c.config.filePatterns {
for _, filePattern := range c.config.FilePatterns {
wg.Add(1)

go func(filePattern string) {
Expand Down
6 changes: 6 additions & 0 deletions internal/collector/filetime/filetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ import (
func BenchmarkCollector(b *testing.B) {
testutils.FuncBenchmarkCollector(b, filetime.Name, filetime.NewWithFlags)
}

func TestCollector(t *testing.T) {
testutils.TestCollector(t, filetime.New, &filetime.Config{
FilePatterns: []string{"*.*"},
})
}
4 changes: 4 additions & 0 deletions internal/collector/license/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ import (
func BenchmarkCollector(b *testing.B) {
testutils.FuncBenchmarkCollector(b, license.Name, license.NewWithFlags)
}

func TestCollector(t *testing.T) {
testutils.TestCollector(t, license.New, nil)
}
43 changes: 43 additions & 0 deletions internal/collector/logical_disk/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package logical_disk

const (
avgDiskReadQueueLength = "Avg. Disk Read Queue Length"
avgDiskSecPerRead = "Avg. Disk sec/Read"
avgDiskSecPerTransfer = "Avg. Disk sec/Transfer"
avgDiskSecPerWrite = "Avg. Disk sec/Write"
avgDiskWriteQueueLength = "Avg. Disk Write Queue Length"
currentDiskQueueLength = "Current Disk Queue Length"
freeSpace = "Free Megabytes"
diskReadBytesPerSec = "Disk Read Bytes/sec"
diskReadsPerSec = "Disk Reads/sec"
diskWriteBytesPerSec = "Disk Write Bytes/sec"
diskWritesPerSec = "Disk Writes/sec"
percentDiskReadTime = "% Disk Read Time"
percentDiskWriteTime = "% Disk Write Time"
percentFreeSpace = "% Free Space"
percentIdleTime = "% Idle Time"
SplitIOPerSec = "Split IO/Sec"
)

// 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/library/ms803973.aspx - LogicalDisk object reference.
type logicalDisk struct {
Name string
CurrentDiskQueueLength float64 `perflib:"Current Disk Queue Length"`
AvgDiskReadQueueLength float64 `perflib:"Avg. Disk Read Queue Length"`
AvgDiskWriteQueueLength float64 `perflib:"Avg. Disk Write Queue Length"`
DiskReadBytesPerSec float64 `perflib:"Disk Read Bytes/sec"`
DiskReadsPerSec float64 `perflib:"Disk Reads/sec"`
DiskWriteBytesPerSec float64 `perflib:"Disk Write Bytes/sec"`
DiskWritesPerSec float64 `perflib:"Disk Writes/sec"`
PercentDiskReadTime float64 `perflib:"% Disk Read Time"`
PercentDiskWriteTime float64 `perflib:"% Disk Write Time"`
PercentFreeSpace float64 `perflib:"% Free Space_Base"`
PercentFreeSpace_Base float64 `perflib:"Free Megabytes"`
PercentIdleTime float64 `perflib:"% Idle Time"`
SplitIOPerSec float64 `perflib:"Split IO/Sec"`
AvgDiskSecPerRead float64 `perflib:"Avg. Disk sec/Read"`
AvgDiskSecPerWrite float64 `perflib:"Avg. Disk sec/Write"`
AvgDiskSecPerTransfer float64 `perflib:"Avg. Disk sec/Transfer"`
}
Loading

0 comments on commit 2ef1a5f

Please sign in to comment.