Windows Operating System
Send Windows logs and metrics with OpenTelemetry
For a simpler and more efficient way to collect and send metrics, use the Logz.io telemetry collector.
1. Create a Logz.io directory:
New-Item -Path $env:APPDATA\LogzioAgent -ItemType Directory -Force
2. Download OpenTelemetry tar.gz:
Invoke-WebRequest -Uri "https://github.com/logzio/otel-collector-distro/releases/download/v0.95.0/otelcol-logzio-windows_amd64.zip" -OutFile C:\Users\<<USERNAME>>\Downloads\otelcol-logzio.zip
3. Extract the OpenTelemetry binary:
Expand-Archive -LiteralPath C:\Users\<<USERNAME>>\Downloads\otelcol-logzio.zip -DestinationPath $env:APPDATA\LogzioAgent -Force
4. Create the OpenTelemetry config file:
New-Item -Path $env:APPDATA\LogzioAgent\otel_config.yaml -ItemType File -Force
5. Copy the following into the config file:
Replace <<LOG-SHIPPING-TOKEN>>
, <<LISTENER-HOST>>
, and <<PROMETHEUS-METRICS-SHIPPING-TOKEN>>
with the relevant parameters from your Logz.io account.
receivers:
windowseventlog/application/localhost_windows_system:
channel: Application
exclude_providers:
- LogzioOTELCollector
attributes:
type: agent-windows
windowseventlog/security/localhost_windows_system:
channel: Security
attributes:
type: agent-windows
windowseventlog/system/localhost_windows_system:
channel: System
attributes:
type: agent-windows
hostmetrics/localhost_windows_system:
collection_interval: 15s
scrapers:
cpu:
metrics:
system.cpu.utilization:
enabled: true
disk:
load:
filesystem:
memory:
metrics:
system.memory.utilization:
enabled: true
network:
paging:
process:
mute_process_name_error: true
mute_process_exe_error: true
mute_process_io_error: true
processors:
resourcedetection/system:
detectors: ["system"]
system:
hostname_sources: ["os"]
filter:
metrics:
include:
match_type: strict
metric_names: ["system.cpu.time", "system.cpu.load_average.1m", "system.cpu.load_average.5m", "system.cpu.load_average.15m", "system.cpu.utilization", "system.memory.usage", "system.memory.utilization", "system.filesystem.usage", "system.disk.io", "system.disk.io_time", "system.disk.operation_time", "system.network.connections", "system.network.io", "system.network.packets", "system.network.errors", "process.cpu.time", "process.memory.usage", "process.disk.io", "process.memory.usage", "process.memory.virtual"]
exporters:
logging:
logzio/logs:
account_token: <<LOG-SHIPPING-TOKEN>>
region: <<LOGZIO_ACCOUNT_REGION_CODE>> # Default is US
headers:
user-agent: logzio-windows-logs
prometheusremotewrite:
endpoint: https://<<LISTENER-HOST>>:8053
headers:
Authorization: Bearer <<PROMETHEUS-METRICS-SHIPPING-TOKEN>>
user-agent: logzio-windows-metrics
resource_to_telemetry_conversion:
enabled: true
target_info:
enabled: false
service:
pipelines:
logs:
receivers:
- windowseventlog/application/localhost_windows_system
- windowseventlog/security/localhost_windows_system
- windowseventlog/system/localhost_windows_system
processors:
- resourcedetection/system
exporters: [logzio/logs]
metrics:
receivers:
- hostmetrics/localhost_windows_system
processors:
- resourcedetection/system
- filter
exporters: [prometheusremotewrite]
telemetry:
logs:
level: "info"
metrics:
address: localhost:8888
If OpenTelemetry metrics are already running on port 8888, edit the address
field in the config file.
6. Create the service file:
New-Service -Name LogzioOTELCollector -BinaryPathName "$env:APPDATA\LogzioAgent\otelcol-logzio-windows_amd64.exe --config $env:APPDATA\LogzioAgent\otel_config.yaml" -Description "Collects localhost logs/metrics and sends them to Logz.io."
Optional - Add basic filtering
You can use the filter processor to remove telemetry data based on OTTL (OpenTelemetry Transformation Language) rules. Any telemetry that meets at least one of the specified conditions will be dropped.
For example, to allow span data from services app1, app2, and app3 and drop data from all other services:
processors:
filter/ottl:
error_mode: ignore
traces:
span:
- |
resource.attributes["service.name"] != "app1" and
resource.attributes["service.name"] != "app2" and
resource.attributes["service.name"] != "app3"
metrics:
datapoint:
- metric.name == "k8s.pod.phase" and value_int == 4
logs:
log_record:
- 'IsMatch(body, ".*password.*")'
- 'severity_number < SEVERITY_NUMBER_WARN'
To only drop spans from a service called service1 while keeping all other spans:
processors:
filter/ottl:
error_mode: ignore
traces:
span:
- resource.attributes["service.name"] == "service1"
Learn more about filtering options in OpenTelemetry's Transforming telemetry documentation.
Manage your OpenTelemetry on Localhost
Manage OpenTelemetry on your machine using the following commands:
Description | Command |
---|---|
Start service | Start-Service -Name LogzioOTELCollector |
Stop service | Stop-Service -Name LogzioOTELCollector |
Service logs | eventvwr.msc |
Delete service | Stop-Service -Name LogzioOTELCollector sc.exe DELETE LogzioOTELCollector |