mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-05 18:16:35 +00:00
fix: add missing concurrency lock (#2098)
This commit is contained in:
@@ -143,7 +143,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
},
|
||||
}
|
||||
|
||||
c.queryAllServicesBuffer = make([]byte, 1024*100)
|
||||
c.queryAllServicesBuffer = make([]byte, 1024*200)
|
||||
|
||||
c.info = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||
@@ -242,6 +242,15 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
||||
}
|
||||
|
||||
func (c *Collector) collectWorker(ch chan<- prometheus.Metric, service windows.ENUM_SERVICE_STATUS_PROCESS) {
|
||||
if uintptr(unsafe.Pointer(service.ServiceName)) == uintptr(windows.InvalidHandle) {
|
||||
c.logger.Log(context.Background(), slog.LevelWarn, "failed collecting service info",
|
||||
slog.String("err", "ServiceName is 0xffffffffffffffff"),
|
||||
slog.String("service", fmt.Sprintf("%+v", service)),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
serviceName := windows.UTF16PtrToString(service.ServiceName)
|
||||
|
||||
if c.config.ServiceExclude.MatchString(serviceName) || !c.config.ServiceInclude.MatchString(serviceName) {
|
||||
@@ -375,6 +384,8 @@ func (c *Collector) queryAllServices() ([]windows.ENUM_SERVICE_STATUS_PROCESS, e
|
||||
err error
|
||||
)
|
||||
|
||||
clear(c.queryAllServicesBuffer)
|
||||
|
||||
for {
|
||||
currentBufferSize := uint32(cap(c.queryAllServicesBuffer))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user