Monitoring Plex with Logship
By Adam Sulucz
Monitoring Plex with Logship
This guide covers setting up Logship to monitor a Plex Media Server in a homelab environment. The instructions are tested on Proxmox LXC running Debian and may require adjustment for other platforms.
- Monitoring Plex with Logship
Prerequisites:
- A running Plex Media Server
- A Logship instance (Getting Started)
Before proceeding, note your Logship backend endpoint and account ID (found under Account Settings in the Logship frontend).
Install the Logship Agent
The Logship Agent collects system metrics, process information, and log files from the host machine. Install it on the same machine as Plex to capture both system-level and application-level telemetry.
Installing on Debian/Ubuntu
Download and install the latest agent release:
# Create installation directory
sudo mkdir -p /opt/logship/agent
cd /opt/logship/agent
# Download the latest release
wget https://github.com/logship-io/logship-agent/releases/latest/download/LogshipAgent-linux-x64.zip
# Extract
unzip LogshipAgent-linux-x64.zip
rm LogshipAgent-linux-x64.zip
# Make executable
chmod +x Logship.Agent.ConsoleHost Configure the Agent
Create the agent configuration at /opt/logship/agent/appsettings.json:
{
"Output": {
"endpoint": "http://localhost:5000",
"account": "00000000-0000-0000-0000-000000000000",
"interval": "00:00:02",
"maximumBufferSize": 40000,
"maximumFlushSize": 15000,
"health": {
"interval": "00:00:05"
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"System.Net.Http.HttpClient.Default": "Warning"
}
},
"Sources": {
"DiskInformation": {
"enabled": true,
"interval": "00:00:05"
},
"LogFile": {
"enabled": true,
"include": [
"*.log",
"PMS Plugin Logs/*.log"
],
"exclude": [
"*.tmp",
"*.bak"
],
"workingDirectory": "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/",
"encoding": "utf-8",
"startAtBeginning": false,
"ignoreCheckpoints": false,
"ignoreOlderSecs": 86400,
"globMinimumCooldownMs": 5000,
"readBufferSize": 65536,
"maxLineBytes": 32768,
"multiline": {
"mode": "start_pattern",
"startPattern": "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}",
"timeoutMs": 5000
}
},
"JournalCtl": {
"enabled": true,
"flags": 0,
"includeFields": ["USERID"],
"filters": [
{
"matchAny": [
{
"hasField": "CONTAINER_NAME"
},
{
"hasField": "SYSLOG_IDENTIFIER"
}
]
}
]
},
"NetworkInformation": {
"enabled": true,
"interval": "00:00:15"
},
"Proc": {
"enabled": true,
"interval": "00:00:05"
},
"Proc.OpenFiles": {
"enabled": true,
"interval": "00:05:00"
},
"ProcessInformation": {
"enabled": true,
"interval": "00:00:30"
},
"SystemInformation": {
"enabled": true,
"interval": "01:00:00"
},
"UDPListener": {
"enabled": true,
"port": 49999
}
}
} Replace the endpoint and account values with your Logship instance details.
The LogFile source reads Plex logs directly from disk with multiline support for Plex's timestamp format, capturing server logs, transcoder logs, and plugin logs.
Systemd Service
Create /etc/systemd/system/logship-agent.service:
[Unit]
Description=Logship Agent
[Service]
ExecStart=/opt/logship/agent/Logship.Agent.ConsoleHost
WorkingDirectory=/opt/logship/agent
Restart=on-failure
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable logship-agent
sudo systemctl start logship-agent Verify it's running:
sudo systemctl status logship-agent Install the Plex Exporter
The Logship Plex Exporter connects to the Plex API and exports session, library, and server metrics. It forwards data to the Logship Agent via UDP.
Obtain Your Plex Token
- Sign in to Plex Web App
- Browse to any media item and click "Get Info"
- Click "View XML"
- Copy the
X-Plex-Tokenparameter from the URL
Alternatively, you can find your token in the Plex preferences file:
grep -oP 'PlexOnlineToken="\K[^"]+' "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Preferences.xml" Install the Plex Exporter
# Create installation directory
sudo mkdir -p /opt/logship/plex-exporter
cd /opt/logship/plex-exporter
# Download the latest release
wget https://github.com/logship-io/logship-plex-exporter/releases/latest/download/LogshipPlexExporter-linux-x64.zip
# Extract
unzip LogshipPlexExporter-linux-x64.zip
rm LogshipPlexExporter-linux-x64.zip
# Make executable
chmod +x Logship.Plex.Exporter.ConsoleHost Configure the Exporter
Create the exporter configuration at /opt/logship/plex-exporter/appsettings.json:
{
"Plex": {
"url": "http://localhost:32400",
"token": "YOUR_PLEX_TOKEN"
},
"Output": {
"type": "udp",
"host": "127.0.0.1",
"port": 49999
},
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"Sources": {
"Sessions": {
"enabled": true,
"interval": "00:00:30"
},
"Libraries": {
"enabled": true,
"interval": "00:05:00"
},
"ServerInfo": {
"enabled": true,
"interval": "00:01:00"
},
"Bandwidth": {
"enabled": true,
"interval": "00:00:30"
}
}
} The exporter forwards metrics to the Logship Agent's UDP listener on port 49999.
Systemd Service
Create /etc/systemd/system/logship-plex-exporter.service:
[Unit]
Description=Logship Plex Exporter
Requires=logship-agent.service plexmediaserver.service
[Service]
ExecStart=/opt/logship/plex-exporter/Logship.Plex.Exporter.ConsoleHost
WorkingDirectory=/opt/logship/plex-exporter
Restart=on-failure
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable logship-plex-exporter
sudo systemctl start logship-plex-exporter Querying Plex Data
Once data collection begins, query your Plex metrics from the Logship Query page.
Server Logs
LogFile
| where timestamp > ago(15m)
| where FilePath contains_cs "Plex Media Server"
| project timestamp, FilePath, Content, LineNumber, ModifiedTime
| order by ModifiedTime asc, timestamp asc
| limit 1000 Library Contents
Plex.Media
| where timestamp > ago(1d)
| project timestamp, Title, Type, Library, LibraryType, Duration, Summary
| limit 100 User Accounts
Plex.Server.Accounts
| where timestamp > ago(1d)
| project timestamp, Id, Name, DefaultAudioLanguage, SubtitleMode
| limit 100 Connected Clients
Plex.Server.Clients
| where timestamp > ago(1d)
| project timestamp, Name, Platform, PlatformVersion, Product, DeviceClass, Address
| limit 100 Registered Devices
Plex.Server.Devices
| where timestamp > ago(1d)
| project timestamp, Id, Name, Platform, ClientIdentifier, CreatedAt
| limit 100 Alerts
Configure alerts in the Logship frontend to receive notifications for key events.
Playback Notifications
Notify when a user starts watching content:
Plex.Sessions.Video
| where timestamp > ago(5m)
| where LibrarySectionTitle != "TV Shows"
| summarize by PlayerUserId, AudienceRating, ContentRating, LibrarySectionTitle, PlayerAddress, PlayerModel, PlayerProduct, PlayerRemotePublicAddress, Summary, Title, Type, Year
| join (
Plex.Server.Accounts
| where timestamp > ago(1d)
| summarize by Id, Name
) on $right.Id == $left.PlayerUserId Settings: Check interval: 1 minute, Deduplicate on: Title, Name
Content template:
# {Name} has started watching {Title} on Plex
## Content Details
* Title: {Title}
* Summary: {Summary}
* Rating: {ContentRating}
* Type: {LibrarySectionTitle} / {Type}
* Year: {Year}
## Player Details
* Address: {PlayerAddress}
* Player: {PlayerModel}
* Public Address: {PlayerRemotePublicAddress} Daily Content Digest
Summarize newly added content:
let age = ago(4d);
let cutoff = ago(1d);
Plex.Media
| where timestamp > age
| project timestamp, Title, Summary, Type, Library
| summarize oldest = agg_min(timestamp) by Title, Summary, Type
| where oldest > cutoff
| summarize
count = count(),
MovieCount = sum(case(Type == "movie", 1, 0)),
ShowCount = sum(case(Type == "episode", 1, 0)),
Values = join("\n* ", Title + " - " + Type + ": " + Summary) Settings: Check interval: Daily, Deduplicate on: Content
Content template:
# Plex Content Summary (Last 24 Hours)
**Movies:** {MovieCount} | **Episodes:** {ShowCount}
{Values} Dashboard
Build a monitoring dashboard with these panels. Navigate to Dashboards in the Logship frontend and click New Dashboard.
Disk Free Space
System.Storage
| where timestamp > $__startTime() and timestamp <= $__endTime()
| where Name contains 'zfs1'
| summarize FreeSpace = agg_min(TotalFreespaceBytes) by timestamp = bin(timestamp, 5m), Name
| sort by timestamp
| project timestamp, FreeSpace, Name
| render timechart with (title = "Disk free space per 5m") Memory Usage by Process
System.Process.Memory
| where timestamp > $__startTime() and timestamp <= $__endTime()
| make-streams executable, machine
| sort by timestamp
| summarize bytes = agg_avg(bytes) by timestamp = bin(timestamp, bucketSize), executable, machine
| project timestamp, bytes, machine, executable
| render timechart with (title = "AVG Memory Usage bytes by process") Set the dashboard refresh interval to 1 minute for real-time monitoring.