nucleus-core-ts 0.9.985 → 0.9.987
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,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the process is HOLDING, counted — because a memory number alone cannot
|
|
3
|
+
* say where the memory went.
|
|
4
|
+
*
|
|
5
|
+
* Measured on a live install: resident memory climbing 119.5 MB/hour with the
|
|
6
|
+
* JS heap floor flat at 38 MB. Two independent sources agreed (the cgroup's own
|
|
7
|
+
* working set and `process.memoryUsage().rss`), so the growth is real and it is
|
|
8
|
+
* native. And there the trail ended: the snapshot recorded memory, CPU,
|
|
9
|
+
* database connections and Redis — and every one of those was flat.
|
|
10
|
+
*
|
|
11
|
+
* Something that grows without bound almost always leaves a countable trace:
|
|
12
|
+
* a socket that is never closed, a file handle, a worker thread, a subscriber.
|
|
13
|
+
* These are those counts. They cost one directory listing per collection and
|
|
14
|
+
* they are the difference between "it died holding 981 MB" and "it died holding
|
|
15
|
+
* 981 MB and 4,000 open sockets".
|
|
16
|
+
*
|
|
17
|
+
* Linux-only by nature — `/proc/self` does not exist elsewhere — and every
|
|
18
|
+
* field is optional, so a Mac or a BSD simply reports nothing rather than
|
|
19
|
+
* failing a collection that is otherwise fine.
|
|
20
|
+
*/
|
|
21
|
+
export interface HandleCounts {
|
|
22
|
+
/** Open file descriptors: sockets, files, pipes, everything. */
|
|
23
|
+
fileDescriptors?: number;
|
|
24
|
+
/** Of those, how many are sockets — the usual suspect. */
|
|
25
|
+
sockets?: number;
|
|
26
|
+
/** OS threads. A pool that keeps growing shows up here first. */
|
|
27
|
+
threads?: number;
|
|
28
|
+
/** The kernel's own ceiling, so a count can be read as a fraction of it. */
|
|
29
|
+
fileDescriptorLimit?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function collectHandles(root?: string): HandleCounts;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHERE the resident memory is, not just how much of it there is.
|
|
3
|
+
*
|
|
4
|
+
* This exists because of a night spent guessing. A live install was climbing
|
|
5
|
+
* with the JS heap floor flat at 37 MB and `external` at 13 MB, which said the
|
|
6
|
+
* growth was native and said nothing else. Six hypotheses were tested and
|
|
7
|
+
* plateaued — request handling, loopback fetch, file serving, aborted range
|
|
8
|
+
* requests, the dominant endpoint, the JS heap. The one number that would have
|
|
9
|
+
* cut that short is here: the split between anonymous memory (what the process
|
|
10
|
+
* allocated) and file-backed memory (what it mapped), plus the kernel's own
|
|
11
|
+
* accounting of what the cgroup is being charged for.
|
|
12
|
+
*
|
|
13
|
+
* The distinction that matters most:
|
|
14
|
+
*
|
|
15
|
+
* anon grows → the allocator is holding it. On musl this is usually
|
|
16
|
+
* retention rather than a leak: freed, never returned.
|
|
17
|
+
* file grows → mapped files or page cache. Reclaimable; not a leak, but
|
|
18
|
+
* it still counts against `memory.max`.
|
|
19
|
+
* sock grows → network buffers, i.e. sockets nobody is draining.
|
|
20
|
+
* slab /
|
|
21
|
+
* kernel_stack → the kernel's share, which usually means threads or fds.
|
|
22
|
+
*
|
|
23
|
+
* Linux-only, every field optional: elsewhere it reports nothing rather than
|
|
24
|
+
* failing a collection that is otherwise fine.
|
|
25
|
+
*/
|
|
26
|
+
export interface NativeMemoryBreakdown {
|
|
27
|
+
/** Resident anonymous memory — heap, stacks, allocator arenas. Bytes. */
|
|
28
|
+
anonymous?: number;
|
|
29
|
+
/** Resident file-backed memory — mapped executables, libraries. Bytes. */
|
|
30
|
+
fileBacked?: number;
|
|
31
|
+
/** Resident shared memory. Bytes. */
|
|
32
|
+
shared?: number;
|
|
33
|
+
/** Swapped out. Bytes. Non-zero here changes what every other number means. */
|
|
34
|
+
swapped?: number;
|
|
35
|
+
/** Distinct mappings in /proc/self/maps. A fragmenting arena shows up here. */
|
|
36
|
+
mappings?: number;
|
|
37
|
+
/** cgroup: anonymous charge. Bytes. */
|
|
38
|
+
cgroupAnon?: number;
|
|
39
|
+
/** cgroup: page cache charge — reclaimable, but inside the limit. Bytes. */
|
|
40
|
+
cgroupFile?: number;
|
|
41
|
+
/** cgroup: socket buffers. Bytes. */
|
|
42
|
+
cgroupSock?: number;
|
|
43
|
+
/** cgroup: kernel slab. Bytes. */
|
|
44
|
+
cgroupSlab?: number;
|
|
45
|
+
/** cgroup: kernel stacks, i.e. threads. Bytes. */
|
|
46
|
+
cgroupKernelStack?: number;
|
|
47
|
+
}
|
|
48
|
+
export declare function collectNativeMemory(procRoot?: string, cgroupRoot?: string): NativeMemoryBreakdown;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { HandleCounts } from './collectors/handles';
|
|
2
|
+
import type { NativeMemoryBreakdown } from './collectors/nativeMemory';
|
|
1
3
|
export interface MonitoringConfig {
|
|
2
4
|
enabled?: boolean;
|
|
3
5
|
system?: {
|
|
@@ -127,6 +129,26 @@ export interface SystemMetrics {
|
|
|
127
129
|
uptime: number;
|
|
128
130
|
pid: number;
|
|
129
131
|
eventLoopLag: number;
|
|
132
|
+
/**
|
|
133
|
+
* What the process is HOLDING — open descriptors, sockets, threads.
|
|
134
|
+
*
|
|
135
|
+
* A memory number alone cannot say where memory went. Measured live:
|
|
136
|
+
* resident memory climbing 119.5 MB/h with the JS heap floor flat, and
|
|
137
|
+
* every counter the snapshot DID carry (database, Redis) flat too. The
|
|
138
|
+
* thing that grows usually leaves a countable trace; these are the counts
|
|
139
|
+
* that would name it.
|
|
140
|
+
*
|
|
141
|
+
* Linux-only, and optional everywhere: a platform without /proc reports
|
|
142
|
+
* nothing rather than failing the collection.
|
|
143
|
+
*/
|
|
144
|
+
handles?: HandleCounts;
|
|
145
|
+
/**
|
|
146
|
+
* WHERE the resident memory is: anonymous vs file-backed, plus the cgroup's
|
|
147
|
+
* own breakdown. A memory total says a process is growing; this says which
|
|
148
|
+
* kind of memory is growing, which is the difference between a hypothesis
|
|
149
|
+
* and a diagnosis.
|
|
150
|
+
*/
|
|
151
|
+
nativeMemory?: NativeMemoryBreakdown;
|
|
130
152
|
};
|
|
131
153
|
}
|
|
132
154
|
export interface ApplicationMetrics {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nucleus-core-ts",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.987",
|
|
4
4
|
"description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
|
|
5
5
|
"author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|