apm-optima 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/LICENSE +21 -0
- package/README.md +166 -0
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksa Stanojevic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<h1>Optima APM</h1>
|
|
4
|
+
|
|
5
|
+
<img src="docs/assets/optima-icon.svg" alt="Optima Icon" width="64" />
|
|
6
|
+
|
|
7
|
+
<p><b>Lightweight, real-time Telemetry & Application Performance Monitoring for Node.js</b></p>
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@optima/core)
|
|
10
|
+
[](https://github.com/Nosalis1/Optima/blob/main/LICENSE)
|
|
11
|
+
[](https://nodejs.org)
|
|
12
|
+
[](https://www.npmjs.com/)
|
|
13
|
+
[](http://makeapullrequest.com)
|
|
14
|
+
|
|
15
|
+
<br/>
|
|
16
|
+
|
|
17
|
+
<a href="#key-features">Key Features</a> •
|
|
18
|
+
<a href="#architecture">Architecture</a> •
|
|
19
|
+
<a href="#quick-start">Quick Start</a> •
|
|
20
|
+
<a href="#configuration-options">Configuration</a> •
|
|
21
|
+
<a href="#dashboard-preview">Dashboard</a>
|
|
22
|
+
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Overview
|
|
28
|
+
|
|
29
|
+
**Optima** is an in-memory Application Performance Monitoring (APM) library designed for modern Node.js web services. It intercepts HTTP requests, tracks Event Loop lag, computes latency percentiles in real time, and identifies performance anomalies—all while serving an embedded React Dashboard with zero external database dependencies.
|
|
30
|
+
|
|
31
|
+
> Built for **Express.js** and **NestJS** applications with low runtime overhead.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Key Features
|
|
36
|
+
|
|
37
|
+
- **Real-time Latency Metrics:** On-the-fly computation of $P_{50}$, $P_{95}$, and $P_{99}$ percentiles.
|
|
38
|
+
- **Z-Score Anomaly Detection:** Statistical detection of unexpected response time spikes.
|
|
39
|
+
- **In-Memory Storage:** Efficient metric aggregation using typed array (`Uint32Array`) histogram buckets and circular ring buffers.
|
|
40
|
+
- **Embedded React Dashboard:** Zero-config static dashboard served directly through your primary Node.js HTTP server.
|
|
41
|
+
- **Framework Agnostic Core:** Native support for both **Express** (middleware) and **NestJS** (interceptors/modules).
|
|
42
|
+
- **Live Updates:** Low-latency WebSocket layer pushing live metrics straight to the UI.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Dashboard Preview
|
|
47
|
+
|
|
48
|
+
<!-- ZAMENI SA STVARNOM SLIKOM KADA JE DODATNA U REPOZITORIJUM -->
|
|
49
|
+
<div align="center">
|
|
50
|
+
<table border="0">
|
|
51
|
+
<tr>
|
|
52
|
+
<td width="33.3%"><img src="docs/assets/dashboard-1.png" alt="Optima Dashboard Preview 1" /></td>
|
|
53
|
+
<td width="33.3%"><img src="docs/assets/dashboard-2.png" alt="Optima Dashboard Preview 2" /></td>
|
|
54
|
+
<td width="33.3%"><img src="docs/assets/dashboard-3.png" alt="Optima Dashboard Preview 3" /></td>
|
|
55
|
+
</tr>
|
|
56
|
+
</table>
|
|
57
|
+
<td width="33.3%"><img src="docs/assets/dashboard-1-dark.png" alt="Optima Dashboard Preview 3" /></td>
|
|
58
|
+
<p><i>Real-time monitoring interface served directly via <code>/optima-metrics</code>.</i></p>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Architecture
|
|
64
|
+
|
|
65
|
+
Optima is structured as a **Monorepo** managed with `npm workspaces`:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
├── packages/
|
|
69
|
+
│ └── core/ # Telemetry engine, interceptors, and WebSocket adapters (@optima-apm/core)
|
|
70
|
+
│ └── dashboard/ # Next.js React Dashboard (exported statically into @optima-apm/core)
|
|
71
|
+
├── apps/ # Integration & demo application (Express & NestJS)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
### Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install @optima-apm/core
|
|
82
|
+
# or
|
|
83
|
+
pnpm add @optima-apm/core
|
|
84
|
+
# or
|
|
85
|
+
yarn add @optima-apm/core
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Express.js Integration
|
|
89
|
+
|
|
90
|
+
Attach Optima using setupOptima and hook the HTTP server instance:
|
|
91
|
+
```ts
|
|
92
|
+
const express = require('express');
|
|
93
|
+
const { setupOptima } = require('@optima-apm/core/express');
|
|
94
|
+
|
|
95
|
+
const app = express();
|
|
96
|
+
app.use(express.json());
|
|
97
|
+
|
|
98
|
+
// Initialize Optima telemetry & embed UI
|
|
99
|
+
const optima = setupOptima(app, {
|
|
100
|
+
dashboardPath: '/optima-metrics',
|
|
101
|
+
publisher: {
|
|
102
|
+
intervalMs: 1000,
|
|
103
|
+
slowLatencyThresholdMs: 500,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
app.get('/api/v1/resource', (req, res) => {
|
|
108
|
+
res.json({ status: 'ok' });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const server = app.listen(3000, () => {
|
|
112
|
+
console.log('Server running on port 3000');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Attach WebSocket server & background timers
|
|
116
|
+
const stopMetrics = optima.attachServer(server);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### NestJS Integration
|
|
120
|
+
|
|
121
|
+
Import MetricsModule into your root application module:
|
|
122
|
+
```ts
|
|
123
|
+
import { Module } from '@nestjs/common';
|
|
124
|
+
import { MetricsModule } from '@optima-apm/core/nest';
|
|
125
|
+
|
|
126
|
+
@Module({
|
|
127
|
+
imports: [
|
|
128
|
+
MetricsModule.forRoot({
|
|
129
|
+
dashboardPath: '/optima-metrics',
|
|
130
|
+
publisher: {
|
|
131
|
+
intervalMs: 1000,
|
|
132
|
+
slowLatencyThresholdMs: 500,
|
|
133
|
+
},
|
|
134
|
+
excludePaths: ['/health'],
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
})
|
|
138
|
+
export class AppModule {}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Configuration Options
|
|
142
|
+
|
|
143
|
+
| Option | Type | Default | Description |
|
|
144
|
+
| --- | --- | --- | --- |
|
|
145
|
+
| `dashboardPath` | `string \| false` | `/optima-metrics` | Route endpoint for serving the embedded UI (`false` to disable). |
|
|
146
|
+
| `simulation` | `false \| { intervalMs: number, requestsPerTick: number }` | `false` | Generates synthetic traffic for local testing and load simulation. |
|
|
147
|
+
| `publisher.intervalMs` | `number` | `1000` | Broadcast interval (in ms) for pushing telemetry updates over WebSockets. |
|
|
148
|
+
| `publisher.slowLatencyThresholdMs` | `number` | `500` | Latency limit in milliseconds above which requests are flagged as slow. |
|
|
149
|
+
| `publisher.eventLoopLagThresholdMs` | `number` | `50` | Event Loop delay threshold in milliseconds for triggering lag alerts. |
|
|
150
|
+
| `publisher.eventLoopResolutionMs` | `number` | `10` | Sampling resolution interval for computing Event Loop delay. |
|
|
151
|
+
| `tickIntervalMs` | `number` | `250` | Resolution interval for recalculating internal metrics and buckets. |
|
|
152
|
+
| `excludePaths` | `string[]` | `['/_next/*','/_next/**','*.map','/favicon.ico','/metrics_pack']` | Array of route patterns or paths to skip from metric collection (e.g., `/health`). |
|
|
153
|
+
| `consoleLog` | `boolean` | `false` | Enables logging internal system events and alerts to `stdout`. |
|
|
154
|
+
| `ringBufferSize` | `number` | `60` | Capacity of the internal ring buffer used for storing time-series data. |
|
|
155
|
+
| `alertBufferSize` | `number` | `100` | Maximum capacity of the buffer holding recent alerts and detected anomalies. |
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
Contributions, issues, and feature requests are welcome!
|
|
160
|
+
Feel free to check out the [issues page](https://github.com/Nosalis1/Optima/issues).
|
|
161
|
+
|
|
162
|
+
Please read our [Contributing Guidelines](CONTRIBUTING.md) before submitting a Pull Request or opening an issue.
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
Distributed under the MIT License. See [`LICENSE`](LICENSE) for more information.
|