Skip to content

High CPU usage on Windows when using loki.source.file on IIS logs #6209

@ceisele-r

Description

@ceisele-r

Component(s)

loki.source.file

What's wrong?

When using the following config

loki.source.file "log_scrape_iis" {
 targets = [{
  __address__ = "localhost",
  __path__    = string.format("%s\\inetpub\\logs\\LogFiles\\W3SVC1\\u_ex*.log", sys.env("SystemDrive")),
  instance    = constants.hostname,
  job         = "integrations/iis",
  site        = "Default Web Site",
  },
 ]
 file_match {
  enabled = true
  sync_period = "15m"
 }
 forward_to = [loki.process.logs_integrations_integrations_iis_process.receiver]
}

to scrape IIS log files from the path C:\inetpub\logs\LogFiles\W3SVC1, it causes a high CPU usage for the Alloy process.

Here's the flame graph from the cpu.pprof profile generated using Invoke-WebRequest -Uri "http://localhost:12345/debug/pprof/profile?seconds=30" -OutFile "cpu.pprof":

Image

This is the flame graph from a server where the C:\inetpub\logs\LogFiles\W3SVC1 directory contains ~1.100 logfiles with a filesize of 5-10MB each.

It shows that significant time is spent tailing the files.
It seems that the tailer code calls createFile, GetFileInformationByHandle and CloseHandle indefinitely in a loop for every file causing the high CPU usage.

Steps to reproduce

  1. Use a Windows Server with IIS and some traffic (so logs are generated)
  2. Add the above loki.source.file module to the Alloy config
  3. Start alloy
  4. Watch the process CPU usage

System information

Windows Server 2022 Datacenter

Software version

Grafana Alloy v1.16.1

Configuration

loki.source.file "log_scrape_iis" {
 targets = [{
  __address__ = "localhost",
  __path__    = string.format("%s\\inetpub\\logs\\LogFiles\\W3SVC1\\u_ex*.log", sys.env("SystemDrive")),
  instance    = constants.hostname,
  job         = "integrations/iis",
  site        = "Default Web Site",
  },
 ]
 file_match {
  enabled = true
  sync_period = "15m"
 }
 forward_to = [loki.process.logs_integrations_integrations_iis_process.receiver]
}

Logs


Tip

React with 👍 if this issue is important to you.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions