From f8805932b2699925fa94de423265b55e88e58df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 5 Jul 2025 15:34:04 +0200 Subject: [PATCH] logon: remove logon collector. Use `terminal_services` instead. (#2114) --- .run/all.run.xml | 2 +- Makefile | 2 +- README.md | 6 +- config.yaml | 2 +- docs/README.md | 1 - internal/collector/logon/logon.go | 105 ------------------------- internal/collector/logon/logon_test.go | 34 -------- pkg/collector/collection.go | 2 - pkg/collector/config.go | 3 - pkg/collector/map.go | 2 - tools/e2e-output.txt | 4 - tools/end-to-end-test.ps1 | 4 +- 12 files changed, 8 insertions(+), 159 deletions(-) delete mode 100644 internal/collector/logon/logon.go delete mode 100644 internal/collector/logon/logon_test.go diff --git a/.run/all.run.xml b/.run/all.run.xml index c95df5b6..3bc35cc0 100644 --- a/.run/all.run.xml +++ b/.run/all.run.xml @@ -19,7 +19,7 @@ - + diff --git a/Makefile b/Makefile index 5da2e303..c6dbf64c 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ test: go test -v ./... bench: - go test -v -bench='benchmarkcollector' ./internal/collectors/{cpu,logical_disk,physical_disk,logon,memory,net,printer,process,service,system,tcp,time} + go test -v -bench='benchmarkcollector' ./internal/collectors/{cpu,logical_disk,physical_disk,memory,net,printer,process,service,system,tcp,time} lint: golangci-lint -c .golangci.yaml run diff --git a/README.md b/README.md index 96722037..01cd1f52 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ msiexec /i --% ADDLOCAL=FirewallException APPLICATIONFOLDER=" On some older versions of Windows, you may need to surround parameter values with double quotes to get the installation command parsing properly: ```powershell -msiexec /i C:\Users\Administrator\Downloads\windows_exporter.msi --% ENABLED_COLLECTORS="ad,iis,logon,memory,process,tcp,textfile,thermalzone" TEXTFILE_DIRS="C:\custom_metrics\" +msiexec /i C:\Users\Administrator\Downloads\windows_exporter.msi --% ENABLED_COLLECTORS="ad,iis,memory,process,tcp,textfile,thermalzone" TEXTFILE_DIRS="C:\custom_metrics\" ``` To install the exporter with creating a firewall exception, use the following command: @@ -194,7 +194,7 @@ See detailed steps to install on Windows Kubernetes [here](./kubernetes/kubernet `windows_exporter` supports Windows Server versions 2016 and later, and desktop Windows version 10 and 11 (21H2 or later). -There are known compatibility issues with Windows Server 2012 R2 and earlier versions. +There are known compatibility issues with Windows Server 2012 R2 and earlier versions. ## Usage @@ -258,7 +258,7 @@ An example configuration file can be found [here](docs/example_config.yml). Configuration file values can be mixed with CLI flags. E.G. -`.\windows_exporter.exe --collectors.enabled=cpu,logon` +`.\windows_exporter.exe --collectors.enabled=cpu` ```yaml log: diff --git a/config.yaml b/config.yaml index c4f16ee6..abf80ee4 100644 --- a/config.yaml +++ b/config.yaml @@ -1,7 +1,7 @@ # example configuration file for windows_exporter collectors: - enabled: cpu,cpu_info,exchange,iis,logical_disk,logon,memory,net,os,performancecounter,process,remote_fx,service,system,tcp,time,terminal_services,textfile + enabled: cpu,cpu_info,exchange,iis,logical_disk,memory,net,os,performancecounter,process,remote_fx,service,system,tcp,time,terminal_services,textfile collector: service: include: "windows_exporter" diff --git a/docs/README.md b/docs/README.md index a470a89f..d66c4229 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,7 +20,6 @@ This directory contains documentation of the collectors in the windows_exporter, - [`iis`](collector.iis.md) - [`license`](collector.license.md) - [`logical_disk`](collector.logical_disk.md) -- [`logon`](collector.logon.md) - [`memory`](collector.memory.md) - [`mscluster`](collector.mscluster.md) - [`msmq`](collector.msmq.md) diff --git a/internal/collector/logon/logon.go b/internal/collector/logon/logon.go deleted file mode 100644 index b7bd867d..00000000 --- a/internal/collector/logon/logon.go +++ /dev/null @@ -1,105 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build windows - -package logon - -import ( - "fmt" - "log/slog" - - "github.com/alecthomas/kingpin/v2" - "github.com/prometheus-community/windows_exporter/internal/headers/secur32" - "github.com/prometheus-community/windows_exporter/internal/mi" - "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus/client_golang/prometheus" -) - -const Name = "logon" - -type Config struct{} - -//nolint:gochecknoglobals -var ConfigDefaults = Config{} - -// A Collector is a Prometheus Collector for WMI metrics. -// Deprecated: Use windows_terminal_services_session_info instead. -type Collector struct { - config Config - - sessionInfo *prometheus.Desc -} - -func New(config *Config) *Collector { - if config == nil { - config = &ConfigDefaults - } - - c := &Collector{ - config: *config, - } - - return c -} - -func NewWithFlags(_ *kingpin.Application) *Collector { - return &Collector{} -} - -func (c *Collector) GetName() string { - return Name -} - -func (c *Collector) Close() error { - return nil -} - -func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { - logger.Warn("The logon collector will be removed mid 2025. Use terminal_service instead."+ - " See https://github.com/prometheus-community/windows_exporter/pull/1957 for more information. If you see values in this collector"+ - " that you need, please open an issue to discuss how to get them into the new collector.", - slog.String("collector", Name), - ) - - c.sessionInfo = prometheus.NewDesc( - prometheus.BuildFQName(types.Namespace, Name, "session_logon_timestamp_seconds"), - "Deprecated. Use windows_terminal_services_session_info instead.", - []string{"id", "username", "domain", "type"}, - nil, - ) - - return nil -} - -// Collect sends the metric values for each metric -// to the provided prometheus Metric channel. -func (c *Collector) Collect(ch chan<- prometheus.Metric) error { - logonSessions, err := secur32.GetLogonSessions() - if err != nil { - return fmt.Errorf("failed to get logon sessions: %w", err) - } - - for _, session := range logonSessions { - ch <- prometheus.MustNewConstMetric( - c.sessionInfo, - prometheus.GaugeValue, - float64(session.LogonTime.UnixMicro())/1e6, - session.LogonId.String(), session.UserName, session.LogonDomain, session.LogonType.String(), - ) - } - - return nil -} diff --git a/internal/collector/logon/logon_test.go b/internal/collector/logon/logon_test.go deleted file mode 100644 index 30c7855f..00000000 --- a/internal/collector/logon/logon_test.go +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// -// Copyright The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build windows - -package logon_test - -import ( - "testing" - - "github.com/prometheus-community/windows_exporter/internal/collector/logon" - "github.com/prometheus-community/windows_exporter/internal/utils/testutils" -) - -func BenchmarkCollector(b *testing.B) { - // No context name required as Collector source is WMI - testutils.FuncBenchmarkCollector(b, logon.Name, logon.NewWithFlags) -} - -func TestCollector(t *testing.T) { - testutils.TestCollector(t, logon.New, nil) -} diff --git a/pkg/collector/collection.go b/pkg/collector/collection.go index f11d1deb..1a6442b5 100644 --- a/pkg/collector/collection.go +++ b/pkg/collector/collection.go @@ -48,7 +48,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/collector/iis" "github.com/prometheus-community/windows_exporter/internal/collector/license" "github.com/prometheus-community/windows_exporter/internal/collector/logical_disk" - "github.com/prometheus-community/windows_exporter/internal/collector/logon" "github.com/prometheus-community/windows_exporter/internal/collector/memory" "github.com/prometheus-community/windows_exporter/internal/collector/mscluster" "github.com/prometheus-community/windows_exporter/internal/collector/msmq" @@ -120,7 +119,6 @@ func NewWithConfig(config Config) *Collection { collectors[iis.Name] = iis.New(&config.IIS) collectors[license.Name] = license.New(&config.License) collectors[logical_disk.Name] = logical_disk.New(&config.LogicalDisk) - collectors[logon.Name] = logon.New(&config.Logon) collectors[memory.Name] = memory.New(&config.Memory) collectors[mscluster.Name] = mscluster.New(&config.MSCluster) collectors[msmq.Name] = msmq.New(&config.Msmq) diff --git a/pkg/collector/config.go b/pkg/collector/config.go index 791247f1..00d7644f 100644 --- a/pkg/collector/config.go +++ b/pkg/collector/config.go @@ -38,7 +38,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/collector/iis" "github.com/prometheus-community/windows_exporter/internal/collector/license" "github.com/prometheus-community/windows_exporter/internal/collector/logical_disk" - "github.com/prometheus-community/windows_exporter/internal/collector/logon" "github.com/prometheus-community/windows_exporter/internal/collector/memory" "github.com/prometheus-community/windows_exporter/internal/collector/mscluster" "github.com/prometheus-community/windows_exporter/internal/collector/msmq" @@ -90,7 +89,6 @@ type Config struct { IIS iis.Config `yaml:"iis"` License license.Config `yaml:"license"` LogicalDisk logical_disk.Config `yaml:"logical_disk"` - Logon logon.Config `yaml:"logon"` Memory memory.Config `yaml:"memory"` MSCluster mscluster.Config `yaml:"mscluster"` Msmq msmq.Config `yaml:"msmq"` @@ -146,7 +144,6 @@ var ConfigDefaults = Config{ IIS: iis.ConfigDefaults, License: license.ConfigDefaults, LogicalDisk: logical_disk.ConfigDefaults, - Logon: logon.ConfigDefaults, Memory: memory.ConfigDefaults, MSCluster: mscluster.ConfigDefaults, Msmq: msmq.ConfigDefaults, diff --git a/pkg/collector/map.go b/pkg/collector/map.go index bf9a8236..776b5e36 100644 --- a/pkg/collector/map.go +++ b/pkg/collector/map.go @@ -42,7 +42,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/collector/iis" "github.com/prometheus-community/windows_exporter/internal/collector/license" "github.com/prometheus-community/windows_exporter/internal/collector/logical_disk" - "github.com/prometheus-community/windows_exporter/internal/collector/logon" "github.com/prometheus-community/windows_exporter/internal/collector/memory" "github.com/prometheus-community/windows_exporter/internal/collector/mscluster" "github.com/prometheus-community/windows_exporter/internal/collector/msmq" @@ -101,7 +100,6 @@ var BuildersWithFlags = map[string]BuilderWithFlags[Collector]{ iis.Name: NewBuilderWithFlags(iis.NewWithFlags), license.Name: NewBuilderWithFlags(license.NewWithFlags), logical_disk.Name: NewBuilderWithFlags(logical_disk.NewWithFlags), - logon.Name: NewBuilderWithFlags(logon.NewWithFlags), memory.Name: NewBuilderWithFlags(memory.NewWithFlags), mscluster.Name: NewBuilderWithFlags(mscluster.NewWithFlags), msmq.Name: NewBuilderWithFlags(msmq.NewWithFlags), diff --git a/tools/e2e-output.txt b/tools/e2e-output.txt index 0c28795a..b091841c 100644 --- a/tools/e2e-output.txt +++ b/tools/e2e-output.txt @@ -118,7 +118,6 @@ windows_exporter_collector_success{collector="cpu"} 1 windows_exporter_collector_success{collector="cpu_info"} 1 windows_exporter_collector_success{collector="cs"} 1 windows_exporter_collector_success{collector="logical_disk"} 1 -windows_exporter_collector_success{collector="logon"} 1 windows_exporter_collector_success{collector="memory"} 1 windows_exporter_collector_success{collector="net"} 1 windows_exporter_collector_success{collector="os"} 1 @@ -140,7 +139,6 @@ windows_exporter_collector_timeout{collector="cpu"} 0 windows_exporter_collector_timeout{collector="cpu_info"} 0 windows_exporter_collector_timeout{collector="cs"} 0 windows_exporter_collector_timeout{collector="logical_disk"} 0 -windows_exporter_collector_timeout{collector="logon"} 0 windows_exporter_collector_timeout{collector="memory"} 0 windows_exporter_collector_timeout{collector="net"} 0 windows_exporter_collector_timeout{collector="os"} 0 @@ -191,8 +189,6 @@ windows_exporter_collector_timeout{collector="udp"} 0 # TYPE windows_logical_disk_write_seconds_total counter # HELP windows_logical_disk_writes_total The number of write operations on the disk (LogicalDisk.DiskWritesPerSec) # TYPE windows_logical_disk_writes_total counter -# HELP windows_logon_session_logon_timestamp_seconds Deprecated. Use windows_terminal_services_session_info instead. -# TYPE windows_logon_session_logon_timestamp_seconds gauge # HELP windows_memory_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 standby (cached), free and zero page lists (AvailableBytes) # TYPE windows_memory_available_bytes gauge # HELP windows_memory_cache_bytes (CacheBytes) diff --git a/tools/end-to-end-test.ps1 b/tools/end-to-end-test.ps1 index 89746057..5f62ad2d 100644 --- a/tools/end-to-end-test.ps1 +++ b/tools/end-to-end-test.ps1 @@ -18,14 +18,14 @@ mkdir $textfile_dir | Out-Null Copy-Item 'e2e-textfile.prom' -Destination "$($textfile_dir)/e2e-textfile.prom" # Omit dynamic collector information that will change after each run -$skip_re = "^(go_|windows_exporter_build_info|windows_exporter_collector_duration_seconds|windows_exporter_scrape_duration_seconds|process_|windows_textfile_mtime_seconds|windows_cpu|windows_cs|windows_cache|windows_logon|windows_pagefile|windows_logical_disk|windows_physical_disk|windows_memory|windows_net|windows_os|windows_process|windows_service_process|windows_printer|windows_udp|windows_tcp|windows_system|windows_time|windows_session|windows_performancecounter|windows_performancecounter|windows_textfile_mtime_seconds)" +$skip_re = "^(go_|windows_exporter_build_info|windows_exporter_collector_duration_seconds|windows_exporter_scrape_duration_seconds|process_|windows_textfile_mtime_seconds|windows_cpu|windows_cs|windows_cache|windows_pagefile|windows_logical_disk|windows_physical_disk|windows_memory|windows_net|windows_os|windows_process|windows_service_process|windows_printer|windows_udp|windows_tcp|windows_system|windows_time|windows_session|windows_performancecounter|windows_performancecounter|windows_textfile_mtime_seconds)" # Start process in background, awaiting HTTP requests. # Use default collectors, port and address: http://localhost:9182/metrics $exporter_proc = Start-Process ` -PassThru ` -FilePath ..\windows_exporter.exe ` - -ArgumentList "--log.level=debug","--web.disable-exporter-metrics","--collectors.enabled=[defaults],cpu_info,textfile,process,pagefile,performancecounter,scheduled_task,tcp,udp,time,system,service,logical_disk,os,net,memory,logon,cache","--collector.process.include=explorer.exe","--collector.scheduled_task.include=.*GAEvents","--collector.service.include=Themes","--collector.textfile.directories=$($textfile_dir)",@" + -ArgumentList "--log.level=debug","--web.disable-exporter-metrics","--collectors.enabled=[defaults],cpu_info,textfile,process,pagefile,performancecounter,scheduled_task,tcp,udp,time,system,service,logical_disk,os,net,memory,cache","--collector.process.include=explorer.exe","--collector.scheduled_task.include=.*GAEvents","--collector.service.include=Themes","--collector.textfile.directories=$($textfile_dir)",@" --collector.performancecounter.objects="[{\"name\":\"cpu\",\"object\":\"Processor Information\",\"instances\":[\"*\"],\"instance_label\":\"core\",\"counters\":[{\"name\":\"% Processor Time\",\"metric\":\"windows_performancecounter_processor_information_processor_time\",\"labels\":{\"state\":\"active\"}},{\"name\":\"% Idle Time\",\"metric\":\"windows_performancecounter_processor_information_processor_time\",\"labels\":{\"state\":\"idle\"}}]},{\"name\":\"memory\",\"object\":\"Memory\",\"counters\":[{\"name\":\"Cache Faults/sec\",\"type\":\"counter\"}]}]" "@ ` -WindowStyle Hidden `