Remove Plex media server (#78)
## Summary - Remove plex_metrics ansible role - Remove Plex Grafana dashboard - Remove Plex log collection from Alloy config - Update indri-services-check to check Jellyfin instead of Plex ## Deployment and Testing - [x] Unloaded plex-metrics LaunchAgent on indri - [x] Deleted plex-metrics plist and script - [x] Deleted plex.prom textfile - [ ] Deploy Alloy config update - [ ] Sync grafana-config to remove dashboard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: https://forge.ops.eblu.me/eblume/blumeops/pulls/78
This commit is contained in:
parent
bcc8685316
commit
b8b33b76c8
12 changed files with 2 additions and 940 deletions
|
|
@ -112,8 +112,6 @@
|
|||
tags: minikube
|
||||
- role: minikube_metrics
|
||||
tags: minikube_metrics
|
||||
- role: plex_metrics
|
||||
tags: plex_metrics
|
||||
- role: jellyfin
|
||||
tags: jellyfin
|
||||
- role: jellyfin_metrics
|
||||
|
|
|
|||
|
|
@ -79,11 +79,6 @@ alloy_mcquack_logs:
|
|||
service: jellyfin
|
||||
stream: stderr
|
||||
|
||||
alloy_plex_logs:
|
||||
- path: /Users/erichblume/Library/Logs/Plex Media Server/Plex Media Server.log
|
||||
service: plex
|
||||
stream: stdout
|
||||
|
||||
# Enable log collection (requires Loki to be running)
|
||||
alloy_collect_logs: true
|
||||
|
||||
|
|
|
|||
|
|
@ -90,15 +90,6 @@ local.file_match "mcquack_logs" {
|
|||
]
|
||||
}
|
||||
|
||||
// Discover log files - Plex Media Server
|
||||
local.file_match "plex_logs" {
|
||||
path_targets = [
|
||||
{% for log in alloy_plex_logs %}
|
||||
{__path__ = "{{ log.path }}", service = "{{ log.service }}", stream = "{{ log.stream }}"},
|
||||
{% endfor %}
|
||||
]
|
||||
}
|
||||
|
||||
// Read and forward brew service logs
|
||||
loki.source.file "brew_logs" {
|
||||
targets = local.file_match.brew_logs.targets
|
||||
|
|
@ -111,12 +102,6 @@ loki.source.file "mcquack_logs" {
|
|||
forward_to = [loki.relabel.add_host.receiver]
|
||||
}
|
||||
|
||||
// Read and forward Plex logs
|
||||
loki.source.file "plex_logs" {
|
||||
targets = local.file_match.plex_logs.targets
|
||||
forward_to = [loki.relabel.add_host.receiver]
|
||||
}
|
||||
|
||||
// Add host label to all logs
|
||||
loki.relabel "add_host" {
|
||||
forward_to = [loki.write.loki.receiver]
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
---
|
||||
# Plex metrics collection configuration
|
||||
|
||||
# Plex server URL
|
||||
plex_metrics_url: "http://localhost:32400"
|
||||
|
||||
# Path to file containing Plex token (should have 600 permissions)
|
||||
plex_metrics_token_file: "/Users/erichblume/.plex-token"
|
||||
|
||||
# Metrics collection interval in seconds
|
||||
plex_metrics_interval: 60
|
||||
|
||||
# Output directory for prometheus textfile collector
|
||||
plex_metrics_dir: /opt/homebrew/var/node_exporter/textfile
|
||||
|
||||
# Script installation path
|
||||
plex_metrics_script: /Users/erichblume/.local/bin/plex-metrics
|
||||
|
||||
# Log directory for metrics script output
|
||||
plex_metrics_log_dir: /opt/homebrew/var/log
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
- name: Reload plex-metrics
|
||||
ansible.builtin.shell: |
|
||||
launchctl unload ~/Library/LaunchAgents/mcquack.eblume.plex-metrics.plist 2>/dev/null || true
|
||||
launchctl load ~/Library/LaunchAgents/mcquack.eblume.plex-metrics.plist
|
||||
changed_when: true
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
# Role ordering is controlled by indri.yml playbook - do not add dependencies here
|
||||
# (Ansible's tag accumulation prevents proper deduplication when using meta dependencies)
|
||||
dependencies: []
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
---
|
||||
- name: Ensure bin directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ plex_metrics_script | dirname }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Deploy plex metrics collection script
|
||||
ansible.builtin.template:
|
||||
src: plex-metrics.sh.j2
|
||||
dest: "{{ plex_metrics_script }}"
|
||||
mode: '0755'
|
||||
notify: Reload plex-metrics
|
||||
|
||||
- name: Deploy plex-metrics LaunchAgent plist
|
||||
ansible.builtin.template:
|
||||
src: plex-metrics.plist.j2
|
||||
dest: ~/Library/LaunchAgents/mcquack.eblume.plex-metrics.plist
|
||||
mode: '0644'
|
||||
notify: Reload plex-metrics
|
||||
|
||||
- name: Check if plex-metrics LaunchAgent is loaded
|
||||
ansible.builtin.command: launchctl list mcquack.eblume.plex-metrics
|
||||
register: plex_metrics_launchctl_check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Load plex-metrics LaunchAgent if not loaded
|
||||
ansible.builtin.command: launchctl load ~/Library/LaunchAgents/mcquack.eblume.plex-metrics.plist
|
||||
when: plex_metrics_launchctl_check.rc != 0
|
||||
changed_when: true
|
||||
failed_when: false
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- {{ ansible_managed }} -->
|
||||
<!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>mcquack.eblume.plex-metrics</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PATH</key>
|
||||
<string>/opt/homebrew/bin:/usr/bin:/bin</string>
|
||||
</dict>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>{{ plex_metrics_script }}</string>
|
||||
</array>
|
||||
<key>StartInterval</key>
|
||||
<integer>{{ plex_metrics_interval }}</integer>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>{{ plex_metrics_log_dir }}/plex-metrics.err.log</string>
|
||||
<key>StandardOutPath</key>
|
||||
<string>{{ plex_metrics_log_dir }}/plex-metrics.out.log</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
#!/bin/bash
|
||||
# {{ ansible_managed }}
|
||||
# Collects Plex Media Server metrics for node_exporter textfile collector
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
PLEX_URL="{{ plex_metrics_url }}"
|
||||
TOKEN_FILE="{{ plex_metrics_token_file }}"
|
||||
OUTPUT_FILE="{{ plex_metrics_dir }}/plex.prom"
|
||||
TEMP_FILE="${OUTPUT_FILE}.tmp"
|
||||
|
||||
# Read token from file
|
||||
get_token() {
|
||||
if [ -f "$TOKEN_FILE" ]; then
|
||||
cat "$TOKEN_FILE" | tr -d '\n'
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# Make API request with optional token
|
||||
api_request() {
|
||||
local endpoint="$1"
|
||||
local use_token="${2:-true}"
|
||||
local token
|
||||
local url="${PLEX_URL}${endpoint}"
|
||||
|
||||
if [ "$use_token" = "true" ]; then
|
||||
token=$(get_token)
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -H "Accept: application/json" -H "X-Plex-Token: $token" "$url" 2>/dev/null
|
||||
else
|
||||
curl -s -H "Accept: application/json" "$url" 2>/dev/null
|
||||
fi
|
||||
else
|
||||
curl -s -H "Accept: application/json" "$url" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
# Initialize metrics
|
||||
plex_up=0
|
||||
plex_version=""
|
||||
plex_sessions_total=0
|
||||
plex_sessions_playing=0
|
||||
plex_sessions_paused=0
|
||||
plex_transcode_sessions_total=0
|
||||
plex_transcode_video=0
|
||||
plex_transcode_audio=0
|
||||
|
||||
# Library metrics will be built dynamically
|
||||
library_metrics=""
|
||||
|
||||
# Check server identity (no auth required)
|
||||
identity=$(api_request "/identity" false)
|
||||
if echo "$identity" | jq -e '.MediaContainer.machineIdentifier' > /dev/null 2>&1; then
|
||||
plex_up=1
|
||||
plex_version=$(echo "$identity" | jq -r '.MediaContainer.version // ""')
|
||||
fi
|
||||
|
||||
# If server is up, get additional metrics (require auth)
|
||||
if [ "$plex_up" -eq 1 ] && [ -f "$TOKEN_FILE" ]; then
|
||||
# Get library sections
|
||||
sections=$(api_request "/library/sections")
|
||||
|
||||
# Process each library using jq
|
||||
while IFS=$'\t' read -r lib_key lib_type lib_title; do
|
||||
if [ -n "$lib_key" ] && [ -n "$lib_type" ]; then
|
||||
# Get library details for item count
|
||||
lib_detail=$(api_request "/library/sections/${lib_key}/all?X-Plex-Container-Start=0&X-Plex-Container-Size=0")
|
||||
lib_size=$(echo "$lib_detail" | jq -r '.MediaContainer.totalSize // .MediaContainer.size // 0')
|
||||
|
||||
library_metrics="${library_metrics}plex_library_items{library=\"${lib_title}\",type=\"${lib_type}\"} ${lib_size}
|
||||
"
|
||||
fi
|
||||
done < <(echo "$sections" | jq -r '.MediaContainer.Directory[] | [.key, .type, .title] | @tsv' 2>/dev/null || true)
|
||||
|
||||
# Get active sessions
|
||||
sessions=$(api_request "/status/sessions")
|
||||
if echo "$sessions" | jq -e '.MediaContainer' > /dev/null 2>&1; then
|
||||
plex_sessions_total=$(echo "$sessions" | jq -r '.MediaContainer.size // 0')
|
||||
|
||||
# Count playing vs paused
|
||||
plex_sessions_playing=$(echo "$sessions" | jq -r '[.MediaContainer.Metadata[]? | select(.Player.state == "playing")] | length')
|
||||
plex_sessions_paused=$(echo "$sessions" | jq -r '[.MediaContainer.Metadata[]? | select(.Player.state == "paused")] | length')
|
||||
|
||||
# Count transcode sessions
|
||||
plex_transcode_video=$(echo "$sessions" | jq -r '[.MediaContainer.Metadata[]? | select(.TranscodeSession.videoDecision == "transcode")] | length')
|
||||
plex_transcode_audio=$(echo "$sessions" | jq -r '[.MediaContainer.Metadata[]? | select(.TranscodeSession.audioDecision == "transcode")] | length')
|
||||
plex_transcode_sessions_total=$(echo "$sessions" | jq -r '[.MediaContainer.Metadata[]? | select(.TranscodeSession)] | length')
|
||||
fi
|
||||
fi
|
||||
|
||||
# Write metrics
|
||||
cat > "$TEMP_FILE" << EOF
|
||||
# HELP plex_up Plex Media Server is up and responding
|
||||
# TYPE plex_up gauge
|
||||
plex_up ${plex_up}
|
||||
|
||||
# HELP plex_version_info Plex Media Server version information
|
||||
# TYPE plex_version_info gauge
|
||||
plex_version_info{version="${plex_version}"} 1
|
||||
|
||||
# HELP plex_sessions_total Total number of active Plex sessions
|
||||
# TYPE plex_sessions_total gauge
|
||||
plex_sessions_total ${plex_sessions_total}
|
||||
|
||||
# HELP plex_sessions_playing Number of sessions currently playing
|
||||
# TYPE plex_sessions_playing gauge
|
||||
plex_sessions_playing ${plex_sessions_playing}
|
||||
|
||||
# HELP plex_sessions_paused Number of sessions currently paused
|
||||
# TYPE plex_sessions_paused gauge
|
||||
plex_sessions_paused ${plex_sessions_paused}
|
||||
|
||||
# HELP plex_transcode_sessions_total Number of sessions being transcoded
|
||||
# TYPE plex_transcode_sessions_total gauge
|
||||
plex_transcode_sessions_total ${plex_transcode_sessions_total}
|
||||
|
||||
# HELP plex_transcode_video_sessions Number of sessions transcoding video
|
||||
# TYPE plex_transcode_video_sessions gauge
|
||||
plex_transcode_video_sessions ${plex_transcode_video}
|
||||
|
||||
# HELP plex_transcode_audio_sessions Number of sessions transcoding audio
|
||||
# TYPE plex_transcode_audio_sessions gauge
|
||||
plex_transcode_audio_sessions ${plex_transcode_audio}
|
||||
|
||||
# HELP plex_library_items Number of items in each Plex library
|
||||
# TYPE plex_library_items gauge
|
||||
${library_metrics}
|
||||
EOF
|
||||
|
||||
# Atomic move
|
||||
mv "$TEMP_FILE" "$OUTPUT_FILE"
|
||||
Loading…
Add table
Add a link
Reference in a new issue