thinknagent 0.1.8 → 0.1.10
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 +315 -0
- package/package.json +1 -1
package/Readme.md
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# thinknagent
|
|
2
|
+
|
|
3
|
+
Official server agent for [ThinkNCollab](https://thinkncollab.com) — monitor your servers, stream logs, and access remote terminals directly from your DevOps Wall.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g thinknagent
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
> **Linux/macOS only.** Requires Node.js v18+.
|
|
14
|
+
|
|
15
|
+
**If build error on Linux:**
|
|
16
|
+
```bash
|
|
17
|
+
sudo apt-get install -y build-essential python3
|
|
18
|
+
npm install -g thinknagent
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**If permission denied:**
|
|
22
|
+
```bash
|
|
23
|
+
chmod +x (which thinknagent)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Commands
|
|
29
|
+
|
|
30
|
+
| Command | Description |
|
|
31
|
+
|---------|-------------|
|
|
32
|
+
| `thinknagent init` | Register this server with ThinkNCollab |
|
|
33
|
+
| `thinknagent start` | Connect and start monitoring |
|
|
34
|
+
| `thinknagent status` | Show current config and status |
|
|
35
|
+
| `thinknagent revoke` | Clear all credentials and re-register |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Init Options
|
|
40
|
+
|
|
41
|
+
| Option | Required | Description |
|
|
42
|
+
|--------|----------|-------------|
|
|
43
|
+
| `--server <url>` | ✅ | ThinkNCollab server URL |
|
|
44
|
+
| `--name <name>` | ✅ | Display name on DevOps Wall |
|
|
45
|
+
| `--room <roomId>` | ✅ | Room ID to connect to |
|
|
46
|
+
| `--gpu` | ❌ | Enable GPU metrics (requires nvidia-smi) |
|
|
47
|
+
| `--logs <paths>` | ❌ | Comma-separated log file paths to stream |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
### Step 1 — Initialize
|
|
54
|
+
|
|
55
|
+
**Basic (metrics only):**
|
|
56
|
+
```bash
|
|
57
|
+
thinknagent init \
|
|
58
|
+
--server YOUR_APP_SERVER \
|
|
59
|
+
--name my-server \
|
|
60
|
+
--room <roomId>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**With log streaming:**
|
|
64
|
+
```bash
|
|
65
|
+
thinknagent init \
|
|
66
|
+
--server YOUR_APP_SERVER \
|
|
67
|
+
--name my-server \
|
|
68
|
+
--room <roomId> \
|
|
69
|
+
--logs <YOUR_LOG_FILE>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**With PM2 app logs:**
|
|
73
|
+
```bash
|
|
74
|
+
thinknagent init \
|
|
75
|
+
--server YOUR_APP_SERVER \
|
|
76
|
+
--name my-server \
|
|
77
|
+
--room <roomId> \
|
|
78
|
+
--logs <YOUR_PM2_LOG_FILE>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**With GPU metrics:**
|
|
82
|
+
```bash
|
|
83
|
+
thinknagent init \
|
|
84
|
+
--server YOUR_APP_SERVER \
|
|
85
|
+
--name my-server \
|
|
86
|
+
--room <roomId> \
|
|
87
|
+
--gpu \
|
|
88
|
+
--logs <YOUR_SYS_LOG_FILE>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Get your `roomId` from the room URL:
|
|
92
|
+
https://thinkncollab.com/rooms/YOUR_ROOM_ID_HERE
|
|
93
|
+
|
|
94
|
+
### Step 2 — Start
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
thinknagent start
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Output:
|
|
101
|
+
Starting thinknagent — my-server
|
|
102
|
+
Status: PENDING — waiting for Owner approval
|
|
103
|
+
[agent] Connecting to https://thinkncollab.com...
|
|
104
|
+
[thinknagent] Registered as <agentId> — waiting for Owner approval...
|
|
105
|
+
|
|
106
|
+
### Step 3 — Approve in Browser
|
|
107
|
+
|
|
108
|
+
Go to your room's DevOps Wall:
|
|
109
|
+
https://thinkncollab.com/devops/<roomId>/devops
|
|
110
|
+
|
|
111
|
+
Click **Approve** on the pending agent in the sidebar.
|
|
112
|
+
|
|
113
|
+
Once approved:
|
|
114
|
+
[thinknagent] Approved! Role: monitor | Room: <roomId>
|
|
115
|
+
[agent] Active. Role: monitor | Room: <roomId>
|
|
116
|
+
[metrics] Poller started
|
|
117
|
+
[logs] Watching 2 file(s)
|
|
118
|
+
[shell] Bridge ready
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Features
|
|
123
|
+
|
|
124
|
+
### ◈ Metrics
|
|
125
|
+
Real-time system metrics pushed every 5 seconds — no config needed, starts automatically:
|
|
126
|
+
- CPU usage + load average + core count
|
|
127
|
+
- Memory usage (used / total GB)
|
|
128
|
+
- Disk usage per mount point
|
|
129
|
+
- Network I/O (rx/tx per second)
|
|
130
|
+
- Top 5 processes by CPU
|
|
131
|
+
|
|
132
|
+
### ≡ Log Streaming
|
|
133
|
+
Stream any log file to the DevOps Wall in real-time:
|
|
134
|
+
```bash
|
|
135
|
+
# Common log paths on Ubuntu
|
|
136
|
+
/var/log/syslog # system
|
|
137
|
+
/var/log/auth.log # auth/ssh
|
|
138
|
+
/var/log/nginx/access.log # nginx access
|
|
139
|
+
/var/log/nginx/error.log # nginx errors
|
|
140
|
+
/home/ubuntu/.pm2/logs/app-out.log # pm2 stdout
|
|
141
|
+
/home/ubuntu/.pm2/logs/app-error.log # pm2 stderr
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Pass multiple paths comma-separated:
|
|
145
|
+
```bash
|
|
146
|
+
--logs /var/log/syslog,/var/log/nginx/error.log,/home/ubuntu/.pm2/logs/app-out.log
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### ⚠ Alerts
|
|
150
|
+
Default alert rules — configurable from DevOps Wall at runtime:
|
|
151
|
+
|
|
152
|
+
| ID | Metric | Condition | Severity |
|
|
153
|
+
|----|--------|-----------|----------|
|
|
154
|
+
| cpu-high | CPU usage | > 85% for 60s | warning |
|
|
155
|
+
| cpu-crit | CPU usage | > 95% for 30s | critical |
|
|
156
|
+
| mem-high | Memory usage | > 85% for 60s | warning |
|
|
157
|
+
| disk-root | Disk `/` | > 90% | critical |
|
|
158
|
+
|
|
159
|
+
### ▸ Shell Access
|
|
160
|
+
Remote terminal via xterm.js in the browser. Requires `shell` or `admin` role.
|
|
161
|
+
|
|
162
|
+
**How to enable shell access:**
|
|
163
|
+
|
|
164
|
+
1. Owner opens DevOps Wall
|
|
165
|
+
2. Changes agent role to `shell` from the UI
|
|
166
|
+
3. Click `▸ shell` tab → `▸ open terminal`
|
|
167
|
+
|
|
168
|
+
Full bash session on your server — directly in the browser.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Roles
|
|
173
|
+
|
|
174
|
+
| Role | Metrics | Logs | Alerts | Shell | Edit Rules |
|
|
175
|
+
|------|---------|------|--------|-------|------------|
|
|
176
|
+
| monitor | ✅ | ✅ | ✅ | ❌ | ❌ |
|
|
177
|
+
| shell | ✅ | ✅ | ✅ | ✅ | ❌ |
|
|
178
|
+
| admin | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
179
|
+
|
|
180
|
+
Role is assigned by the room Owner at approval time and can be changed anytime from the DevOps Wall.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Auth Flow
|
|
185
|
+
thinknagent init
|
|
186
|
+
→ generates agentId
|
|
187
|
+
→ saves to ~/.thinknagent/config.json
|
|
188
|
+
thinknagent start
|
|
189
|
+
→ connects to wss://thinkncollab.com/devops
|
|
190
|
+
→ sends { agentId, name, hostname, roomId }
|
|
191
|
+
→ server creates PENDING entry
|
|
192
|
+
→ Owner approves in browser
|
|
193
|
+
→ server sends back signed agentToken
|
|
194
|
+
→ token saved to config (mode 600)
|
|
195
|
+
→ agent reconnects as ACTIVE
|
|
196
|
+
subsequent starts
|
|
197
|
+
→ sends { agentId, agentToken }
|
|
198
|
+
→ server verifies → ACTIVE immediately
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Config File
|
|
203
|
+
|
|
204
|
+
Location: `~/.thinknagent/config.json` (permissions: 600)
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"agentId": "uuid-v4",
|
|
209
|
+
"serverUrl": "ur.server.url",
|
|
210
|
+
"name": "my-server",
|
|
211
|
+
"roomId": "your-room-id",
|
|
212
|
+
"agentToken": "sha256-hmac-signed-token",
|
|
213
|
+
"role": "monitor",
|
|
214
|
+
"gpu": false,
|
|
215
|
+
"logs": [
|
|
216
|
+
"/var/log/syslog",
|
|
217
|
+
"/var/log/nginx/error.log"
|
|
218
|
+
],
|
|
219
|
+
"alerts": [
|
|
220
|
+
{ "id": "cpu-high", "metric": "cpu.usage", "op": "gt", "value": 85, "for": 60, "severity": "warning" },
|
|
221
|
+
{ "id": "cpu-crit", "metric": "cpu.usage", "op": "gt", "value": 95, "for": 30, "severity": "critical" },
|
|
222
|
+
{ "id": "mem-high", "metric": "memory.usedPct", "op": "gt", "value": 85, "for": 60, "severity": "warning" },
|
|
223
|
+
{ "id": "disk-root", "metric": "disk./", "op": "gt", "value": 90, "for": 0, "severity": "critical" }
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Run as a Service (Recommended)
|
|
231
|
+
|
|
232
|
+
Keep the agent running after SSH disconnect:
|
|
233
|
+
|
|
234
|
+
**Using pm2:**
|
|
235
|
+
```bash
|
|
236
|
+
npm install -g pm2
|
|
237
|
+
pm2 start $(which thinknagent) --name thinknagent -- start
|
|
238
|
+
pm2 save
|
|
239
|
+
pm2 startup
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Using systemd:**
|
|
243
|
+
```bash
|
|
244
|
+
sudo nano /etc/systemd/system/app.service
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
```ini
|
|
248
|
+
[Unit]
|
|
249
|
+
Description=ThinkNCollab Agent
|
|
250
|
+
After=network.target
|
|
251
|
+
|
|
252
|
+
[Service]
|
|
253
|
+
Type=simple
|
|
254
|
+
User=ubuntu
|
|
255
|
+
ExecStart=/home/ubuntu/.npm-global/bin/thinknagent start
|
|
256
|
+
Restart=always
|
|
257
|
+
RestartSec=5
|
|
258
|
+
|
|
259
|
+
[Install]
|
|
260
|
+
WantedBy=multi-user.target
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
sudo systemctl enable thinknagent
|
|
265
|
+
sudo systemctl start thinknagent
|
|
266
|
+
sudo systemctl status thinknagent
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Troubleshooting
|
|
272
|
+
|
|
273
|
+
**Permission denied**
|
|
274
|
+
```bash
|
|
275
|
+
chmod +x $(which thinknagent)
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**node-pty build error**
|
|
279
|
+
```bash
|
|
280
|
+
sudo apt-get install -y build-essential python3
|
|
281
|
+
npm install -g thinknagent
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Registration rejected: Invalid or revoked credentials**
|
|
285
|
+
```bash
|
|
286
|
+
thinknagent revoke
|
|
287
|
+
thinknagent init --server https://thinkncollab.com --name my-server --room <roomId>
|
|
288
|
+
thinknagent start
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Agent connects but not showing in DevOps Wall**
|
|
292
|
+
|
|
293
|
+
Refresh the DevOps Wall page — the agent list updates on page load.
|
|
294
|
+
|
|
295
|
+
**Metrics not updating**
|
|
296
|
+
|
|
297
|
+
Make sure agent is approved and `connected: true`. Check:
|
|
298
|
+
```bash
|
|
299
|
+
thinknagent status
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Requirements
|
|
305
|
+
|
|
306
|
+
- Node.js v18+
|
|
307
|
+
- Linux or macOS
|
|
308
|
+
- `build-essential` + `python3` (for shell feature)
|
|
309
|
+
- Outbound HTTPS/WSS to your ThinkNCollab server
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
MIT © [ThinkNCollab](https://thinkncollab.com)
|