adonisjs-server-stats 1.0.3 → 1.0.5
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 +46 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# adonisjs-server-stats
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/adonisjs-server-stats)
|
|
4
|
+
[](https://www.npmjs.com/package/adonisjs-server-stats)
|
|
5
|
+
[](https://bundlephobia.com/package/adonisjs-server-stats)
|
|
6
|
+
[](https://github.com/simulieren/adonisjs-server-stats/blob/main/LICENSE)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://adonisjs.com/)
|
|
9
|
+
|
|
3
10
|
A Laravel Telescope-inspired dev toolbar and real-time server monitor for **AdonisJS v6**.
|
|
4
11
|
|
|
5
12
|
Drop a single Edge tag into your layout and get a live stats bar showing CPU, memory, requests/sec, database pool, Redis, queues, and logs -- plus a full debug toolbar with SQL query inspection, event tracing, route listing, live log tailing, and custom panels.
|
|
@@ -82,6 +89,23 @@ server.use([
|
|
|
82
89
|
```ts
|
|
83
90
|
// config/server_stats.ts
|
|
84
91
|
import { defineConfig } from 'adonisjs-server-stats'
|
|
92
|
+
import { processCollector, systemCollector, httpCollector } from 'adonisjs-server-stats/collectors'
|
|
93
|
+
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
collectors: [
|
|
96
|
+
processCollector(),
|
|
97
|
+
systemCollector(),
|
|
98
|
+
httpCollector(),
|
|
99
|
+
],
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
That's it -- this gives you CPU, memory, event loop lag, and HTTP throughput out of the box. All other options have sensible defaults. Add more collectors as needed:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
// config/server_stats.ts
|
|
107
|
+
import env from '#start/env'
|
|
108
|
+
import { defineConfig } from 'adonisjs-server-stats'
|
|
85
109
|
import {
|
|
86
110
|
processCollector,
|
|
87
111
|
systemCollector,
|
|
@@ -92,14 +116,12 @@ import {
|
|
|
92
116
|
logCollector,
|
|
93
117
|
appCollector,
|
|
94
118
|
} from 'adonisjs-server-stats/collectors'
|
|
95
|
-
import env from '#start/env'
|
|
96
119
|
|
|
97
120
|
export default defineConfig({
|
|
98
121
|
intervalMs: 3000,
|
|
99
122
|
transport: 'transmit',
|
|
100
123
|
channelName: 'admin/server-stats',
|
|
101
124
|
endpoint: '/admin/api/server-stats',
|
|
102
|
-
shouldShow: (ctx) => !!ctx.auth?.user?.isAdmin,
|
|
103
125
|
collectors: [
|
|
104
126
|
processCollector(),
|
|
105
127
|
systemCollector(),
|
|
@@ -126,7 +148,7 @@ export default defineConfig({
|
|
|
126
148
|
// start/routes.ts
|
|
127
149
|
router
|
|
128
150
|
.get('/admin/api/server-stats', '#controllers/admin/server_stats_controller.index')
|
|
129
|
-
.use(middleware.superadmin())
|
|
151
|
+
.use(middleware.superadmin()) // Replace with your own middleware
|
|
130
152
|
```
|
|
131
153
|
|
|
132
154
|
### 5. Create the controller
|
|
@@ -271,23 +293,35 @@ interface MetricCollector {
|
|
|
271
293
|
|
|
272
294
|
## Visibility Control (`shouldShow`)
|
|
273
295
|
|
|
274
|
-
|
|
296
|
+
By default the stats bar renders for every request. Use `shouldShow` to restrict it. The callback receives the AdonisJS `HttpContext` and should return `true` to show the bar, `false` to hide it.
|
|
297
|
+
|
|
298
|
+
Because `shouldShow` runs **after** middleware (including auth), you have full access to `ctx.auth`.
|
|
275
299
|
|
|
276
300
|
```ts
|
|
277
301
|
export default defineConfig({
|
|
278
|
-
// Only
|
|
279
|
-
shouldShow: (
|
|
302
|
+
// Only show in development
|
|
303
|
+
shouldShow: () => env.get('NODE_ENV'),
|
|
304
|
+
})
|
|
305
|
+
```
|
|
280
306
|
|
|
281
|
-
|
|
282
|
-
|
|
307
|
+
```ts
|
|
308
|
+
export default defineConfig({
|
|
309
|
+
// Only show for logged-in admin users
|
|
310
|
+
shouldShow: (ctx) => ctx.auth?.user?.isAdmin === true,
|
|
311
|
+
})
|
|
312
|
+
```
|
|
283
313
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
314
|
+
```ts
|
|
315
|
+
export default defineConfig({
|
|
316
|
+
// Only show for specific roles
|
|
317
|
+
shouldShow: (ctx) => {
|
|
318
|
+
const role = ctx.auth?.user?.role
|
|
319
|
+
return role === 'admin' || role === 'superadmin'
|
|
320
|
+
},
|
|
287
321
|
})
|
|
288
322
|
```
|
|
289
323
|
|
|
290
|
-
When `shouldShow` is not set, the
|
|
324
|
+
> **Tip:** When `shouldShow` is not set, the bar renders for everyone. In production you almost always want to set this.
|
|
291
325
|
|
|
292
326
|
---
|
|
293
327
|
|