mikroscope 0.0.1 → 1.0.0
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 +278 -25
- package/dist/cli.mjs +30 -23
- package/openapi/openapi.json +328 -49
- package/openapi/openapi.yaml +194 -3
- package/package.json +15 -9
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# MikroScope
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Ultralight log sidecar for Node.js that turns NDJSON into instant queries and actionable webhook alerts.**
|
|
4
4
|
|
|
5
|
-
MikroScope runs next to your service, writes/reads `.ndjson` logs, indexes them into SQLite, and exposes an HTTP API for search and aggregation.
|
|
5
|
+
MikroScope runs next to your service, writes/reads `.ndjson` logs, indexes them into SQLite, and exposes an HTTP API for search and aggregation with millisecond latency.
|
|
6
6
|
|
|
7
7
|
## What You Get
|
|
8
8
|
|
|
@@ -21,30 +21,28 @@ MikroScope runs next to your service, writes/reads `.ndjson` logs, indexes them
|
|
|
21
21
|
|
|
22
22
|
## Install
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
Requirements:
|
|
25
|
+
|
|
26
|
+
- Node.js `>= 24` (required to run MikroScope).
|
|
27
|
+
- `npm` (required for npm install / npx flows).
|
|
28
|
+
- `curl` or `wget` (used by installer to download release assets).
|
|
29
|
+
- `tar` (or `unzip` for `.zip`) to extract release archives.
|
|
30
|
+
|
|
31
|
+
Install methods:
|
|
32
|
+
|
|
33
|
+
- `npm install -g mikroscope` for persistent CLI usage in Node/npm environments.
|
|
34
|
+
- `npx mikroscope --help` for one-off execution without global install.
|
|
35
|
+
- One-line installer (below) for VM/server installs without npm dependency.
|
|
36
|
+
- Non-interactive installer (below) for CI/provisioning.
|
|
37
|
+
- Manual release archive install (see "Manual Release Install" below) for pinned/manual installs.
|
|
38
38
|
|
|
39
39
|
Installer behavior:
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
| Prompt for config | Writes host/port/path/auth settings to a local env file |
|
|
47
|
-
| Create wrapper | Adds a `mikroscope` command in your chosen bin directory |
|
|
41
|
+
- Download latest release from GitHub Releases.
|
|
42
|
+
- Verify checksum using `SHA256SUMS.txt` when available.
|
|
43
|
+
- Expand archive into your chosen install directory.
|
|
44
|
+
- Prompt for host/port/path/auth config values.
|
|
45
|
+
- Create a `mikroscope` wrapper command in your chosen bin directory.
|
|
48
46
|
|
|
49
47
|
npm install examples:
|
|
50
48
|
|
|
@@ -77,7 +75,7 @@ If `mikroscope` is not found after install, add your chosen bin directory to `PA
|
|
|
77
75
|
### Manual Release Install
|
|
78
76
|
|
|
79
77
|
```bash
|
|
80
|
-
VERSION=0.0
|
|
78
|
+
VERSION=1.0.0
|
|
81
79
|
curl -LO "https://github.com/mikaelvesavuori/mikroscope/releases/download/v${VERSION}/mikroscope-${VERSION}.tar.gz"
|
|
82
80
|
curl -LO "https://github.com/mikaelvesavuori/mikroscope/releases/download/v${VERSION}/SHA256SUMS.txt"
|
|
83
81
|
shasum -a 256 -c SHA256SUMS.txt
|
|
@@ -127,6 +125,252 @@ curl -sS "http://127.0.0.1:4310/api/logs?field=producerId&value=backend-api&limi
|
|
|
127
125
|
|
|
128
126
|
If `/docs` is blank (for example blocked CDN scripts), use `/openapi.json` directly.
|
|
129
127
|
|
|
128
|
+
## Configuration Inputs
|
|
129
|
+
|
|
130
|
+
`mikroscope serve`, `mikroscope index`, `mikroscope query`, and `mikroscope aggregate` resolve configuration with layered precedence:
|
|
131
|
+
|
|
132
|
+
1. Built-in defaults
|
|
133
|
+
1. JSON config file (`--config` or `MIKROSCOPE_CONFIG_PATH`; default: `./mikroscope.config.json` if present)
|
|
134
|
+
1. Environment variables (`MIKROSCOPE_*`)
|
|
135
|
+
1. Direct CLI flags (highest precedence)
|
|
136
|
+
|
|
137
|
+
### mikroscope.config.json
|
|
138
|
+
|
|
139
|
+
MikroScope will automatically read `./mikroscope.config.json` when it exists in your current working directory.
|
|
140
|
+
|
|
141
|
+
Quick setup:
|
|
142
|
+
|
|
143
|
+
1. Copy the example template from this repo:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
cp ./examples/mikroscope.config.json ./mikroscope.config.json
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
1. Set your real secrets/tokens in `./mikroscope.config.json`.
|
|
150
|
+
1. Start MikroScope:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
mikroscope serve
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
If your config is not in the current directory, set an explicit path:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
mikroscope serve --config /absolute/or/relative/path/mikroscope.config.json
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Config file keys use camelCase (for example `ingestQueueFlushMs`, `alertErrorThreshold`) and match the server option names.
|
|
163
|
+
|
|
164
|
+
Template (`./examples/mikroscope.config.json`):
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"dbPath": "./data/mikroscope.db",
|
|
169
|
+
"logsPath": "./logs",
|
|
170
|
+
"host": "127.0.0.1",
|
|
171
|
+
"port": 4310,
|
|
172
|
+
"protocol": "http",
|
|
173
|
+
"apiToken": "api-token-123",
|
|
174
|
+
"ingestProducers": "backend-token=backend-api,frontend-token=frontend-web",
|
|
175
|
+
"ingestAsyncQueue": true,
|
|
176
|
+
"alertWebhookUrl": "https://example.com/webhook"
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
You can still override config-file values via env vars or CLI flags at runtime.
|
|
181
|
+
|
|
182
|
+
Use it explicitly:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
mikroscope serve --config ./mikroscope.config.json
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Env-only example:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
MIKROSCOPE_DB_PATH=./data/mikroscope.db \
|
|
192
|
+
MIKROSCOPE_LOGS_PATH=./logs \
|
|
193
|
+
MIKROSCOPE_PORT=4310 \
|
|
194
|
+
MIKROSCOPE_API_TOKEN=api-token-123 \
|
|
195
|
+
mikroscope serve
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Programmatic usage with direct params:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import { resolveMikroScopeServerOptions } from "./src/application/config/resolveMikroScopeServerOptions.js";
|
|
202
|
+
import { startMikroScopeServer } from "./src/server.js";
|
|
203
|
+
|
|
204
|
+
const options = resolveMikroScopeServerOptions({
|
|
205
|
+
configFilePath: "./mikroscope.config.json",
|
|
206
|
+
overrides: {
|
|
207
|
+
port: 4320
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await startMikroScopeServer(options);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Generate Mock Data
|
|
215
|
+
|
|
216
|
+
If you want realistic logs to inspect quickly, generate synthetic NDJSON files from a source checkout of this repository.
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Standard dataset (writes to ./logs)
|
|
220
|
+
npm run mock-data
|
|
221
|
+
|
|
222
|
+
# Smaller/faster dataset
|
|
223
|
+
npm run mock-data:quick
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
What this does:
|
|
227
|
+
|
|
228
|
+
- Writes normal logs to `./logs/generated/*.ndjson`.
|
|
229
|
+
- Writes audit logs to `./logs/audit/generated/*.ndjson`.
|
|
230
|
+
- Uses deterministic random data (seeded) so runs are reproducible.
|
|
231
|
+
|
|
232
|
+
Useful tuning options:
|
|
233
|
+
|
|
234
|
+
- `MOCK_LOG_DAYS` (default: `21`)
|
|
235
|
+
- `MOCK_LOGS_PER_DAY` (default: `1200`)
|
|
236
|
+
- `MOCK_AUDIT_LOGS_PER_DAY` (default: `150`)
|
|
237
|
+
- `MOCK_LOG_TENANTS` (default: `320`)
|
|
238
|
+
- `MOCK_LOG_SEED` (default: `2602`)
|
|
239
|
+
- `MOCK_LOG_OUT_DIR` (default: `./logs`)
|
|
240
|
+
|
|
241
|
+
Example custom run:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
MOCK_LOG_DAYS=14 \
|
|
245
|
+
MOCK_LOGS_PER_DAY=800 \
|
|
246
|
+
MOCK_AUDIT_LOGS_PER_DAY=100 \
|
|
247
|
+
MOCK_LOG_TENANTS=120 \
|
|
248
|
+
npm run mock-data
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Then index and run:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
npm run index
|
|
255
|
+
npm start
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Optional UI: MikroScope Console
|
|
259
|
+
|
|
260
|
+
MikroScope works with the optional [MikroScope Console](https://github.com/mikaelvesavuori/mikroscope-console), a static web UI for exploring logs and correlations.
|
|
261
|
+
|
|
262
|
+
Basic setup:
|
|
263
|
+
|
|
264
|
+
1. Start MikroScope:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
mikroscope serve --host 127.0.0.1 --port 4310 --logs ./logs --db ./data/mikroscope.db --cors-allow-origin http://127.0.0.1:4320
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
1. Install Console (from the console repo README):
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
curl -fsSL https://raw.githubusercontent.com/mikaelvesavuori/mikroscope-console/main/install.sh -o install.sh && sh install.sh && rm install.sh
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
1. Set Console API target in `public/config.json`:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"apiOrigin": "http://127.0.0.1:4310"
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
1. Serve Console static files and open it:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
npx http-server public -p 4320 -c-1
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
MikroScope endpoints used by Console:
|
|
291
|
+
|
|
292
|
+
- `GET /health`
|
|
293
|
+
- `GET /api/logs`
|
|
294
|
+
- `GET /api/logs/aggregate`
|
|
295
|
+
- `GET /api/alerts/config`
|
|
296
|
+
- `PUT /api/alerts/config`
|
|
297
|
+
- `POST /api/alerts/test-webhook`
|
|
298
|
+
|
|
299
|
+
## Manual Webhook Alert Demo
|
|
300
|
+
|
|
301
|
+
If you want to manually experience alerting (not test runner output), use the helper script:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# Start demo in error-threshold mode
|
|
305
|
+
npm run demo:alerts -- up error
|
|
306
|
+
|
|
307
|
+
# Trigger ERROR logs (should fire webhook)
|
|
308
|
+
npm run demo:alerts -- trigger-error
|
|
309
|
+
|
|
310
|
+
# Check alerting state from /health
|
|
311
|
+
npm run demo:alerts -- status
|
|
312
|
+
|
|
313
|
+
# Inspect recent webhook + server logs
|
|
314
|
+
npm run demo:alerts -- logs
|
|
315
|
+
|
|
316
|
+
# Stop demo
|
|
317
|
+
npm run demo:alerts -- down
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
No-logs mode:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
npm run demo:alerts -- up nologs
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Then wait ~60-70 seconds without sending logs and check `npm run demo:alerts -- logs` for a `rule: "no_logs"` webhook.
|
|
327
|
+
|
|
328
|
+
## Remote Alert Configuration
|
|
329
|
+
|
|
330
|
+
Alert config can be managed over API and is persisted to disk so it survives restarts/reboots.
|
|
331
|
+
|
|
332
|
+
Default config file path:
|
|
333
|
+
|
|
334
|
+
- `<db-directory>/mikroscope.alert-config.json`
|
|
335
|
+
|
|
336
|
+
Override path:
|
|
337
|
+
|
|
338
|
+
- CLI: `--alert-config-path /path/to/mikroscope.alert-config.json`
|
|
339
|
+
- Env: `MIKROSCOPE_ALERT_CONFIG_PATH=/path/to/mikroscope.alert-config.json`
|
|
340
|
+
|
|
341
|
+
Examples:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# Read current policy
|
|
345
|
+
curl -sS "http://127.0.0.1:4310/api/alerts/config" \
|
|
346
|
+
-H "Authorization: Bearer api-token-123"
|
|
347
|
+
|
|
348
|
+
# Update and persist policy
|
|
349
|
+
curl -sS "http://127.0.0.1:4310/api/alerts/config" \
|
|
350
|
+
-H "Authorization: Bearer api-token-123" \
|
|
351
|
+
-H "Content-Type: application/json" \
|
|
352
|
+
-X PUT \
|
|
353
|
+
--data '{
|
|
354
|
+
"enabled": true,
|
|
355
|
+
"webhookUrl": "https://example.com/webhook",
|
|
356
|
+
"intervalMs": 30000,
|
|
357
|
+
"windowMinutes": 5,
|
|
358
|
+
"errorThreshold": 20,
|
|
359
|
+
"noLogsThresholdMinutes": 0,
|
|
360
|
+
"cooldownMs": 300000,
|
|
361
|
+
"webhookTimeoutMs": 5000,
|
|
362
|
+
"webhookRetryAttempts": 3,
|
|
363
|
+
"webhookBackoffMs": 250
|
|
364
|
+
}'
|
|
365
|
+
|
|
366
|
+
# Send a manual test webhook event
|
|
367
|
+
curl -sS "http://127.0.0.1:4310/api/alerts/test-webhook" \
|
|
368
|
+
-H "Authorization: Bearer api-token-123" \
|
|
369
|
+
-H "Content-Type: application/json" \
|
|
370
|
+
-X POST \
|
|
371
|
+
--data '{}'
|
|
372
|
+
```
|
|
373
|
+
|
|
130
374
|
## CLI Commands
|
|
131
375
|
|
|
132
376
|
| Command | Use case |
|
|
@@ -143,6 +387,9 @@ If `/docs` is blank (for example blocked CDN scripts), use `/openapi.json` direc
|
|
|
143
387
|
| `POST /api/ingest` | `Bearer <ingest-token>` mapped by `--ingest-producers`, or Basic auth if configured | Always server-assigned. Incoming `producerId` in payload is ignored/overridden. |
|
|
144
388
|
| `GET /api/logs` | `Bearer <api-token>` and/or Basic auth (if enabled) | N/A |
|
|
145
389
|
| `GET /api/logs/aggregate` | `Bearer <api-token>` and/or Basic auth (if enabled) | N/A |
|
|
390
|
+
| `GET /api/alerts/config` | `Bearer <api-token>` and/or Basic auth (if enabled) | N/A |
|
|
391
|
+
| `PUT /api/alerts/config` | `Bearer <api-token>` and/or Basic auth (if enabled) | N/A |
|
|
392
|
+
| `POST /api/alerts/test-webhook` | `Bearer <api-token>` and/or Basic auth (if enabled) | N/A |
|
|
146
393
|
| `POST /api/reindex` | `Bearer <api-token>` and/or Basic auth (if enabled) | N/A |
|
|
147
394
|
|
|
148
395
|
Notes:
|
|
@@ -171,6 +418,9 @@ Notes:
|
|
|
171
418
|
|--------|-----------------------|-------------------------------------------|------------------------------------------|
|
|
172
419
|
| `GET` | `/health` | None | Runtime health and policy/status details |
|
|
173
420
|
| `POST` | `/api/ingest` | Ingest bearer token mapping or Basic auth | Accept and persist inbound logs |
|
|
421
|
+
| `GET` | `/api/alerts/config` | API bearer token and/or Basic auth | Read active alert policy + config path |
|
|
422
|
+
| `PUT` | `/api/alerts/config` | API bearer token and/or Basic auth | Update and persist alert policy |
|
|
423
|
+
| `POST` | `/api/alerts/test-webhook` | API bearer token and/or Basic auth | Send manual webhook test event |
|
|
174
424
|
| `GET` | `/api/logs` | API bearer token and/or Basic auth | Paginated log query |
|
|
175
425
|
| `GET` | `/api/logs/aggregate` | API bearer token and/or Basic auth | Bucketed counts |
|
|
176
426
|
| `POST` | `/api/reindex` | API bearer token and/or Basic auth | Full DB reset + reindex from logs |
|
|
@@ -207,8 +457,10 @@ Query parameters for `/api/logs/aggregate`:
|
|
|
207
457
|
|-----------------------|------------------------|------------------------------------------------|
|
|
208
458
|
| `--logs` | `./logs` | NDJSON root directory |
|
|
209
459
|
| `--db` | `./data/mikroscope.db` | SQLite database file |
|
|
460
|
+
| `--config` | `./mikroscope.config.json` | JSON config file path (if present) |
|
|
210
461
|
| `--host` | `127.0.0.1` | Bind host |
|
|
211
462
|
| `--port` | `4310` | Bind port |
|
|
463
|
+
| `--protocol` | `http` | Listener protocol (`http` or `https`) |
|
|
212
464
|
| `--https` | `false` | Enable HTTPS listener |
|
|
213
465
|
| `--tls-cert` | none | TLS certificate path (required with `--https`) |
|
|
214
466
|
| `--tls-key` | none | TLS key path (required with `--https`) |
|
|
@@ -253,6 +505,7 @@ Query parameters for `/api/logs/aggregate`:
|
|
|
253
505
|
| `--alert-webhook-timeout-ms` | `5000` | Webhook timeout per request |
|
|
254
506
|
| `--alert-webhook-retry-attempts` | `3` | Webhook retry attempts per alert |
|
|
255
507
|
| `--alert-webhook-backoff-ms` | `250` | Base backoff between webhook retries |
|
|
508
|
+
| `--alert-config-path` | db dir | Path to persisted alert config JSON |
|
|
256
509
|
|
|
257
510
|
## Example Integrations
|
|
258
511
|
|
|
@@ -333,5 +586,5 @@ Use this only if you want to develop MikroScope itself.
|
|
|
333
586
|
```bash
|
|
334
587
|
npm install
|
|
335
588
|
npm run index
|
|
336
|
-
npm
|
|
589
|
+
npm start
|
|
337
590
|
```
|