@bitcall/pm2-pulse-agent 1.0.1-beta.0 → 1.0.1-beta.2

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 CHANGED
@@ -1 +1,176 @@
1
- # MONITORING-SERVICE
1
+ # PM2 Pulse Agent
2
+
3
+ A Node.js monitoring agent that tracks server metrics (CPU, RAM, processes) and sends real-time alerts to a gRPC monitoring service.
4
+
5
+ ## Features
6
+
7
+ - **Real-time Metrics Collection**: Monitors CPU usage, RAM consumption, and PM2 process states
8
+ - **Configurable Thresholds**: Set custom CPU and RAM alert thresholds
9
+ - **PM2 Integration**: Tracks all PM2-managed processes and their status
10
+ - **gRPC Communication**: Sends metrics to a monitoring server via gRPC
11
+ - **Authentication Support**: Optional Bearer token authentication
12
+ - **Singleton Pattern**: Ensures only one agent instance runs per server
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @bitcall/pm2-pulse-agent@beta
18
+ ```
19
+
20
+ ### Dependencies
21
+
22
+ - `@grpc/grpc-js` - gRPC protocol implementation
23
+ - `@grpc/proto-loader` - Protocol buffer loader
24
+ - `dotenv` - Environment variable management
25
+
26
+ ## Setup
27
+
28
+ Run the interactive setup script to configure the agent:
29
+
30
+ ```bash
31
+ npx @bitcall/pm2-pulse-agent pm2-pulse-setup
32
+ ```
33
+
34
+ Or if installed globally:
35
+
36
+ ```bash
37
+ npm install -g @bitcall/pm2-pulse-agent@beta
38
+ pm2-pulse-setup
39
+ ```
40
+
41
+ This will prompt you to configure:
42
+ - **AUTH_TOKEN**: Secret token for server authentication (optional)
43
+ - **MONITOR_SERVER**: gRPC server address (default: `localhost:50051`)
44
+ - **VPS_ID**: Unique identifier for this server (default: `server-{hostname}`)
45
+
46
+ Settings are saved to `.env` file in your current directory.
47
+
48
+ ## Usage
49
+
50
+ ### Start the Agent
51
+
52
+ **Using npx (recommended):**
53
+ ```bash
54
+ npx @bitcall/pm2-pulse-agent pm2-pulse-agent
55
+ ```
56
+
57
+ **If installed globally:**
58
+ ```bash
59
+ pm2-pulse-agent
60
+ ```
61
+
62
+ **Run with PM2 (for persistent monitoring):**
63
+ ```bash
64
+ pm2 start "npx @bitcall/pm2-pulse-agent pm2-pulse-agent" --name pm2-pulse-agent
65
+ ```
66
+
67
+ ### Configuration Options
68
+
69
+ Environment variables in `.env`:
70
+
71
+ | Variable | Default | Description |
72
+ |----------|---------|-------------|
73
+ | `MONITOR_SERVER` | `localhost:50051` | gRPC server host:port |
74
+ | `VPS_ID` | `server-{hostname}` | Unique server identifier |
75
+ | `AUTH_TOKEN` | `` | Bearer token for authentication |
76
+ | `CPU_THRESHOLD` | `70` | CPU alert threshold (%) |
77
+ | `RAM_THRESHOLD` | `80` | RAM alert threshold (%) |
78
+
79
+ ## How It Works
80
+
81
+ 1. **Agent Startup**: Initializes gRPC client and logs configuration
82
+ 2. **Metrics Collection**: Every 10 seconds, collects:
83
+ - CPU usage (2-second measurement window)
84
+ - RAM usage and statistics
85
+ - PM2 process information (name, status, restarts, CPU, memory)
86
+ 3. **Alert Detection**: Triggers alerts when:
87
+ - CPU exceeds threshold
88
+ - RAM exceeds threshold
89
+ - Any process is not in "online" status
90
+ 4. **Data Transmission**: Sends metrics to gRPC server with optional authentication
91
+ 5. **Logging**: Displays metrics and alerts in console
92
+
93
+ ## Metrics Structure
94
+
95
+ ```javascript
96
+ {
97
+ vps_id: string, // Server identifier
98
+ cpu: number, // CPU usage percentage (0-100)
99
+ ram: number, // RAM usage percentage (0-100)
100
+ ram_used_mb: number, // Used RAM in MB
101
+ ram_total_mb: number, // Total RAM in MB
102
+ processes: [ // PM2 processes
103
+ {
104
+ name: string,
105
+ status: string, // 'online', 'stopped', etc.
106
+ restarts: number,
107
+ cpu_percent: number,
108
+ memory_mb: number
109
+ }
110
+ ],
111
+ alerts: string[], // Alert messages
112
+ urgent: boolean, // Whether message contains alerts
113
+ timestamp: number // Unix timestamp
114
+ }
115
+ ```
116
+
117
+ ## Example Output
118
+
119
+ ```
120
+ ============================================================
121
+ 🚀 PM2 Monitoring Agent Started
122
+ ============================================================
123
+ VPS ID: server-app-01
124
+ Server: monitoring-server.example.com:50051
125
+ Authentication: ✓ Enabled
126
+ Check interval: 10 second(s)
127
+ CPU Threshold: 70%
128
+ RAM Threshold: 80%
129
+ ============================================================
130
+
131
+ [14:23:45] CPU: 45% | RAM: 2048/8192MB (25%) | Alerts: 0
132
+ [14:23:55] CPU: 62% | RAM: 3512/8192MB (43%) | Alerts: 0
133
+ [14:24:05] CPU: 85% | RAM: 6144/8192MB (75%) | Alerts: 1 🚨
134
+ ✓ Alert sent to server
135
+ ```
136
+
137
+ ## Quick Start Guide
138
+
139
+ 1. **Install the package:**
140
+ ```bash
141
+ npm install -g @bitcall/pm2-pulse-agent@beta
142
+ ```
143
+
144
+ 2. **Run setup:**
145
+ ```bash
146
+ pm2-pulse-setup
147
+ ```
148
+
149
+ 3. **Start monitoring:**
150
+ ```bash
151
+ pm2 start pm2-pulse-agent --name monitoring-agent
152
+ ```
153
+
154
+ 4. **Check status:**
155
+ ```bash
156
+ pm2 logs monitoring-agent
157
+ ```
158
+
159
+ ## Troubleshooting
160
+
161
+ **Agent not connecting to server:**
162
+ - Verify `MONITOR_SERVER` address is correct in `.env`
163
+ - Check network connectivity: `telnet <server-host> <port>`
164
+ - Ensure firewall allows outbound connections
165
+
166
+ **PM2 processes not detected:**
167
+ - Verify PM2 is installed: `pm2 --version`
168
+ - Check PM2 has running processes: `pm2 list`
169
+
170
+ **Authentication errors:**
171
+ - Verify `AUTH_TOKEN` in `.env` matches server configuration
172
+ - Check token hasn't expired
173
+
174
+ ## License
175
+
176
+ MIT
package/agent.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const os = require('os')
2
4
  const { exec } = require('child_process')
3
5
  const grpc = require('@grpc/grpc-js')
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@bitcall/pm2-pulse-agent",
3
- "version": "1.0.1-beta.0",
3
+ "version": "1.0.1-beta.2",
4
+ "bin": {
5
+ "pm2-pulse-setup": "./scripts/setup-agent.js",
6
+ "pm2-pulse-agent": "./agent.js"
7
+ },
4
8
  "scripts": {
5
9
  "agent": "node agent.js",
6
10
  "monitor": "node agent.js",
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const fs = require('fs')
2
4
  const path = require('path')
3
5
  const readline = require('readline')