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.
Files changed (2) hide show
  1. package/README.md +46 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # adonisjs-server-stats
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/adonisjs-server-stats.svg)](https://www.npmjs.com/package/adonisjs-server-stats)
4
+ [![npm downloads](https://img.shields.io/npm/dm/adonisjs-server-stats.svg)](https://www.npmjs.com/package/adonisjs-server-stats)
5
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/adonisjs-server-stats)](https://bundlephobia.com/package/adonisjs-server-stats)
6
+ [![license](https://img.shields.io/npm/l/adonisjs-server-stats.svg)](https://github.com/simulieren/adonisjs-server-stats/blob/main/LICENSE)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9+-blue.svg)](https://www.typescriptlang.org/)
8
+ [![AdonisJS](https://img.shields.io/badge/AdonisJS-v6-5A45FF.svg)](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
- Control who sees the stats bar via the `shouldShow` config callback. It receives the AdonisJS `HttpContext` and returns `true` to render.
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 admin users
279
- shouldShow: (ctx) => !!ctx.auth?.user?.isAdmin,
302
+ // Only show in development
303
+ shouldShow: () => env.get('NODE_ENV'),
304
+ })
305
+ ```
280
306
 
281
- // Only in development
282
- shouldShow: () => process.env.NODE_ENV === 'development',
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
- // Multiple roles
285
- shouldShow: (ctx) =>
286
- ctx.auth?.user?.role === 'admin' || ctx.auth?.user?.role === 'superadmin',
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 stats bar always renders.
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adonisjs-server-stats",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Real-time server monitoring for AdonisJS v6 applications",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",