@daemonitor/plugins 1.0.1 → 1.0.3
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/dist/plugins/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { EwelinkPlugin } from "./monitoring/EwelinkPlugin.js";
|
|
2
2
|
import { OSPlugin } from "./monitoring/OSPlugin.js";
|
|
3
3
|
import { PM2Plugin } from "./monitoring/PM2Plugin.js";
|
|
4
|
+
import { MongoDBPlugin } from "./monitoring/MongoDBPlugin.js";
|
|
4
5
|
import { WebsitePlugin } from "./monitoring/WebsitePlugin.js";
|
|
5
6
|
export default {
|
|
6
7
|
EwelinkPlugin,
|
|
8
|
+
MongoDBPlugin,
|
|
7
9
|
OSPlugin,
|
|
8
10
|
PM2Plugin,
|
|
9
11
|
WebsitePlugin
|
|
@@ -19,7 +19,8 @@ export class EwelinkPlugin extends MonitoringPlugin {
|
|
|
19
19
|
email: process.env.EWELINK_EMAIL,
|
|
20
20
|
password: process.env.EWELINK_PASSWORD
|
|
21
21
|
});
|
|
22
|
-
this.refresh().then(() => {
|
|
22
|
+
this.refresh().then(() => {
|
|
23
|
+
});
|
|
23
24
|
return Promise.resolve();
|
|
24
25
|
}
|
|
25
26
|
async get(key) {
|
|
@@ -39,9 +40,14 @@ export class EwelinkPlugin extends MonitoringPlugin {
|
|
|
39
40
|
async refresh() {
|
|
40
41
|
/* get all devices */
|
|
41
42
|
return this.connection.getDevices().then((devices) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (Array.isArray(devices) && (Symbol.iterator in Object(devices))) {
|
|
44
|
+
this.devices = devices;
|
|
45
|
+
for (const device of this.devices) {
|
|
46
|
+
this.send(device, device.deviceid);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.error("EwelinkPlugin: Invalid response from getDevices()", devices);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
53
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MonitoringPlugin } from "../../lib/MonitoringPlugin.js";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
export class MongoDBPlugin extends MonitoringPlugin {
|
|
4
|
+
childProcess;
|
|
5
|
+
constructor() {
|
|
6
|
+
super("mongodb", "mongodb", "MongoDB Monitoring Plugin");
|
|
7
|
+
}
|
|
8
|
+
async setup() {
|
|
9
|
+
// no setup required
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
|
12
|
+
async refresh() {
|
|
13
|
+
// get mongodb db.serverStatus
|
|
14
|
+
}
|
|
15
|
+
async monitor() {
|
|
16
|
+
// this.refreshTimer = setInterval(this.refresh.bind(this), this.config.refreshInterval || 5000)
|
|
17
|
+
this.childProcess = spawn("mongostat", ["--json", "mongodb://localhost:27017", "10"]);
|
|
18
|
+
this.childProcess.stdout.on("data", (input) => {
|
|
19
|
+
const jsonObject = JSON.parse(input.toString());
|
|
20
|
+
if (!jsonObject["localhost:27017"]) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const data = jsonObject["localhost:27017"];
|
|
24
|
+
this.send(data, "mongodb-localhost:27017");
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async teardown() {
|
|
28
|
+
this.childProcess.kill();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -24,6 +24,7 @@ export class PM2Plugin extends MonitoringPlugin {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
async refresh() {
|
|
27
|
+
const instanceCounts = {};
|
|
27
28
|
pm2.list(async (err, list) => {
|
|
28
29
|
if (!err) {
|
|
29
30
|
for (const p of list) {
|
|
@@ -42,7 +43,12 @@ export class PM2Plugin extends MonitoringPlugin {
|
|
|
42
43
|
// windowsHide,
|
|
43
44
|
// kill_retry_time
|
|
44
45
|
} = p;
|
|
45
|
-
|
|
46
|
+
if (instanceCounts[name] === undefined) {
|
|
47
|
+
instanceCounts[name] = 0;
|
|
48
|
+
}
|
|
49
|
+
const index = instanceCounts[name]++;
|
|
50
|
+
const instance_id = `pm2-${name}-${index}`;
|
|
51
|
+
let { username, watch, axm_options, axm_monitor, node_version, unique_id, pm_name, restart_time, created_at, unstable_restarts, autorestart, status, pm_uptime } = p.pm2_env;
|
|
46
52
|
const payload = {
|
|
47
53
|
updated: (new Date()).getTime(),
|
|
48
54
|
created_at,
|
|
@@ -63,7 +69,7 @@ export class PM2Plugin extends MonitoringPlugin {
|
|
|
63
69
|
status,
|
|
64
70
|
pm_uptime,
|
|
65
71
|
};
|
|
66
|
-
await this.send(payload,
|
|
72
|
+
await this.send(payload, instance_id);
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
else {
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daemonitor/plugins",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "daemonitor plugins",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
8
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|