File size: 5,055 Bytes
d0e39d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# 🚀 Quick Start - API Monitoring Now Active!

## ⚠️ IMPORTANT: You Must Restart the App

The API monitoring UI has been added to `app.py`, but **it won't appear until you restart the Gradio app**.

## 🎯 Three Ways to Restart:

### Option 1: Use the Restart Script (Recommended)
```bash
cd /home/gpaasch/overgrowth
./RESTART_APP.sh
```

### Option 2: Manual Restart
```bash
# Stop any running instance
pkill -f "python.*app.py"

# Start fresh
cd /home/gpaasch/overgrowth
source venv/bin/activate
nohup python app.py > app.log 2>&1 &

# Check logs
tail -f app.log
```

### Option 3: HuggingFace Space
If deployed to HuggingFace Spaces:
1. Go to your Space settings
2. Click "Restart this Space"
3. Wait for reboot

## 📊 What You'll See After Restart

The **very first section** at the top of the UI will be:

```
🔍 Live API Activity Monitor
Real-time visibility into all API calls - LLM, GNS3, and more

┌─────────────────────────────┬──────────────────────────────────────────┐
│ 📊 Session Statistics       │ 📡 Recent API Calls                      │
├─────────────────────────────┼──────────────────────────────────────────┤
│ Session Duration: 0m 0s     │ *No API calls yet. Start using the      │
│ Total API Calls: 0          │  system to see activity here.*           │
│ LLM Calls: 0                │                                          │
│ GNS3 Calls: 0               │                                          │
│ Total Tokens: 0             │                                          │
│ Total Cost: $0.0000         │                                          │
│ Errors: 0                   │                                          │
│                             │                                          │
│ [🔄 Refresh Stats]          │ [🔄 Refresh Activity]                    │
└─────────────────────────────┴──────────────────────────────────────────┘

---

🌿 Network Automation Pipeline
[Rest of the UI continues below...]
```

## 🎬 Demo Flow for Judges

1. **Page loads** → See API monitor with $0.00 cost

2. **Enter network description** → Click "🚀 Run Full Pipeline"

3. **Watch in real-time** as API calls appear:
   ```
   ✅ 🤖 ANTHROPIC claude-3-haiku-20240307
      📝 1,247→892 tokens | 💰 $0.0043 | ⏱️ 2,314ms
   
   ✅ 🤖 ANTHROPIC claude-3-haiku-20240307  
      📝 2,105→1,543 tokens | 💰 $0.0201 | ⏱️ 3,127ms
   ```

4. **Pipeline completes** → Status shows:
   ```
   💰 API Usage This Session
   - Total Cost: $0.0823
   - LLM Calls: 3 | GNS3 Calls: 5
   - Tokens: 8,456 (4,123 in / 4,333 out)
   ```

5. **Click "🔄 Refresh Stats"** → Dashboard updates instantly

## ✅ Verification Checklist

After restarting, verify these features work:

- [ ] "Live API Activity Monitor" section appears at top
- [ ] Session Statistics shows $0.00 initially
- [ ] Running pipeline populates API calls
- [ ] Each call shows: provider, model, tokens, cost, timing
- [ ] Total cost updates in real-time
- [ ] Refresh buttons work
- [ ] Pipeline status includes API usage summary

## 🐛 Troubleshooting

### "I don't see the API monitor"
→ You didn't restart the app. Run `./RESTART_APP.sh`

### "API calls show but no tokens/costs"
→ This happens with mock responses (no API keys configured)
→ Set `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` in `.env`

### "App won't start"
→ Check logs: `cat app.log`
→ Verify virtual environment: `source venv/bin/activate`

### "Port 7860 in use"
→ Kill existing process: `pkill -f "python.*app.py"`

## 📝 Files Changed

1. **`agent/api_monitor.py`** - New monitoring system (343 lines)
2. **`agent/llm_client.py`** - Added tracking to all LLM calls
3. **`agent/local_mcp.py`** - Added tracking to GNS3 calls
4. **`app.py`** - Added monitoring UI at top of interface
5. **`API_MONITORING.md`** - Full documentation
6. **`RESTART_APP.sh`** - Convenient restart script

## 🎯 Quick Test

```bash
cd /home/gpaasch/overgrowth
source venv/bin/activate

# Test the monitor
python -c "
from agent.api_monitor import monitor
print(monitor.get_stats().format_dashboard())
print(monitor.format_activity_feed())
"

# Should output dashboard and activity feed
```

## 🚀 For Hackathon Submission

Make sure to:
1. ✅ Restart the app before demo
2. ✅ Test with a simple network description  
3. ✅ Show judges the real-time API tracking
4. ✅ Highlight the cost transparency
5. ✅ Mention this is enterprise-grade observability

---

**The monitoring is fully implemented - just restart to see it! 🎉**