-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproduction_ops_example.php
More file actions
102 lines (79 loc) · 2.52 KB
/
Copy pathproduction_ops_example.php
File metadata and controls
102 lines (79 loc) · 2.52 KB
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
<?php
/**
* Production Operations Agents Example
*
* Demonstrates MonitoringAgent, SchedulerAgent, and AlertAgent
* working together for system monitoring and alerting.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use ClaudeAgents\Agents\MonitoringAgent;
use ClaudeAgents\Agents\SchedulerAgent;
use ClaudeAgents\Agents\AlertAgent;
use ClaudeAgents\Monitoring\Metric;
use ClaudeAgents\Monitoring\Alert;
use ClaudePhp\ClaudePhp;
// Load API key
if (file_exists(__DIR__ . '/.env')) {
$env = parse_ini_file(__DIR__ . '/.env');
$_ENV['ANTHROPIC_API_KEY'] = $env['ANTHROPIC_API_KEY'] ?? '';
}
$apiKey = $_ENV['ANTHROPIC_API_KEY'] ?? '';
if (empty($apiKey)) {
die("Error: ANTHROPIC_API_KEY not set\n");
}
$client = new ClaudePhp($apiKey);
echo "Production Operations Agents Demo\n";
echo "==================================\n\n";
// 1. Monitoring Agent Example
echo "1. Monitoring Agent\n";
echo "-------------------\n";
$monitor = new MonitoringAgent($client, [
'thresholds' => [
'cpu_usage' => 80,
'memory_usage' => 90,
'error_rate' => 5,
],
]);
$metrics = <<<METRICS
cpu_usage: 85
memory_usage: 75
error_rate: 3
response_time: 250
METRICS;
$result = $monitor->run($metrics);
echo $result->getAnswer() . "\n\n";
// 2. Alert Agent Example
echo "2. Alert Agent\n";
echo "--------------\n";
$alertAgent = new AlertAgent($client, [
'aggregation_window' => 300, // 5 minutes
]);
// Register alert channels
$alertAgent->registerChannel('log', function (Alert $alert, string $message) {
echo "[ALERT] {$alert->getSeverity()}: {$message}\n";
});
$alertAgent->registerChannel('webhook', function (Alert $alert, string $message) {
echo "[WEBHOOK] Sending to monitoring system: {$alert->getTitle()}\n";
});
// Process an alert
$alertTask = "Critical: CPU usage exceeded threshold\nCPU at 95%, threshold is 80%";
$result = $alertAgent->run($alertTask);
echo "\n";
// 3. Scheduler Agent Example
echo "3. Scheduler Agent\n";
echo "------------------\n";
$scheduler = new SchedulerAgent($client);
// Schedule a recurring task
$scheduler->schedule('health-check', '0 * * * *', function () {
echo "Running hourly health check...\n";
return "Health check completed";
});
// Schedule a one-time task
$scheduler->scheduleOnce('backup', '+2 hours', function () {
echo "Running backup...\n";
return "Backup completed";
});
// Simulate checking for pending tasks
$result = $scheduler->run("Check and execute pending tasks");
echo $result->getAnswer() . "\n";
echo "\nProduction Ops Demo Complete!\n";