code-poltergeist-system-monitor 1.1.2 → 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.
Files changed (2) hide show
  1. package/index.js +9 -31
  2. 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://http://3.27.204.114:3001/upload";
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,39 +120,13 @@ async function sendLogFileToBackend(filePath) {
116
120
  },
117
121
  });
118
122
  console.log("Log file sent to backend:", response.data);
123
+
124
+ fs.unlinkSync(filePath);
125
+ console.log(`Deleted local log file: ${filePath}`);
119
126
  } catch (error) {
120
127
  console.error("Error sending log file to backend:", error.message);
121
128
  }
122
129
  }
123
130
 
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);
131
+ setInterval(logSystemInfo, 10000);
154
132
  logSystemInfo();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-poltergeist-system-monitor",
3
- "version": "1.1.2",
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": {