#!/bin/bash # P4 health check probe - writes Prometheus metrics to textfile directory # Managed by Ansible - do not edit manually METRICS_DIR="{{ p4prometheus_metrics_dir }}" METRICS_FILE="${METRICS_DIR}/p4_healthcheck.prom" TMP_FILE="${METRICS_FILE}.$$" INSTANCE="{{ perforce_id }}" source /p4/common/bin/p4_vars "$INSTANCE" # Run p4 info and capture timing start_time=$(date +%s%N) p4_output=$(p4 -ztag info 2>&1) p4_rc=$? end_time=$(date +%s%N) duration_ms=$(( (end_time - start_time) / 1000000 )) # Determine if server is up (1) or down (0) if [ $p4_rc -eq 0 ]; then p4_up=1 else p4_up=0 fi cat > "$TMP_FILE" <