@aidalinfo/aegis-agent 0.2.0 → 0.2.1
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/dist/bin.js +19 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -7,14 +7,25 @@ import { execSync as execSync2 } from "child_process";
|
|
|
7
7
|
// src/config.ts
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { readFileSync } from "fs";
|
|
10
|
+
import { join } from "path";
|
|
10
11
|
import { hostname } from "os";
|
|
11
12
|
var ConfigSchema = z.object({
|
|
12
13
|
interval: z.coerce.number().int().min(5).default(30),
|
|
13
14
|
endpoint: z.string().url(),
|
|
14
15
|
apiKey: z.string().min(1),
|
|
15
16
|
mode: z.enum(["core", "full"]).default("core"),
|
|
16
|
-
hostname: z.string().
|
|
17
|
+
hostname: z.string().min(1)
|
|
17
18
|
});
|
|
19
|
+
function resolveHostname() {
|
|
20
|
+
const hostRoot = process.env.AEGIS_HOST_ROOT;
|
|
21
|
+
if (hostRoot) {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(join(hostRoot, "/etc/hostname"), "utf8").trim();
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return hostname();
|
|
28
|
+
}
|
|
18
29
|
function loadConfig(configPath = "/etc/aegis-agent/config.json") {
|
|
19
30
|
let fileConfig = {};
|
|
20
31
|
try {
|
|
@@ -27,24 +38,24 @@ function loadConfig(configPath = "/etc/aegis-agent/config.json") {
|
|
|
27
38
|
...process.env.AEGIS_ENDPOINT !== void 0 && { endpoint: process.env.AEGIS_ENDPOINT },
|
|
28
39
|
...process.env.AEGIS_API_KEY !== void 0 && { apiKey: process.env.AEGIS_API_KEY },
|
|
29
40
|
...process.env.AEGIS_MODE !== void 0 && { mode: process.env.AEGIS_MODE },
|
|
30
|
-
|
|
41
|
+
hostname: process.env.AEGIS_HOSTNAME ?? fileConfig.hostname ?? resolveHostname()
|
|
31
42
|
});
|
|
32
43
|
}
|
|
33
44
|
|
|
34
45
|
// src/metrics/hostpaths.ts
|
|
35
46
|
import { readFile, statfs } from "fs/promises";
|
|
36
|
-
import { join } from "path";
|
|
47
|
+
import { join as join2 } from "path";
|
|
37
48
|
var HOST_PROC = process.env.AEGIS_HOST_PROC || "/proc";
|
|
38
49
|
var HOST_SYS = process.env.AEGIS_HOST_SYS || "/sys";
|
|
39
50
|
var HOST_ROOT = process.env.AEGIS_HOST_ROOT || "";
|
|
40
51
|
function readProc(rel) {
|
|
41
|
-
return readFile(
|
|
52
|
+
return readFile(join2(HOST_PROC, rel), "utf8");
|
|
42
53
|
}
|
|
43
54
|
function readHostFile(absPath) {
|
|
44
|
-
return readFile(HOST_ROOT ?
|
|
55
|
+
return readFile(HOST_ROOT ? join2(HOST_ROOT, absPath) : absPath, "utf8");
|
|
45
56
|
}
|
|
46
57
|
function statHostFs(mount) {
|
|
47
|
-
return statfs(HOST_ROOT ?
|
|
58
|
+
return statfs(HOST_ROOT ? join2(HOST_ROOT, mount) : mount);
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
// src/metrics/proc-parse.ts
|
|
@@ -146,6 +157,7 @@ var PSEUDO_FS = /* @__PURE__ */ new Set([
|
|
|
146
157
|
"binfmt_misc",
|
|
147
158
|
"efivarfs"
|
|
148
159
|
]);
|
|
160
|
+
var DOCKER_FILE_MOUNTS = /* @__PURE__ */ new Set(["/etc/hostname", "/etc/resolv.conf", "/etc/hosts"]);
|
|
149
161
|
function parseMounts(content) {
|
|
150
162
|
const seen = /* @__PURE__ */ new Set();
|
|
151
163
|
const out = [];
|
|
@@ -154,6 +166,7 @@ function parseMounts(content) {
|
|
|
154
166
|
if (parts.length < 3) continue;
|
|
155
167
|
const [, mount, fstype] = parts;
|
|
156
168
|
if (PSEUDO_FS.has(fstype)) continue;
|
|
169
|
+
if (DOCKER_FILE_MOUNTS.has(mount)) continue;
|
|
157
170
|
if (seen.has(mount)) continue;
|
|
158
171
|
seen.add(mount);
|
|
159
172
|
out.push(mount);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
5
5
|
endpoint: z.ZodString;
|
|
6
6
|
apiKey: z.ZodString;
|
|
7
7
|
mode: z.ZodDefault<z.ZodEnum<["core", "full"]>>;
|
|
8
|
-
hostname: z.
|
|
8
|
+
hostname: z.ZodString;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
interval: number;
|
|
11
11
|
endpoint: string;
|
|
@@ -15,9 +15,9 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
15
15
|
}, {
|
|
16
16
|
endpoint: string;
|
|
17
17
|
apiKey: string;
|
|
18
|
+
hostname: string;
|
|
18
19
|
interval?: number | undefined;
|
|
19
20
|
mode?: "core" | "full" | undefined;
|
|
20
|
-
hostname?: string | undefined;
|
|
21
21
|
}>;
|
|
22
22
|
type Config = z.infer<typeof ConfigSchema>;
|
|
23
23
|
declare function loadConfig(configPath?: string): Config;
|
package/dist/index.js
CHANGED
|
@@ -113,6 +113,7 @@ var PSEUDO_FS = /* @__PURE__ */ new Set([
|
|
|
113
113
|
"binfmt_misc",
|
|
114
114
|
"efivarfs"
|
|
115
115
|
]);
|
|
116
|
+
var DOCKER_FILE_MOUNTS = /* @__PURE__ */ new Set(["/etc/hostname", "/etc/resolv.conf", "/etc/hosts"]);
|
|
116
117
|
function parseMounts(content) {
|
|
117
118
|
const seen = /* @__PURE__ */ new Set();
|
|
118
119
|
const out = [];
|
|
@@ -121,6 +122,7 @@ function parseMounts(content) {
|
|
|
121
122
|
if (parts.length < 3) continue;
|
|
122
123
|
const [, mount, fstype] = parts;
|
|
123
124
|
if (PSEUDO_FS.has(fstype)) continue;
|
|
125
|
+
if (DOCKER_FILE_MOUNTS.has(mount)) continue;
|
|
124
126
|
if (seen.has(mount)) continue;
|
|
125
127
|
seen.add(mount);
|
|
126
128
|
out.push(mount);
|
|
@@ -303,14 +305,25 @@ async function collectMetrics(config) {
|
|
|
303
305
|
// src/config.ts
|
|
304
306
|
import { z } from "zod";
|
|
305
307
|
import { readFileSync } from "fs";
|
|
308
|
+
import { join as join2 } from "path";
|
|
306
309
|
import { hostname } from "os";
|
|
307
310
|
var ConfigSchema = z.object({
|
|
308
311
|
interval: z.coerce.number().int().min(5).default(30),
|
|
309
312
|
endpoint: z.string().url(),
|
|
310
313
|
apiKey: z.string().min(1),
|
|
311
314
|
mode: z.enum(["core", "full"]).default("core"),
|
|
312
|
-
hostname: z.string().
|
|
315
|
+
hostname: z.string().min(1)
|
|
313
316
|
});
|
|
317
|
+
function resolveHostname() {
|
|
318
|
+
const hostRoot = process.env.AEGIS_HOST_ROOT;
|
|
319
|
+
if (hostRoot) {
|
|
320
|
+
try {
|
|
321
|
+
return readFileSync(join2(hostRoot, "/etc/hostname"), "utf8").trim();
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return hostname();
|
|
326
|
+
}
|
|
314
327
|
function loadConfig(configPath = "/etc/aegis-agent/config.json") {
|
|
315
328
|
let fileConfig = {};
|
|
316
329
|
try {
|
|
@@ -323,7 +336,7 @@ function loadConfig(configPath = "/etc/aegis-agent/config.json") {
|
|
|
323
336
|
...process.env.AEGIS_ENDPOINT !== void 0 && { endpoint: process.env.AEGIS_ENDPOINT },
|
|
324
337
|
...process.env.AEGIS_API_KEY !== void 0 && { apiKey: process.env.AEGIS_API_KEY },
|
|
325
338
|
...process.env.AEGIS_MODE !== void 0 && { mode: process.env.AEGIS_MODE },
|
|
326
|
-
|
|
339
|
+
hostname: process.env.AEGIS_HOSTNAME ?? fileConfig.hostname ?? resolveHostname()
|
|
327
340
|
});
|
|
328
341
|
}
|
|
329
342
|
export {
|