code-poltergeist-system-monitor 1.1.3 → 1.1.4
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 +9 -32
- 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();
|
@@ -95,11 +96,14 @@ async function logSystemInfo() {
|
|
95
96
|
},
|
96
97
|
};
|
97
98
|
|
99
|
+
// Ensure the log directory exists
|
98
100
|
if (!fs.existsSync(logDir)) {
|
99
101
|
fs.mkdirSync(logDir, { recursive: true });
|
100
102
|
}
|
101
103
|
|
104
|
+
// Write the log data to a file
|
102
105
|
fs.writeFileSync(logFile, JSON.stringify(logData, null, 2), "utf8");
|
106
|
+
await sendLogFileToBackend(logFile);
|
103
107
|
}
|
104
108
|
|
105
109
|
async function sendLogFileToBackend(filePath) {
|
@@ -116,40 +120,13 @@ async function sendLogFileToBackend(filePath) {
|
|
116
120
|
},
|
117
121
|
});
|
118
122
|
console.log("Log file sent to backend:", response.data);
|
119
|
-
|
123
|
+
|
124
|
+
fs.unlinkSync(filePath);
|
125
|
+
console.log(`Deleted local log file: ${filePath}`);
|
120
126
|
} catch (error) {
|
121
127
|
console.error("Error sending log file to backend:", error.message);
|
122
128
|
}
|
123
129
|
}
|
124
130
|
|
125
|
-
|
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
|
-
setInterval(logSystemInfo, 100);
|
131
|
+
setInterval(logSystemInfo, 10000);
|
155
132
|
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.4",
|
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": {
|