Skip to main content

Mac Operating System

Send Mac logs and metrics using Opentelemetry service

note

For a simpler and more efficient way to collect and send metrics, use the Logz.io telemetry collector.

1. Create a Logz.io directory:

sudo mkdir /opt/logzio-agent

2. Download OpenTelemetry tar.gz:

curl -fsSL "https://github.com/logzio/otel-collector-distro/releases/download/v0.111.0/otelcol-logzio-darwin_amd64.tar.gz" >./otelcol-logzio.tar.gz

3. Extract the OpenTelemetry binary:

sudo tar -zxf ./otelcol-logzio.tar.gz --directory /opt/logzio-agent

4. Create the OpenTelemetry config file:

sudo touch /opt/logzio-agent/otel_config.yaml

5. Copy the following OpenTelemetry config content 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:
filelog/localhost_mac_system:
include:
- /var/log/*.log
include_file_path: true
operators:
- type: move
from: attributes["log.file.name"]
to: attributes["log_file_name"]
- type: move
from: attributes["log.file.path"]
to: attributes["log_file_path"]
attributes:
type: agent-mac
hostmetrics/localhost_mac_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-mac-logs
prometheusremotewrite:
endpoint: https://<<LISTENER-HOST>>:8053
headers:
Authorization: Bearer <<PROMETHEUS-METRICS-SHIPPING-TOKEN>>
user-agent: logzio-mac-metrics
resource_to_telemetry_conversion:
enabled: true
target_info:
enabled: false
service:
pipelines:
logs:
receivers:
- filelog/localhost_mac_system
processors:
- resourcedetection/system
exporters: [logzio/logs]
metrics:
receivers:
- hostmetrics/localhost_mac_system
processors:
- resourcedetection/system
- filter
exporters: [prometheusremotewrite]
telemetry:
logs:
level: "info"
metrics:
address: localhost:8888
Important

If OpenTelemetry metrics are already running on port 8888, edit the address field in the config file.

6. Create plist file:

sudo touch /Library/LaunchDaemons/com.logzio.OTELCollector.plist

Copy the plist file's content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.logzio.OTELCollector</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/opt/logzio-agent/logzio_otel_collector.log</string>
<key>ProgramArguments</key>
<array>
<string>/opt/logzio-agent/otelcol-logzio-darwin_amd64</string>
<string>--config</string>
<string>/opt/logzio-agent/otel_config.yaml</string>
</array>
</dict>
</plist>

Manage your OpenTelemetry on Mac

Manage OpenTelemetry on your machine using the following commands:

DescriptionCommand
Start servicesudo launchctl load /Library/LaunchDaemons/com.logzio.OTELCollector.plist
Stop servicesudo launchctl stop com.logzio.OTELCollector
Service logssudo tail -F /opt/logzio-agent/logzio_otel_collector.log
Delete servicesudo launchctl remove com.logzio.OTELCollector sudo rm /Library/LaunchDaemons/com.logzio.OTELCollector.plist