@daemonitor/plugins 1.1.21 → 1.1.23
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.
|
@@ -128,6 +128,38 @@ async function collectContainers(bin) {
|
|
|
128
128
|
catch (err) {
|
|
129
129
|
console.error("docker: inspect collection failed:", err.message);
|
|
130
130
|
}
|
|
131
|
+
// 4. For UNHEALTHY containers only, read the healthcheck's own last output.
|
|
132
|
+
//
|
|
133
|
+
// "1/13 containers unhealthy" says a problem exists and nothing about what it
|
|
134
|
+
// is. Docker already stores the failing command's output in
|
|
135
|
+
// .State.Health.Log[] — that is the actual error text, and without it an alert
|
|
136
|
+
// sends someone to ssh into the box to run the same healthcheck by hand.
|
|
137
|
+
//
|
|
138
|
+
// Read one container at a time and only for the unhealthy ones. The batched
|
|
139
|
+
// inspect above avoids .State.Health because the template errors for
|
|
140
|
+
// containers that have no healthcheck; a container reporting "(unhealthy)"
|
|
141
|
+
// necessarily has one, so this is safe, and it is a handful of calls at most
|
|
142
|
+
// precisely when something is wrong.
|
|
143
|
+
const unhealthy = containers.filter((c) => c.health === "unhealthy").slice(0, 5);
|
|
144
|
+
for (const c of unhealthy) {
|
|
145
|
+
try {
|
|
146
|
+
const { stdout } = await execAsync(`${bin} inspect --format '{{json .State.Health}}' ${c.id}`, EXEC_OPTS);
|
|
147
|
+
const h = JSON.parse(stdout.trim() || "null");
|
|
148
|
+
if (!h)
|
|
149
|
+
continue;
|
|
150
|
+
c.healthFailingStreak = Number(h.FailingStreak) || 0;
|
|
151
|
+
const last = Array.isArray(h.Log) && h.Log.length ? h.Log[h.Log.length - 1] : null;
|
|
152
|
+
if (last?.Output) {
|
|
153
|
+
// Healthcheck output is often multi-line and ends in a newline; collapse
|
|
154
|
+
// it so it fits an alert line, and keep the head where the error is.
|
|
155
|
+
c.healthOutput = String(last.Output).replace(/\s+/g, " ").trim().slice(0, 300);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
// Best-effort: an alert naming the container is still better than none.
|
|
160
|
+
console.error(`docker: health log read failed for ${c.name}:`, err.message);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
131
163
|
return containers;
|
|
132
164
|
}
|
|
133
165
|
export function createDockerPlugin() {
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daemonitor/plugins",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.23",
|
|
4
4
|
"description": "daemonitor plugins",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"prepublishOnly": "npm run build"
|
|
12
|
-
},
|
|
13
8
|
"files": [
|
|
14
9
|
"dist",
|
|
15
10
|
"types"
|
|
@@ -53,5 +48,9 @@
|
|
|
53
48
|
"bugs": {
|
|
54
49
|
"url": "https://github.com/daemonitor/plugins/issues"
|
|
55
50
|
},
|
|
56
|
-
"homepage": "https://github.com/daemonitor/plugins#readme"
|
|
57
|
-
|
|
51
|
+
"homepage": "https://github.com/daemonitor/plugins#readme",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc",
|
|
54
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
55
|
+
}
|
|
56
|
+
}
|