@daemonitor/plugins 1.0.2 → 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.
@@ -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
@@ -40,12 +40,15 @@ export class EwelinkPlugin extends MonitoringPlugin {
40
40
  async refresh() {
41
41
  /* get all devices */
42
42
  return this.connection.getDevices().then((devices) => {
43
- if (Array.isArray(devices)) {
43
+ if (Array.isArray(devices) && (Symbol.iterator in Object(devices))) {
44
44
  this.devices = devices;
45
45
  for (const device of this.devices) {
46
46
  this.send(device, device.deviceid);
47
47
  }
48
48
  }
49
+ else {
50
+ console.error("EwelinkPlugin: Invalid response from getDevices()", devices);
51
+ }
49
52
  });
50
53
  }
51
54
  async monitor() {
@@ -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
- let { username, watch, axm_options, axm_monitor, node_version, unique_id, restart_time, created_at, unstable_restarts, autorestart, status, pm_uptime } = p.pm2_env;
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, `${unique_id}-${pm_id}`);
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.2",
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": [