Skip to main content

Monitoring & Observability

Effective monitoring is crucial for maintaining healthy autonomous agents. PAP provides comprehensive observability through heartbeats, metrics, logs, and distributed tracing.

The Three Pillars of Agent Observability

💓 Heartbeats

Liveness Signals
Lightweight health checks proving agent is alive and responsive

📊 Metrics

Resource Telemetry
CPU, memory, requests, and custom business metrics

📝 Logs

Event Streams
Structured logs for debugging and audit

Heartbeats: The Liveness Channel

Purpose: Prove agent is alive and responsive.
CRITICAL: Heartbeats contain ONLY liveness data. Resource metrics are FORBIDDEN in heartbeats per PAP-RFC-001 §8.2.

Heartbeat Structure

Allowed Fields:
  • mode: EMERGENCY, IDLE, or SLEEP
  • uptime_seconds: How long agent has been running
  • timestamp: When heartbeat was sent
Forbidden in Heartbeats:
  • ❌ CPU usage
  • ❌ Memory usage
  • ❌ Request counts
  • ❌ Any resource or business metrics

Heartbeat Modes

IDLE Mode (Default)

Interval: 30 seconds Use Case: Normal operation

EMERGENCY Mode

Interval: 5 seconds Use Case: Critical operations requiring aggressive monitoring
Use EMERGENCY Sparingly: High-frequency heartbeats increase control plane load. Only use for truly critical situations (e.g., handling financial transactions, emergency alerts).

SLEEP Mode

Interval: 15 minutes Use Case: Background agents with low-priority work
SLEEP Mode Benefits: Reduces control plane load for infrequently-used agents. Perfect for scheduled report generators or monitoring agents that only act occasionally.

Viewing Heartbeats

Retrieve recent heartbeats via API:
Response:

Heartbeat Health Check


Metrics: The Resource Channel

Purpose: Monitor resource usage and business metrics.
Separation is Key: Metrics are sent on a completely separate channel from heartbeats. This separation is PAP’s superpower for zombie prevention.

Metrics Structure

Standard Metrics

Viewing Metrics

Retrieve recent metrics via API:
Response:

Metric Collection Frequency

Recommended: 60 seconds Unlike heartbeats, metrics can be sent less frequently:
  • More frequent = finer granularity, higher storage
  • Less frequent = reduced load, coarser data
Adaptive Frequency: Send metrics more frequently during high activity, less during idle periods to optimize storage.

Alerting on Metrics

High CPU Alert:
Memory Leak Detection:

Logs: The Event Stream

Purpose: Detailed event logs for debugging and audit.

Log Access (Current)

For now, server administrators can access logs via kubectl:

Log API (Coming Soon)

Future API endpoint for log retrieval:

Structured Logging Best Practices

Use structured JSON logs:
Benefits:
  • Parseable by log aggregators
  • Searchable by field
  • Compatible with OpenTelemetry

Log Levels


Kubernetes-Level Monitoring

Pod Health

Check pod status:
Healthy pod:
Unhealthy indicators:
  • CrashLoopBackOff: Pod keeps crashing
  • ImagePullBackOff: Cannot pull container image
  • Pending: Not scheduled (quota/resources)
  • RESTARTS > 0: Pod restarted (check logs)

Resource Usage

Check actual resource consumption:
Output:

Events

View recent Kubernetes events:

Distributed Tracing

PAP supports OpenTelemetry for distributed tracing across agents and tools.

Trace Context Propagation

All PAP messages carry:

Tracing Agent-to-Tool Calls

Viewing Traces (Future)

Integration with Jaeger/Zipkin/Tempo for trace visualization showing:
  • Agent request flow
  • Tool invocations
  • Database queries
  • External API calls

Alerting Strategies

Critical Alerts (Immediate Response)

  1. Agent Unhealthy:
  2. Agent Killed:
  3. Resource Exhaustion:

Warning Alerts (Monitor)

  1. High Error Rate:
  2. Slow Response Times:

Informational (Logging)

  1. State Changes:

Dashboard Recommendations

Agent Health Dashboard

Metrics to Display:
  1. Agent Count by State
    • ACTIVE count (green)
    • PROVISIONED count (yellow)
    • TERMINATED count (grey)
    • KILLED count (red)
  2. Heartbeat Status
    • Agents with recent heartbeat (< 1min ago)
    • Agents with stale heartbeat (1-2min ago)
    • Agents missing heartbeat (> 2min ago)
  3. Resource Utilization
    • CPU usage histogram
    • Memory usage histogram
    • Agents approaching limits
  4. Request Throughput
    • Requests per minute per agent
    • Error rate per agent

Individual Agent Dashboard

Sections:
  1. Status Overview
    • Current state
    • Uptime
    • Last heartbeat time
  2. Resource Graphs (Time Series)
    • CPU usage over time
    • Memory usage over time
  3. Throughput (Time Series)
    • Requests handled per minute
    • Error rate
  4. Recent Events
    • Lifecycle events (last 24h)
    • Log errors (last 1h)
  5. Kubernetes Health
    • Pod status
    • Restart count
    • Resource quota usage

Monitoring Tools Integration

Prometheus

Metrics Endpoint (Future):
Example output:

Grafana

Import Plugged.in Agent dashboard (future):

Datadog / New Relic

Configure agent to export to APM:

Troubleshooting with Monitoring Data

Problem: Agent Not Processing Requests

Diagnosis:
  1. Check heartbeats: Are they arriving?
  2. Check metrics: Is CPU/memory normal?
  3. Check logs: Any errors?
  4. Check Kubernetes: Is pod healthy?
Resolution Path:

Problem: High CPU Usage

Diagnosis:
  1. Check metrics: CPU consistently > 80%?
  2. Check logs: Infinite loop? Expensive operation?
  3. Check traces: Which operations are slow?
Resolution:
  • Optimize hot code paths
  • Increase CPU limit
  • Scale horizontally (future)

Problem: Memory Leak

Diagnosis:
  1. Check metrics: Memory steadily increasing?
  2. Check logs: Out of memory errors?
  3. Take heap snapshot (future feature)
Resolution:
  • Identify leaking resources
  • Fix and redeploy
  • Restart agent as temporary fix

Best Practices Summary

DO: Keep heartbeats lightweight (mode + uptime only)
DO: Send comprehensive metrics on separate channel
DO: Use structured JSON logging
DO: Include trace_id in all logs
DO: Set up alerts for missed heartbeats
DON’T: Mix metrics with heartbeats
DON’T: Use EMERGENCY mode for normal operations
DON’T: Log sensitive data (passwords, tokens)

Next Steps

Lifecycle Management

Understand agent states and transitions

Architecture Deep Dive

Learn about PAP’s dual-profile design