K8s Migration Phase 0: Foundation Infrastructure #26
6 changed files with 103 additions and 0 deletions
Add zot_metrics role for Prometheus monitoring
Collects zot_up metric via textfile collector every 60 seconds. Additional metrics can be added later if zot exposes them. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
commit
7d673cbee9
|
|
@ -101,6 +101,8 @@
|
|||
tags: devpi_metrics
|
||||
- role: zot
|
||||
tags: zot
|
||||
- role: zot_metrics
|
||||
tags: zot_metrics
|
||||
- role: plex_metrics
|
||||
tags: plex_metrics
|
||||
- role: postgresql
|
||||
|
|
|
|||
6
ansible/roles/zot_metrics/defaults/main.yml
Normal file
6
ansible/roles/zot_metrics/defaults/main.yml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
zot_metrics_url: http://localhost:5050/v2/_catalog
|
||||
zot_metrics_dir: /opt/homebrew/var/node_exporter/textfile
|
||||
zot_metrics_script: /Users/erichblume/bin/zot-metrics
|
||||
zot_metrics_interval: 60 # seconds between metric collection
|
||||
zot_metrics_log_dir: /opt/homebrew/var/log
|
||||
6
ansible/roles/zot_metrics/handlers/main.yml
Normal file
6
ansible/roles/zot_metrics/handlers/main.yml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- name: Reload zot-metrics
|
||||
ansible.builtin.shell: |
|
||||
launchctl unload ~/Library/LaunchAgents/mcquack.eblume.zot-metrics.plist 2>/dev/null || true
|
||||
launchctl load ~/Library/LaunchAgents/mcquack.eblume.zot-metrics.plist
|
||||
changed_when: true
|
||||
43
ansible/roles/zot_metrics/tasks/main.yml
Normal file
43
ansible/roles/zot_metrics/tasks/main.yml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
- name: Ensure metrics directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ zot_metrics_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Ensure log directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ zot_metrics_log_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Ensure bin directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ zot_metrics_script | dirname }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Deploy zot-metrics script
|
||||
ansible.builtin.template:
|
||||
src: zot-metrics.sh.j2
|
||||
dest: "{{ zot_metrics_script }}"
|
||||
mode: '0755'
|
||||
|
||||
- name: Deploy zot-metrics LaunchAgent plist
|
||||
ansible.builtin.template:
|
||||
src: zot-metrics.plist.j2
|
||||
dest: ~/Library/LaunchAgents/mcquack.eblume.zot-metrics.plist
|
||||
mode: '0644'
|
||||
notify: Reload zot-metrics
|
||||
|
||||
- name: Check if zot-metrics LaunchAgent is loaded
|
||||
ansible.builtin.command: launchctl list mcquack.eblume.zot-metrics
|
||||
register: zot_metrics_launchctl_check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Load zot-metrics LaunchAgent if not loaded
|
||||
ansible.builtin.command: launchctl load ~/Library/LaunchAgents/mcquack.eblume.zot-metrics.plist
|
||||
when: zot_metrics_launchctl_check.rc != 0
|
||||
changed_when: true
|
||||
failed_when: false
|
||||
21
ansible/roles/zot_metrics/templates/zot-metrics.plist.j2
Normal file
21
ansible/roles/zot_metrics/templates/zot-metrics.plist.j2
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?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.zot-metrics</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>{{ zot_metrics_script }}</string>
|
||||
</array>
|
||||
<key>StartInterval</key>
|
||||
<integer>{{ zot_metrics_interval }}</integer>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>{{ zot_metrics_log_dir }}/mcquack.zot-metrics.err.log</string>
|
||||
<key>StandardOutPath</key>
|
||||
<string>{{ zot_metrics_log_dir }}/mcquack.zot-metrics.out.log</string>
|
||||
</dict>
|
||||
</plist>
|
||||
25
ansible/roles/zot_metrics/templates/zot-metrics.sh.j2
Normal file
25
ansible/roles/zot_metrics/templates/zot-metrics.sh.j2
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
# {{ ansible_managed }}
|
||||
# Collects Zot registry metrics for node_exporter textfile collector
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
METRICS_URL="{{ zot_metrics_url }}"
|
||||
OUTPUT_FILE="{{ zot_metrics_dir }}/zot.prom"
|
||||
TEMP_FILE="${OUTPUT_FILE}.tmp"
|
||||
|
||||
# Start output file with header
|
||||
cat > "$TEMP_FILE" << 'HEADER'
|
||||
# HELP zot_up Zot registry is up and responding
|
||||
# TYPE zot_up gauge
|
||||
HEADER
|
||||
|
||||
# Check if zot is up
|
||||
if curl -sf "$METRICS_URL" > /dev/null 2>&1; then
|
||||
echo "zot_up 1" >> "$TEMP_FILE"
|
||||
else
|
||||
echo "zot_up 0" >> "$TEMP_FILE"
|
||||
fi
|
||||
|
||||
# Atomic move
|
||||
mv "$TEMP_FILE" "$OUTPUT_FILE"
|
||||
Loading…
Add table
Add a link
Reference in a new issue