@cryptotaxi247 / netdata-1 / commits / 5e2d756a4

daemon status 26b (#20041)

* polishing of dmi decoding * added system vendor, product name and product type to host labels * rename added rrdhost labels

Costa Tsaousis committed Apr 3, 2025 at 12:08 UTC 5e2d756a4c62c47ab6838a2a0307e65ba230f396
4 files changed +38 -5
src/daemon/status-file-dmi.c
+18 -5
@@ -51,6 +51,8 @@ static void dmi_clean_field_placeholder(char *buf, size_t buf_size) {
51 {"unspecified", ""},
52 {"x.x", ""},
53 {"(null)", ""},
54 + {"0123456789", ""},
55 + {"SKU", ""},
56 };
57
58 for (size_t i = 0; i < _countof(placeholders); i++) {
@@ -273,7 +275,7 @@ static const char *dmi_chassis_type_to_string(int chassis_type) {
275 case 22: return "raid";
276 case 23: return "server"; /* "rack-mount-server" */
277 case 24: return "desktop"; /* "sealed-desktop" */
276 - case 25: return "multimount-chassis";
278 + case 25: return "server"; /* "multimount-chassis" */
279 case 26: return "compact-pci";
280 case 27: return "blade"; /* "advanced-tca" */
281 case 28: return "blade";
@@ -308,21 +310,24 @@ static void dmi_clean_field(char *buf, size_t buf_size) {
310 if(!buf || !buf_size) return;
311
312 // replace non-ascii characters and control characters with spaces
311 - for (size_t i = 0; i < sizeof(buf) && buf[i]; i++) {
313 + for (size_t i = 0; i < buf_size && buf[i]; i++) {
314 if (!isascii((uint8_t)buf[i]) || iscntrl((uint8_t)buf[i]))
315 buf[i] = ' ';
316 }
317
318 // detect if all characters are symbols
319 bool contains_alnum = false;
318 - for (size_t i = 0; i < sizeof(buf) && buf[i]; i++) {
320 + for (size_t i = 0; i < buf_size && buf[i]; i++) {
321 if (isalnum((uint8_t)buf[i])) {
322 contains_alnum = true;
323 break;
324 }
325 }
324 - if (!contains_alnum || !buf[0])
326 +
327 + if (!contains_alnum || !buf[0]) {
328 + buf[0] = '\0';
329 return;
330 + }
331
332 // remove leading, trailing and duplicate spaces
333 trim_all(buf);
@@ -368,7 +373,7 @@ static void linux_get_dmi_field(const char *field, const char *alt, char *dst, s
373 if (!filename[0])
374 return;
375
371 - char buf[256];
376 + char buf[MAX(256, dst_size)];
377 if (read_txt_file(filename, buf, sizeof(buf)) != 0)
378 return;
379
@@ -1357,6 +1362,10 @@ void fill_dmi_info(DAEMON_STATUS_FILE *ds) {
1362 safecpy(ds->hw.sys.vendor, ds->hw.chassis.vendor);
1363 if(!ds->hw.sys.vendor[0])
1364 safecpy(ds->hw.sys.vendor, ds->hw.bios.vendor);
1365 + if(!ds->hw.sys.vendor[0] && strstr(ds->hw.product.name, "Raspberry") != NULL)
1366 + safecpy(ds->hw.sys.vendor, "Raspberry");
1367 + if(!ds->hw.sys.vendor[0] && (strstr(ds->hw.product.name, "VirtualMac") != NULL || strstr(ds->hw.board.name, "Apple") != NULL))
1368 + safecpy(ds->hw.sys.vendor, "Apple");
1369 if(!ds->hw.sys.vendor[0])
1370 safecpy(ds->hw.sys.vendor, "Unknown");
1371
@@ -1366,6 +1375,10 @@ void fill_dmi_info(DAEMON_STATUS_FILE *ds) {
1375 if(!ds->hw.product.name[0])
1376 safecpy(ds->hw.product.name, "Unknown");
1377
1378 + // make sure we have a chassis type
1379 + if(!ds->hw.chassis.type[0])
1380 + safecpy(ds->hw.chassis.type, "Unknown");
1381 +
1382 // make sure the cloud provider and cloud instance loaded from system-info.sh are preferred
1383 finalize_vendor_product_vm(ds);
1384 }
src/daemon/status-file.c
+12
@@ -1459,6 +1459,18 @@ const char *daemon_status_file_get_fatal_thread(void) {
1459 return session_status.fatal.thread;
1460 }
1461
1462 +const char *daemon_status_file_get_hw_sys_vendor(void) {
1463 + return session_status.hw.sys.vendor;
1464 +}
1465 +
1466 +const char *daemon_status_file_get_hw_product_name(void) {
1467 + return session_status.hw.product.name;
1468 +}
1469 +
1470 +const char *daemon_status_file_get_hw_chassis_type(void) {
1471 + return session_status.hw.chassis.type;
1472 +}
1473 +
1474 pid_t daemon_status_file_get_fatal_thread_id(void) {
1475 return session_status.fatal.thread_id;
1476 }
src/daemon/status-file.h
+4
@@ -181,6 +181,10 @@ const char *daemon_status_file_get_fatal_errno(void);
181 const char *daemon_status_file_get_fatal_stack_trace(void);
182 const char *daemon_status_file_get_fatal_thread(void);
183 const char *daemon_status_file_get_stack_trace_backend(void);
184 +const char *daemon_status_file_get_hw_sys_vendor(void);
185 +const char *daemon_status_file_get_hw_product_name(void);
186 +const char *daemon_status_file_get_hw_chassis_type(void);
187 +
188 pid_t daemon_status_file_get_fatal_thread_id(void);
189 long daemon_status_file_get_fatal_line(void);
190 DAEMON_STATUS daemon_status_file_get_status(void);
src/database/rrdhost-system-info.c
+4
@@ -240,6 +240,10 @@ void rrdhost_system_info_to_rrdlabels(struct rrdhost_system_info *system_info, R
240
241 if (system_info->prebuilt_dist)
242 rrdlabels_add(labels, "_prebuilt_dist", system_info->prebuilt_dist, RRDLABEL_SRC_AUTO);
243 +
244 + rrdlabels_add(labels, "_hw_sys_vendor", daemon_status_file_get_hw_sys_vendor(), RRDLABEL_SRC_AUTO);
245 + rrdlabels_add(labels, "_hw_product_name", daemon_status_file_get_hw_product_name(), RRDLABEL_SRC_AUTO);
246 + rrdlabels_add(labels, "_hw_product_type", daemon_status_file_get_hw_chassis_type(), RRDLABEL_SRC_AUTO);
247 }
248
249 int rrdhost_system_info_detect(struct rrdhost_system_info *system_info) {