adonisjs-server-stats 1.4.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +272 -142
- package/dist/configure.d.ts.map +1 -1
- package/dist/src/controller/debug_controller.d.ts +2 -2
- package/dist/src/controller/debug_controller.d.ts.map +1 -1
- package/dist/src/controller/server_stats_controller.d.ts +1 -1
- package/dist/src/controller/server_stats_controller.d.ts.map +1 -1
- package/dist/src/dashboard/chart_aggregator.d.ts.map +1 -1
- package/dist/src/dashboard/chart_aggregator.js +8 -8
- package/dist/src/dashboard/dashboard_controller.d.ts +12 -97
- package/dist/src/dashboard/dashboard_controller.d.ts.map +1 -1
- package/dist/src/dashboard/dashboard_controller.js +244 -522
- package/dist/src/dashboard/dashboard_routes.d.ts.map +1 -1
- package/dist/src/dashboard/dashboard_routes.js +7 -2
- package/dist/src/dashboard/dashboard_store.d.ts +6 -3
- package/dist/src/dashboard/dashboard_store.d.ts.map +1 -1
- package/dist/src/dashboard/dashboard_store.js +54 -78
- package/dist/src/dashboard/integrations/cache_inspector.d.ts.map +1 -1
- package/dist/src/dashboard/integrations/queue_inspector.d.ts.map +1 -1
- package/dist/src/dashboard/migrator.d.ts.map +1 -1
- package/dist/src/dashboard/migrator.js +3 -1
- package/dist/src/dashboard/models/stats_event.d.ts +1 -1
- package/dist/src/dashboard/models/stats_event.d.ts.map +1 -1
- package/dist/src/dashboard/models/stats_query.d.ts +1 -1
- package/dist/src/dashboard/models/stats_query.d.ts.map +1 -1
- package/dist/src/dashboard/models/stats_request.d.ts +2 -2
- package/dist/src/dashboard/models/stats_request.d.ts.map +1 -1
- package/dist/src/dashboard/models/stats_request.js +1 -1
- package/dist/src/dashboard/models/stats_trace.d.ts +1 -1
- package/dist/src/dashboard/models/stats_trace.d.ts.map +1 -1
- package/dist/src/debug/debug_store.d.ts +6 -6
- package/dist/src/debug/debug_store.d.ts.map +1 -1
- package/dist/src/debug/debug_store.js +10 -10
- package/dist/src/debug/email_collector.d.ts +0 -9
- package/dist/src/debug/email_collector.d.ts.map +1 -1
- package/dist/src/debug/email_collector.js +6 -28
- package/dist/src/debug/event_collector.d.ts +1 -1
- package/dist/src/debug/event_collector.d.ts.map +1 -1
- package/dist/src/debug/event_collector.js +17 -17
- package/dist/src/debug/query_collector.d.ts +1 -1
- package/dist/src/debug/query_collector.d.ts.map +1 -1
- package/dist/src/debug/query_collector.js +13 -14
- package/dist/src/debug/ring_buffer.d.ts.map +1 -1
- package/dist/src/debug/route_inspector.d.ts +1 -1
- package/dist/src/debug/route_inspector.d.ts.map +1 -1
- package/dist/src/debug/route_inspector.js +12 -12
- package/dist/src/debug/trace_collector.d.ts.map +1 -1
- package/dist/src/debug/trace_collector.js +6 -5
- package/dist/src/edge/client/dashboard.css +516 -171
- package/dist/src/edge/client/dashboard.js +2756 -1662
- package/dist/src/edge/client/debug-panel.css +476 -133
- package/dist/src/edge/client/debug-panel.js +1496 -1043
- package/dist/src/edge/client/stats-bar.css +64 -30
- package/dist/src/edge/client/stats-bar.js +598 -319
- package/dist/src/edge/plugin.d.ts +1 -1
- package/dist/src/edge/plugin.d.ts.map +1 -1
- package/dist/src/edge/plugin.js +41 -59
- package/dist/src/edge/views/stats-bar.edge +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/middleware/request_tracking_middleware.d.ts +4 -4
- package/dist/src/middleware/request_tracking_middleware.d.ts.map +1 -1
- package/dist/src/middleware/request_tracking_middleware.js +7 -6
- package/dist/src/prometheus/prometheus_collector.d.ts +1 -1
- package/dist/src/prometheus/prometheus_collector.d.ts.map +1 -1
- package/dist/src/provider/server_stats_provider.d.ts +1 -1
- package/dist/src/provider/server_stats_provider.d.ts.map +1 -1
- package/dist/src/provider/server_stats_provider.js +33 -32
- package/dist/src/types.d.ts +2 -2
- package/dist/src/utils/json_helpers.d.ts +8 -0
- package/dist/src/utils/json_helpers.d.ts.map +1 -0
- package/dist/src/utils/json_helpers.js +21 -0
- package/dist/src/utils/mail_helpers.d.ts +13 -0
- package/dist/src/utils/mail_helpers.d.ts.map +1 -0
- package/dist/src/utils/mail_helpers.js +26 -0
- package/dist/src/utils/math_helpers.d.ts +8 -0
- package/dist/src/utils/math_helpers.d.ts.map +1 -0
- package/dist/src/utils/math_helpers.js +11 -0
- package/dist/src/utils/time_helpers.d.ts +12 -0
- package/dist/src/utils/time_helpers.d.ts.map +1 -0
- package/dist/src/utils/time_helpers.js +32 -0
- package/dist/src/utils/transmit_client.d.ts +9 -0
- package/dist/src/utils/transmit_client.d.ts.map +1 -0
- package/dist/src/utils/transmit_client.js +20 -0
- package/package.json +35 -29
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { round } from '../utils/math_helpers.js';
|
|
2
|
+
import { toSqliteTimestamp } from '../utils/time_helpers.js';
|
|
1
3
|
/**
|
|
2
4
|
* Periodically aggregates recent request data into time-bucketed
|
|
3
5
|
* metrics stored in `server_stats_metrics`.
|
|
@@ -31,13 +33,11 @@ export class ChartAggregator {
|
|
|
31
33
|
async aggregate() {
|
|
32
34
|
const bucket = getBucketTimestamp();
|
|
33
35
|
// Check if we already have a row for this bucket (idempotent)
|
|
34
|
-
const existing = await this.db('server_stats_metrics')
|
|
35
|
-
.where('bucket', bucket)
|
|
36
|
-
.first();
|
|
36
|
+
const existing = await this.db('server_stats_metrics').where('bucket', bucket).first();
|
|
37
37
|
if (existing)
|
|
38
38
|
return;
|
|
39
39
|
// Get requests from the last 60 seconds
|
|
40
|
-
const cutoff = new Date(Date.now() - 60_000)
|
|
40
|
+
const cutoff = toSqliteTimestamp(new Date(Date.now() - 60_000));
|
|
41
41
|
const requests = await this.db('server_stats_requests')
|
|
42
42
|
.where('created_at', '>=', cutoff)
|
|
43
43
|
.select('duration', 'status_code');
|
|
@@ -70,11 +70,11 @@ export class ChartAggregator {
|
|
|
70
70
|
await this.db('server_stats_metrics').insert({
|
|
71
71
|
bucket,
|
|
72
72
|
request_count: requestCount,
|
|
73
|
-
avg_duration:
|
|
74
|
-
p95_duration:
|
|
73
|
+
avg_duration: round(avgDuration),
|
|
74
|
+
p95_duration: round(p95Duration),
|
|
75
75
|
error_count: errorCount,
|
|
76
76
|
query_count: queryStats?.query_count ?? 0,
|
|
77
|
-
avg_query_duration:
|
|
77
|
+
avg_query_duration: round(queryStats?.avg_query_duration ?? 0),
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -85,5 +85,5 @@ export class ChartAggregator {
|
|
|
85
85
|
function getBucketTimestamp() {
|
|
86
86
|
const now = new Date();
|
|
87
87
|
now.setSeconds(0, 0);
|
|
88
|
-
return now
|
|
88
|
+
return toSqliteTimestamp(now);
|
|
89
89
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import type { DebugStore } from '../debug/debug_store.js';
|
|
2
|
+
import type { DashboardStore } from './dashboard_store.js';
|
|
1
3
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
4
|
import type { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
-
import type { DashboardStore } from './dashboard_store.js';
|
|
4
|
-
import type { DebugStore } from '../debug/debug_store.js';
|
|
5
5
|
/**
|
|
6
6
|
* Controller for the full-page dashboard.
|
|
7
7
|
*
|
|
8
8
|
* Serves the dashboard HTML page and all JSON API endpoints.
|
|
9
|
-
*
|
|
10
|
-
* the in-memory DebugStore, and the AdonisJS application instance.
|
|
9
|
+
* Delegates all data access to the DashboardStore.
|
|
11
10
|
*/
|
|
12
11
|
export default class DashboardController {
|
|
13
12
|
private dashboardStore;
|
|
@@ -22,126 +21,42 @@ export default class DashboardController {
|
|
|
22
21
|
private cachedJs;
|
|
23
22
|
private cachedTransmitClient;
|
|
24
23
|
constructor(dashboardStore: DashboardStore, debugStore: DebugStore, app: ApplicationService);
|
|
25
|
-
/**
|
|
26
|
-
* GET {dashboardPath} — Render the dashboard Edge template.
|
|
27
|
-
*
|
|
28
|
-
* Reads the dashboard CSS/JS assets and passes them as template state
|
|
29
|
-
* along with configuration for tracing and custom panes.
|
|
30
|
-
*/
|
|
31
24
|
page(ctx: HttpContext): Promise<any>;
|
|
32
|
-
/**
|
|
33
|
-
* GET {dashboardPath}/api/overview — Overview metrics cards.
|
|
34
|
-
*/
|
|
35
25
|
overview({ request, response }: HttpContext): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* GET {dashboardPath}/api/overview/chart — Chart data with time range.
|
|
38
|
-
*/
|
|
39
26
|
overviewChart({ request, response }: HttpContext): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* GET {dashboardPath}/api/requests — Paginated request history.
|
|
42
|
-
*/
|
|
43
27
|
requests({ request, response }: HttpContext): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* GET {dashboardPath}/api/requests/:id — Single request with trace.
|
|
46
|
-
*/
|
|
47
28
|
requestDetail({ params, response }: HttpContext): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* GET {dashboardPath}/api/queries — Paginated query history.
|
|
50
|
-
*/
|
|
51
29
|
queries({ request, response }: HttpContext): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* GET {dashboardPath}/api/queries/grouped — Grouped by normalized SQL.
|
|
54
|
-
*/
|
|
55
30
|
queriesGrouped({ request, response }: HttpContext): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* GET {dashboardPath}/api/queries/:id/explain — Run EXPLAIN on a query.
|
|
58
|
-
*/
|
|
59
31
|
queryExplain({ params, response }: HttpContext): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* GET {dashboardPath}/api/events — Paginated event history.
|
|
62
|
-
*/
|
|
63
32
|
events({ request, response }: HttpContext): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* GET {dashboardPath}/api/routes — Route table (delegates to DebugStore).
|
|
66
|
-
*/
|
|
67
33
|
routes({ response }: HttpContext): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* GET {dashboardPath}/api/logs — Paginated logs with structured search.
|
|
70
|
-
*/
|
|
71
34
|
logs({ request, response }: HttpContext): Promise<void>;
|
|
72
|
-
/**
|
|
73
|
-
* GET {dashboardPath}/api/emails — Paginated email history.
|
|
74
|
-
*/
|
|
75
35
|
emails({ request, response }: HttpContext): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* GET {dashboardPath}/api/emails/:id/preview — Email HTML preview.
|
|
78
|
-
*/
|
|
79
36
|
emailPreview({ params, response }: HttpContext): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* GET {dashboardPath}/api/traces — Paginated trace list (lightweight).
|
|
82
|
-
*/
|
|
83
37
|
traces({ request, response }: HttpContext): Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* GET {dashboardPath}/api/traces/:id — Single trace with full spans.
|
|
86
|
-
*/
|
|
87
38
|
traceDetail({ params, response }: HttpContext): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* GET {dashboardPath}/api/cache — Cache stats and key list.
|
|
90
|
-
*/
|
|
91
39
|
cacheStats({ request, response }: HttpContext): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* GET {dashboardPath}/api/cache/:key — Single cache key detail.
|
|
94
|
-
*/
|
|
95
40
|
cacheKey({ params, response }: HttpContext): Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* GET {dashboardPath}/api/jobs — Job list with status filter.
|
|
98
|
-
*/
|
|
99
41
|
jobs({ request, response }: HttpContext): Promise<void>;
|
|
100
|
-
/**
|
|
101
|
-
* GET {dashboardPath}/api/jobs/:id — Single job detail.
|
|
102
|
-
*/
|
|
103
42
|
jobDetail({ params, response }: HttpContext): Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* POST {dashboardPath}/api/jobs/:id/retry — Retry a failed job.
|
|
106
|
-
*/
|
|
107
43
|
jobRetry({ params, response }: HttpContext): Promise<void>;
|
|
108
|
-
/**
|
|
109
|
-
* GET {dashboardPath}/api/config — Sanitized app config and env vars.
|
|
110
|
-
*/
|
|
111
44
|
config({ response }: HttpContext): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
* GET {dashboardPath}/api/filters — List saved filter presets.
|
|
114
|
-
*/
|
|
115
45
|
savedFilters({ response }: HttpContext): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* POST {dashboardPath}/api/filters — Create a saved filter preset.
|
|
118
|
-
*/
|
|
119
46
|
createSavedFilter({ request, response }: HttpContext): Promise<void>;
|
|
120
|
-
/**
|
|
121
|
-
* DELETE {dashboardPath}/api/filters/:id — Delete a saved filter preset.
|
|
122
|
-
*/
|
|
123
47
|
deleteSavedFilter({ params, response }: HttpContext): Promise<void>;
|
|
124
48
|
/**
|
|
125
|
-
*
|
|
49
|
+
* Wraps a store call with null-guard + try/catch boilerplate.
|
|
50
|
+
* Returns emptyValue if the store is not ready or the fn throws.
|
|
126
51
|
*/
|
|
52
|
+
private withDb;
|
|
127
53
|
private checkAccess;
|
|
128
|
-
/**
|
|
129
|
-
* Get the configured dashboard path.
|
|
130
|
-
*/
|
|
131
54
|
private getDashboardPath;
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
private
|
|
138
|
-
/**
|
|
139
|
-
* Lazily initialize and return the CacheInspector (if Redis is available).
|
|
140
|
-
*/
|
|
141
|
-
private getCacheInspector;
|
|
142
|
-
/**
|
|
143
|
-
* Lazily initialize and return the QueueInspector (if Bull Queue is available).
|
|
144
|
-
*/
|
|
145
|
-
private getQueueInspector;
|
|
55
|
+
/** Lazy-init inspector pattern for cache and queue. */
|
|
56
|
+
private getInspector;
|
|
57
|
+
/** Fetch cache overview stats for the overview page. */
|
|
58
|
+
private fetchCacheOverview;
|
|
59
|
+
/** Fetch queue overview stats for the overview page. */
|
|
60
|
+
private fetchQueueOverview;
|
|
146
61
|
}
|
|
147
62
|
//# sourceMappingURL=dashboard_controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard_controller.d.ts","sourceRoot":"","sources":["../../../src/dashboard/dashboard_controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard_controller.d.ts","sourceRoot":"","sources":["../../../src/dashboard/dashboard_controller.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAwB9D;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAWpC,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,GAAG;IAZb,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,oBAAoB,CAAsB;gBAGxC,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,EACtB,GAAG,EAAE,kBAAkB;IAS3B,IAAI,CAAC,GAAG,EAAE,WAAW;IAgDrB,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,WAAW;IAiC3C,aAAa,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,WAAW;IA0BhD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,WAAW;IAqB3C,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,WAAW;IAuB/C,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,WAAW;IAsB1C,cAAc,CAAC,EAAE,OAAO,EA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