Windows Host Metrics
Monitor Windows server metrics including CPU, memory, disk, network, and processes using OpenTelemetry collector with Last9
Use OpenTelemetry to monitor hostmetrics on Windows machines with Last9.
Prerequisites
Before setting up Windows host metrics monitoring, ensure you have:
- Windows Server 2016 or later, or Windows 10/11
- Administrative access to your Windows server
- OpenTelemetry Collector installation access
- Last9 account with integration credentials
-
Install OpenTelemetry Collector
Download the OpenTelemetry Collector MSI installer from the following link:
https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.118.0/otelcol-contrib_0.118.0_windows_x64.msi -
Prerequisites for Log Collection
Before configuring log collection, ensure the following:
Windows Event Logs
Windows Event Logs are available by default. No additional configuration needed.
IIS Logs (if applicable)
If you want to collect IIS logs, ensure IIS is installed and logging is enabled:
- Default IIS log location:
C:\inetpub\logs\LogFiles\W3SVC1\ - Verify logs are being written:
dir "C:\inetpub\logs\LogFiles\W3SVC1\"
Application Logs (if applicable)
For custom application logs:
- Identify the log file path (e.g.,
E:\MyApp\logs\*.log) - Ensure the OpenTelemetry Collector service account has read permissions
SQL Server Logs (if applicable)
If SQL Server is installed and you want to collect error logs:
- Default SQL Server ERRORLOG location:
C:\Program Files\Microsoft SQL Server\MSSQL*.MSSQLSERVER\MSSQL\Log\ERRORLOG* - SQL Server error logs use UTF-16 LE encoding
- Ensure read permissions for the OpenTelemetry Collector service account
File Permissions
The OpenTelemetry Collector service runs under the
NT AUTHORITY\SYSTEMaccount by default, which should have read access to most log files. If you encounter permission issues, run the following PowerShell command:# Grant read permissions to a specific directoryicacls "E:\path\to\logs" /grant "NT AUTHORITY\SYSTEM:(OI)(CI)R" - Default IIS log location:
-
Configure OpenTelemetry Collector
Use the following configuration for Otel Collector. Create a
config.yamlfile atC:\Program Files\OpenTelemetry Collector\config.yamlwith the following content:receivers:# Windows Event Log receiver for System, Application, and Security logswindowseventlog:channel: Systemmax_reads: 100start_at: endwindowseventlog/application:channel: Applicationmax_reads: 100start_at: endwindowseventlog/security:channel: Securitymax_reads: 100start_at: end# IIS log receiver (if IIS is installed)filelog/iis:include:- 'C:\inetpub\logs\LogFiles\W3SVC*\*.log'include_file_path: truestart_at: endretry_on_failure:enabled: true# Application log receiver (customize path as needed)filelog/application:include:- 'C:\MyApp\logs\*.log'- 'C:\Applications\**\*.log'include_file_path: truestart_at: endretry_on_failure:enabled: true# SQL Server ERRORLOG receiver (if SQL Server is installed)filelog/sqlserver:include:- 'C:\Program Files\Microsoft SQL Server\MSSQL*.MSSQLSERVER\MSSQL\Log\ERRORLOG*'include_file_path: true# SQL Server ERRORLOG is UTF-16 LE; set encoding to avoid null-byte spacingencoding: utf-16lestart_at: endretry_on_failure:enabled: truehostmetrics:collection_interval: 60sscrapers:cpu:metrics:system.cpu.logical.count:enabled: truememory:metrics:system.memory.utilization:enabled: truesystem.memory.limit:enabled: truedisk:filesystem:metrics:system.filesystem.utilization:enabled: truenetwork:paging:load:process:mute_process_user_error: truemute_process_io_error: truemute_process_exe_error: truemetrics:process.cpu.utilization:enabled: trueprocess.memory.utilization:enabled: trueprocessors:batch:timeout: 20ssend_batch_size: 10000send_batch_max_size: 10000resourcedetection/azure:detectors: [env, azure]timeout: 2soverride: falseresourcedetection/system:detectors: ["system"]system:hostname_sources: ["os"]transform/logs:log_statements:- context: resourcestatements:- set(attributes["service.name"], "windows-host") # Change this as needed- set(attributes["deployment.environment"], "production") # Change this as neededtransform/hostmetrics:metric_statements:- context: datapointstatements:- set(attributes["host.name"], resource.attributes["host.name"])- set(attributes["cloud.account.id"], resource.attributes["cloud.account.id"])- set(attributes["cloud.availability_zone"], resource.attributes["cloud.availability_zone"])- set(attributes["cloud.platform"], resource.attributes["cloud.platform"])- set(attributes["cloud.provider"], resource.attributes["cloud.provider"])- set(attributes["cloud.region"], resource.attributes["cloud.region"])- set(attributes["host.type"], resource.attributes["host.type"])- set(attributes["host.image.id"], resource.attributes["host.image.id"])exporters:otlp/last9:endpoint: "{{ .Logs.WriteURL }}"headers:"Authorization": "{{ .Logs.AuthValue }}"debug:verbosity: detailedservice:pipelines:logs:receivers:[windowseventlog,windowseventlog/application,windowseventlog/security,filelog/iis,filelog/application,filelog/sqlserver,]processors:[batch,resourcedetection/system,resourcedetection/azure,transform/logs,]exporters: [otlp/last9]metrics:receivers: [hostmetrics]processors:[batch,resourcedetection/system,resourcedetection/azure,transform/hostmetrics,]exporters: [otlp/last9]Note: The logs pipeline includes all log receivers. You can comment out or remove receivers for log sources that are not available on your system (e.g., if IIS or SQL Server are not installed).
-
Start OpenTelemetry Collector
Configuration File Location
After installing the MSI, the config file should be placed in the installation directory:
C:\Program Files\OpenTelemetry Collector\config.yamlStart the OpenTelemetry Collector Service
Instead of running the executable directly, you need to:
Configure and Start Windows Service (Recommended):
# Set service to start automaticallySet-Service -Name otelcol-contrib -StartupType Automatic# Start the serviceStart-Service otelcol-contrib# Check service statusGet-Service otelcol-contrib# Stop the serviceStop-Service otelcol-contrib# Restart the serviceRestart-Service otelcol-contribUsing sc.exe (Windows Service Control):
Note: If using sc.exe, ensure the service is configured with the correct config file path first.
# Start the servicesc start otelcol-contrib# Check statussc query otelcol-contrib# Stop the servicesc stop otelcol-contribAdditional Service Configuration Methods
Configure the Service Binary Path with sc.exe
# View current service configurationsc qc otelcol-contrib# Modify the service to include config file pathsc config otelcol-contrib binPath= "\"C:\Program Files\OpenTelemetry Collector\otelcol-contrib.exe\" --config \"C:\Program Files\OpenTelemetry Collector\config.yaml\""Important: Note the space after
binPath=- this is required by sc.exe syntax!During Service Installation
If the service isn’t installed yet or you need to reinstall:
# Create/Install the service with config pathsc create otelcol-contrib binPath= "\"C:\Program Files\OpenTelemetry Collector\otelcol-contrib.exe\" --config \"C:\Program Files\OpenTelemetry Collector\config.yaml\" " start= auto DisplayName= "OpenTelemetry Collector Contrib"# Then start itsc start otelcol-contribUsing PowerShell
# View current configurationGet-CimInstance -ClassName Win32_Service -Filter "Name='otelcol-contrib'" | Select-Object Name, PathName# Modify the service$configPath = "C:\Program Files\OpenTelemetry Collector\config.yaml"$binPath = "`"C:\Program Files\OpenTelemetry Collector\otelcol-contrib.exe`" --config `"$configPath`""# Stop service firstStop-Service otelcol-contrib# Update the binary path$service = Get-WmiObject Win32_Service -Filter "Name='otelcol-contrib'"$service.Change($null, $binPath)# Start serviceStart-Service otelcol-contribConfigure Service to Start Automatically
# Set service to start automatically on bootSet-Service -Name otelcol-contrib -StartupType AutomaticCustomize Application Log Paths
Update the
filelog/applicationreceiver to match your application’s log locations:filelog/application:include:- 'C:\YourApp\logs\*.log'- 'D:\Applications\MyService\logs\*.log'- 'C:\ProgramData\CustomApp\**\*.log'
Verification
To verify the setup is working:
-
View Service Logs:
# Check Windows Event Viewer logsGet-EventLog -LogName Application -Source otelcol-contrib -Newest 50# Or open Event Viewer GUIeventvwr.msc# Navigate to: Windows Logs > Application -
Check Service Status:
Get-Service -Name otelcol-contrib -
View Metrics and Logs in Last9:
View the hostmetrics and logs from the Windows machine in Last9:
- Metrics: Look for metrics with prefix
system.*(e.g.,system.cpu.utilization,system.memory.utilization,system.filesystem.utilization) - Logs: Filter by
service.name="windows-host"(or your custom service name) to view collected logs
- Metrics: Look for metrics with prefix
Need Help?
If you encounter any issues or have questions:
- Join our Discord community for real-time support
- Contact our support team at support@last9.io