apm-optima 0.0.1 → 1.0.1

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.
@@ -0,0 +1,133 @@
1
+ # Contributing to Optima APM
2
+
3
+ Thank you for your interest in contributing to **Optima APM**! We welcome bug fixes, feature proposals, documentation updates, and performance improvements.
4
+
5
+ This document provides a set of guidelines and instructions for setting up your local development environment and contributing to the project.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ - [Code of Conduct](#code-of-conduct)
12
+ - [Monorepo Architecture](#monorepo-architecture)
13
+ - [Prerequisites](#prerequisites)
14
+ - [Local Development Setup](#local-development-setup)
15
+ - [Project Workflow & Commands](#project-workflow--commands)
16
+ - [Development Guidelines](#development-guidelines)
17
+ - [Submitting a Pull Request](#submitting-a-pull-request)
18
+
19
+ ---
20
+
21
+ ## Code of Conduct
22
+
23
+ Please be respectful, constructive, and collaborative in all communications, issues, and Pull Requests.
24
+
25
+ ---
26
+
27
+ ## Monorepo Architecture
28
+
29
+ This project is structured as a **Monorepo** using **npm workspaces**:
30
+
31
+ ```
32
+ ├── packages/
33
+ │ └── core/ # Telemetry engine, interceptors, and WebSocket adapters (apm-optima/core)
34
+ │ └── dashboard/ # Next.js React Dashboard (exported statically into apm-optima/core)
35
+ ├── apps/ # Integration & demo application (Express & NestJS)
36
+ ```
37
+
38
+ - **`apm-optima/core`**: The published npm package containing the telemetry engine.
39
+ - **`packages/dashboard`**: A Next.js application that gets exported statically (`output: 'export'`) and bundled into `apm-optima/core`.
40
+ - **`apps`**: A local environment used to test `apm-optima/core` changes in real time.
41
+
42
+ ---
43
+
44
+ ## Prerequisites
45
+
46
+ Ensure you have the following installed locally:
47
+
48
+ - **Node.js**: `>= 20.0.0` (LTS version recommended)
49
+ - **npm**: `>= 10.0.0` (Native support for npm workspaces)
50
+ - **Git**: `>= 2.x`
51
+
52
+ ---
53
+
54
+ ## Local Development Setup
55
+
56
+ Follow these steps to clone and run the repository locally:
57
+
58
+ ### 1. Clone the Repository
59
+
60
+ ```bash
61
+ git clone https://github.com/Nosalis1/Optima.git
62
+ cd Optima
63
+ ```
64
+
65
+ ### 2. Install Dependencies
66
+
67
+ Install all dependencies across the entire monorepo with a single command from the root directory:
68
+ ```bash
69
+ npm install
70
+ ```
71
+
72
+ ### 3. Build the Packages
73
+
74
+ Build all packages in order (this compiles the Next.js static dashboard and builds `apm-optima/core`):
75
+ ```bash
76
+ npm run build
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Project Workflow & Commands
82
+
83
+ You can run workspace tasks from the root directory using central npm scripts:
84
+
85
+ ### Build Commands
86
+
87
+ | Command | Description |
88
+ | :--- | :--- |
89
+ | `npm run build` | Builds the Dashboard first, then compiles `apm-optima/core`. |
90
+ | `npm run build:dashboard` | Statically exports the Next.js Dashboard into `apps/dashboard/out`. |
91
+ | `npm run build:core` | Compiles TypeScript code for `apm-optima/core`. |
92
+ | `npm run clean` | Cleans `dist`, `.next`, and build artifacts across all packages. |
93
+
94
+ ### Development Commands
95
+
96
+ | Command | Description |
97
+ | :--- | :--- |
98
+ | `npm run dev:dashboard` | Runs Next.js Dashboard in dev/watch mode (`localhost:3001`). |
99
+ | `npm run dev:core` | Runs TypeScript watch mode for `apm-optima/core`. |
100
+ | `npm run dev:express` | Launches the Express integration demo. |
101
+ | `npm run dev:nest` | Launches the NestJS integration demo. |
102
+ | `npm test` | Runs test suites inside `apm-optima/core`. |
103
+
104
+ ---
105
+
106
+ ## Development Guidelines
107
+
108
+ **Working with Core and Dashboard**
109
+
110
+ 1. **Dashboard Changes:** Any UI changes inside `packages/dashboard` need to be statically exported before being served via `apm-optima/core`.
111
+ 2. **Local Linking:** Thanks to `npm workspaces`, `example-app` automatically links to `apm-optima/core` in real time without needing `npm link`.
112
+ 3. **TypeScript:** Ensure all packages compile without errors (`npm run build`) before submitting changes.
113
+
114
+ ---
115
+
116
+ ## Submitting a Pull Request
117
+
118
+ 1. **Fork & Branch:** Create a fork of the repository and create a new feature branch:
119
+ ```bash
120
+ git checkout -b feat/your-feature-name
121
+ ```
122
+ 2. **Commit Changes:** Write clear, concise commit messages following conventions:
123
+ - `feat`: New features
124
+ - `fix`: Bug fixes
125
+ - `docs`: Documentation changes
126
+ - `refactor`: Code improvements without functional changes
127
+ 3. **Push & Open PR:** Push your branch to GitHub and open a Pull Request against the `main` branch. Provide a clear summary of your changes in the PR description.
128
+
129
+ ---
130
+
131
+ ## Need Help?
132
+
133
+ If you run into issues or have questions, feel free to open a [GitHub Issue](https://github.com/Nosalis1/Optima/issues) or reach out through discussions.
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,165 @@
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
+ [![npm version](https://img.shields.io/npm/v/@optima/core.svg?style=flat-square&color=fc6c26)](https://www.npmjs.com/package/apm-optima)
10
+ [![license](https://img.shields.io/github/license/Nosalis1/Optima?style=flat-square&color=8A897C)](https://github.com/Nosalis1/Optima/blob/main/LICENSE)
11
+ [![node version](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen?style=flat-square)](https://nodejs.org)
12
+ [![npm version](https://img.shields.io/badge/npm-%3E%3D10.0.0-red?style=flat-square)](https://www.npmjs.com/)
13
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](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
+ <div align="center">
49
+ <table border="0">
50
+ <tr>
51
+ <td width="33.3%"><img src="docs/assets/dashboard-1.png" alt="Optima Dashboard Preview 1" /></td>
52
+ <td width="33.3%"><img src="docs/assets/dashboard-2.png" alt="Optima Dashboard Preview 2" /></td>
53
+ <td width="33.3%"><img src="docs/assets/dashboard-3.png" alt="Optima Dashboard Preview 3" /></td>
54
+ </tr>
55
+ </table>
56
+ <td width="33.3%"><img src="docs/assets/dashboard-1-dark.png" alt="Optima Dashboard Preview 3" /></td>
57
+ <p><i>Real-time monitoring interface served directly via <code>/optima-metrics</code>.</i></p>
58
+ </div>
59
+
60
+ ---
61
+
62
+ ## Architecture
63
+
64
+ Optima is structured as a **Monorepo** managed with `npm workspaces`:
65
+
66
+ ```
67
+ ├── packages/
68
+ │ └── core/ # Telemetry engine, interceptors, and WebSocket adapters (apm-optima/core)
69
+ │ └── dashboard/ # Next.js React Dashboard (exported statically into apm-optima/core)
70
+ ├── apps/ # Integration & demo application (Express & NestJS)
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Quick Start
76
+
77
+ ### Installation
78
+
79
+ ```bash
80
+ npm i apm-optima
81
+ # or
82
+ pnpm add apm-optima
83
+ # or
84
+ yarn add apm-optima
85
+ ```
86
+
87
+ ### Express.js Integration
88
+
89
+ Attach Optima using setupOptima and hook the HTTP server instance:
90
+ ```ts
91
+ const express = require('express');
92
+ const { setupOptima } = require('apm-optima/express');
93
+
94
+ const app = express();
95
+ app.use(express.json());
96
+
97
+ // Initialize Optima telemetry & embed UI
98
+ const optima = setupOptima(app, {
99
+ dashboardPath: '/optima-metrics',
100
+ publisher: {
101
+ intervalMs: 1000,
102
+ slowLatencyThresholdMs: 500,
103
+ },
104
+ });
105
+
106
+ app.get('/api/v1/resource', (req, res) => {
107
+ res.json({ status: 'ok' });
108
+ });
109
+
110
+ const server = app.listen(3000, () => {
111
+ console.log('Server running on port 3000');
112
+ });
113
+
114
+ // Attach WebSocket server & background timers
115
+ const stopMetrics = optima.attachServer(server);
116
+ ```
117
+
118
+ ### NestJS Integration
119
+
120
+ Import MetricsModule into your root application module:
121
+ ```ts
122
+ import { Module } from '@nestjs/common';
123
+ import { MetricsModule } from 'apm-optima/nest';
124
+
125
+ @Module({
126
+ imports: [
127
+ MetricsModule.forRoot({
128
+ dashboardPath: '/optima-metrics',
129
+ publisher: {
130
+ intervalMs: 1000,
131
+ slowLatencyThresholdMs: 500,
132
+ },
133
+ excludePaths: ['/health'],
134
+ }),
135
+ ],
136
+ })
137
+ export class AppModule {}
138
+ ```
139
+
140
+ ### Configuration Options
141
+
142
+ | Option | Type | Default | Description |
143
+ | --- | --- | --- | --- |
144
+ | `dashboardPath` | `string \| false` | `/optima-metrics` | Route endpoint for serving the embedded UI (`false` to disable). |
145
+ | `simulation` | `false \| { intervalMs: number, requestsPerTick: number }` | `false` | Generates synthetic traffic for local testing and load simulation. |
146
+ | `publisher.intervalMs` | `number` | `1000` | Broadcast interval (in ms) for pushing telemetry updates over WebSockets. |
147
+ | `publisher.slowLatencyThresholdMs` | `number` | `500` | Latency limit in milliseconds above which requests are flagged as slow. |
148
+ | `publisher.eventLoopLagThresholdMs` | `number` | `50` | Event Loop delay threshold in milliseconds for triggering lag alerts. |
149
+ | `publisher.eventLoopResolutionMs` | `number` | `10` | Sampling resolution interval for computing Event Loop delay. |
150
+ | `tickIntervalMs` | `number` | `250` | Resolution interval for recalculating internal metrics and buckets. |
151
+ | `excludePaths` | `string[]` | `['/_next/*','/_next/**','*.map','/favicon.ico','/metrics_pack']` | Array of route patterns or paths to skip from metric collection (e.g., `/health`). |
152
+ | `consoleLog` | `boolean` | `false` | Enables logging internal system events and alerts to `stdout`. |
153
+ | `ringBufferSize` | `number` | `60` | Capacity of the internal ring buffer used for storing time-series data. |
154
+ | `alertBufferSize` | `number` | `100` | Maximum capacity of the buffer holding recent alerts and detected anomalies. |
155
+
156
+ ## Contributing
157
+
158
+ Contributions, issues, and feature requests are welcome!
159
+ Feel free to check out the [issues page](https://github.com/Nosalis1/Optima/issues).
160
+
161
+ Please read our [Contributing Guidelines](CONTRIBUTING.md) before submitting a Pull Request or opening an issue.
162
+
163
+ ## License
164
+
165
+ Distributed under the MIT License. See [`LICENSE`](LICENSE) for more information.
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,39 @@
1
+ <svg
2
+ width="64"
3
+ height="64"
4
+ viewBox="0 0 200 200"
5
+ fill="none"
6
+ xmlns="http://www.w3.org/2000/svg"
7
+ >
8
+ <circle
9
+ cx="100"
10
+ cy="100"
11
+ r="75"
12
+ stroke="white"
13
+ strokeWidth="7"
14
+ strokeOpacity="0.25"
15
+ />
16
+
17
+ <path
18
+ d="M 45 135 A 65 65 0 1 1 155 135"
19
+ stroke="white"
20
+ strokeWidth="10"
21
+ strokeLinecap="round"
22
+ />
23
+
24
+ <circle cx="50" cy="130" r="4" fill="white" />
25
+ <circle cx="100" cy="42" r="4" fill="white" />
26
+ <circle cx="150" cy="130" r="4" fill="white" />
27
+
28
+ <rect x="78" y="130" width="7" height="18" rx="3.5" fill="white" fillOpacity="0.5" />
29
+ <rect x="92" y="118" width="7" height="30" rx="3.5" fill="white" fillOpacity="0.9" />
30
+ <rect x="106" y="124" width="7" height="24" rx="3.5" fill="white" fillOpacity="0.6" />
31
+
32
+ <path
33
+ d="M 100 100 L 132 68"
34
+ stroke="white"
35
+ strokeWidth="8"
36
+ strokeLinecap="round"
37
+ />
38
+ <circle cx="100" cy="100" r="8" fill="white" />
39
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apm-optima",
3
- "version": "0.0.1",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {
@@ -34,6 +34,9 @@
34
34
  "files": [
35
35
  "dist",
36
36
  "README.md",
37
+ "LICENSE",
38
+ "CONTRIBUTING.md",
39
+ "docs",
37
40
  "package.json"
38
41
  ],
39
42
  "scripts": {
@@ -68,4 +71,4 @@
68
71
  "ts-jest": "^29.0.0",
69
72
  "typescript": "^5.0.0"
70
73
  }
71
- }
74
+ }