Cfn process instrumentation

From masharratt/claude-flow-novice · View interactive version

Cfn process instrumentation is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. Provides comprehensive process instrumentation, monitoring, and automatic resource limiting for CFN Loop agents and orchestration processes. This skill is essential for detecting and preventing memory

How to use this skill

Skill file

CFN Process Instrumentation Skill

Purpose

Provides comprehensive process instrumentation, monitoring, and automatic resource limiting for CFN Loop agents and orchestration processes. This skill is essential for detecting and preventing memory leaks before they impact system performance.

Core Functions

Process Monitoring

Telemetry Collection

Resource Limiting

Usage Patterns

Automatic Instrumentation

#!/usr/bin/env bash

# Source to automatically instrument current process
source "./cfn-process-instrumentation/instrument-process.sh"

# Rest of script runs with monitoring

Manual Process Monitoring

# Monitor specific PID
./cfn-process-instrumentation/instrument-process.sh monitor-pid 12345

# Instrument with custom limits
AGENT_ID="my-agent" CFN_MEMORY_LIMIT="1G" \
    ./instrument-process.sh

Integration in Agent Spawning

#!/usr/bin/env bash

# Load instrumentation before spawning agent
source "./cfn-process-instrumentation/instrument-process.sh"

# Spawn agent with monitoring
npx claude-flow-novice agent "$AGENT_TYPE" \
    --max-memory "$CFN_MEMORY_LIMIT" \
    --timeout "$CFN_TIMEOUT"

Configuration

Environment Variables

Resource Limits

The skill enforces configurable limits:

Telemetry Data Structure

Metrics Format

{
  "agent_id": "agent-123",
  "start_time": "2025-01-06T10:00:00Z",
  "process_id": "12345",
  "memory_limit": "2G",
  "cpu_limit": "80%",
  "timeout": "600",
  "end_time": "2025-01-06T10:05:00Z",
  "exit_code": "0",
  "samples": [
    {
      "timestamp": "2025-01-06T10:01:00Z",
      "memory_kb": "102400",
      "cpu_percent": "15.5",
      "open_files": "45",
      "threads": "8"
    }
  ]
}

Collected Metrics

Integration Points

Orchestration Scripts

#!/usr/bin/env bash

# Load instrumentation for orchestrator
source "./cfn-process-instrumentation/instrument-process.sh"

# Orchestrator runs with monitoring
echo "Starting orchestration with process monitoring"

Agent Templates

#!/usr/bin/env bash

# All agents get automatic instrumentation
source "./cfn-process-instrumentation/instrument-process.sh"

# Agent execution code
echo "Agent execution monitored and resource-limited"

CFN Loop Integration

Safety Features

Graceful Shutdown

Error Handling

Resource Protection

Performance Considerations

Monitoring Overhead

Storage Efficiency

Network Independence

Usage Examples

Basic Agent Monitoring

#!/usr/bin/env bash

# Simple agent with monitoring
source "./cfn-process-instrumentation/instrument-process.sh"

# Agent work here
echo "Performing agent tasks..."

# Monitoring and cleanup automatic

Custom Resource Limits

#!/usr/bin/env bash

# Agent with custom limits
export CFN_MEMORY_LIMIT="1G"
export CFN_CPU_LIMIT="60%"
export CFN_TIMEOUT="300"

source "./cfn-process-instrumentation/instrument-process.sh"

# Agent runs with stricter limits

Background Process Monitoring

#!/usr/bin/env bash

# Start long-running process
./long-running-task &
TASK_PID=$!

# Monitor the background process
./cfn-process-instrumentation/instrument-process.sh monitor-pid $TASK_PID

# Wait for completion
wait $TASK_PID

Monitoring and Alerting

Threshold Alerts

Telemetry Analysis

# Analyze metrics for trends
jq '.samples | map(.memory_kb) | add / length' /tmp/cfn-telemetry/metrics_*.json

# Find processes with high memory usage
find /tmp/cfn-telemetry -name "*.json" -exec jq 'if (.samples | length) > 0 then (.samples[-1].memory_kb | tonumber) else 0 end' {} \;

Integration with Monitoring Systems

Troubleshooting

Common Issues

  1. High monitoring overhead: Increase monitoring interval
  2. Missing tools: Install ps, lsof, jq for full functionality
  3. Permission denied: Check file system permissions for telemetry directory
  4. Process termination: Review and adjust resource limits

Debug Mode

# Enable detailed logging
export CFN_DEBUG=1
source "./cfn-process-instrumentation/instrument-process.sh"

Manual Inspection

# Check current metrics
cat /tmp/cfn-telemetry/metrics_*.json | jq .

# Monitor process manually
ps -p $$ -o pid,rss,pcpu,nlwp,fd

Security Considerations

Data Protection

Process Isolation

Access Control

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.