code-poltergeist-system-monitor 1.1.3 → 1.1.5
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/index.js +6 -31
- package/package.json +1 -1
package/index.js
CHANGED
@@ -9,9 +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://
|
12
|
+
const linkToBackend = "http://3.27.204.114:3001/upload";
|
13
13
|
const logDir = path.resolve(homeDir, "logfilesformonitor");
|
14
14
|
|
15
|
+
// Function to log system info and send it to backend
|
15
16
|
async function logSystemInfo() {
|
16
17
|
const logFile = path.join(logDir, `${Date.now()}.json`);
|
17
18
|
const cpu = os.cpus();
|
@@ -100,6 +101,7 @@ async function logSystemInfo() {
|
|
100
101
|
}
|
101
102
|
|
102
103
|
fs.writeFileSync(logFile, JSON.stringify(logData, null, 2), "utf8");
|
104
|
+
await sendLogFileToBackend(logFile);
|
103
105
|
}
|
104
106
|
|
105
107
|
async function sendLogFileToBackend(filePath) {
|
@@ -116,40 +118,13 @@ async function sendLogFileToBackend(filePath) {
|
|
116
118
|
},
|
117
119
|
});
|
118
120
|
console.log("Log file sent to backend:", response.data);
|
119
|
-
|
121
|
+
|
122
|
+
fs.unlinkSync(filePath);
|
123
|
+
console.log(`Deleted local log file: ${filePath}`);
|
120
124
|
} catch (error) {
|
121
125
|
console.error("Error sending log file to backend:", error.message);
|
122
126
|
}
|
123
127
|
}
|
124
128
|
|
125
|
-
async function sendAllLogsOnExit() {
|
126
|
-
const logFiles = fs.readdirSync(logDir);
|
127
|
-
|
128
|
-
for (const file of logFiles) {
|
129
|
-
const filePath = path.join(logDir, file);
|
130
|
-
await sendLogFileToBackend(filePath);
|
131
|
-
}
|
132
|
-
|
133
|
-
console.log("All log files sent to backend.");
|
134
|
-
}
|
135
|
-
|
136
|
-
function setupExitHandlers() {
|
137
|
-
process.on("exit", sendAllLogsOnExit);
|
138
|
-
|
139
|
-
process.on("SIGINT", () => {
|
140
|
-
sendAllLogsOnExit().then(() => {
|
141
|
-
process.exit();
|
142
|
-
});
|
143
|
-
});
|
144
|
-
|
145
|
-
process.on("SIGTERM", () => {
|
146
|
-
sendAllLogsOnExit().then(() => {
|
147
|
-
process.exit();
|
148
|
-
});
|
149
|
-
});
|
150
|
-
}
|
151
|
-
|
152
|
-
setupExitHandlers();
|
153
|
-
|
154
129
|
setInterval(logSystemInfo, 100);
|
155
130
|
logSystemInfo();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "code-poltergeist-system-monitor",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.5",
|
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": {
|