-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMONITOR_INTEGRATION_GUIDE.php
More file actions
97 lines (95 loc) · 3.23 KB
/
MONITOR_INTEGRATION_GUIDE.php
File metadata and controls
97 lines (95 loc) · 3.23 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
<?php
/**
* Router Integration Patch for Monitor
*
* This file provides instructions for integrating the Monitor class into Router.php
*
* INTEGRATION STEPS:
* ==================
*
* 1. Add Monitor property to Router class (around line 13):
* private ?Monitor $monitor = null;
*
* 2. Initialize Monitor in constructor (around line 35):
* // Initialize monitor
* if (!empty($this->apiConfig['monitoring']['enabled'])) {
* $this->monitor = new Monitor($this->apiConfig['monitoring'] ?? []);
* }
*
* 3. Record request in route() method (around line 70, after rate limit headers):
* // Record request metric
* if ($this->monitor) {
* $this->monitor->recordRequest([
* 'method' => $_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN',
* 'action' => $query['action'] ?? null,
* 'table' => $query['table'] ?? null,
* 'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
* 'user' => $this->auth->getCurrentUser()['username'] ?? null,
* ]);
* }
*
* 4. Record security events for rate limit (around line 80):
* if (!$this->rateLimiter->checkLimit($identifier)) {
* // ... existing logger code ...
*
* // Record security event
* if ($this->monitor) {
* $this->monitor->recordSecurityEvent('rate_limit_hit', [
* 'identifier' => $identifier,
* 'requests' => $this->rateLimiter->getRequestCount($identifier),
* ]);
* }
*
* $this->rateLimiter->sendRateLimitResponse($identifier);
* }
*
* 5. Record security events for authentication (around line 100):
* // After successful auth:
* if ($this->monitor) {
* $this->monitor->recordSecurityEvent('auth_success', [
* 'method' => 'jwt',
* 'user' => $user,
* ]);
* }
*
* // After failed auth:
* if ($this->monitor) {
* $this->monitor->recordSecurityEvent('auth_failure', [
* 'method' => 'jwt',
* 'reason' => 'Invalid credentials',
* 'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
* ]);
* }
*
* 6. Modify logResponse() method to record metrics (around line 450):
* private function logResponse($data, int $code, array $query): void
* {
* $executionTime = (microtime(true) - $this->requestStartTime) * 1000;
* $responseSize = strlen(json_encode($data));
*
* // Existing logger code...
*
* // Record response metric
* if ($this->monitor) {
* $this->monitor->recordResponse($code, $executionTime, $responseSize);
* }
* }
*
* 7. Record errors in catch block (around line 400):
* catch (\Exception $e) {
* // Existing logger code...
*
* // Record error metric
* if ($this->monitor) {
* $this->monitor->recordError($e->getMessage(), [
* 'file' => $e->getFile(),
* 'line' => $e->getLine(),
* 'action' => $query['action'] ?? null,
* 'table' => $query['table'] ?? null,
* ]);
* }
*
* // Existing response code...
* }
*/
// This file is documentation only - no executable code