summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-31 00:46:10 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-31 00:46:10 +0200
commit1b0085c2e7196aa77d605e8cb1863064a8e5189c (patch)
tree64ad8da8000bf7195b7ad7daa4406e8d6be25354
parentd6d394fb0e1d04bbdb9304dcedad933878846266 (diff)
downloadmonitoring-plugins-1b0085c2e7196aa77d605e8cb1863064a8e5189c.tar.gz
Fixes problems after a4cf2e79f75dce3828be21726f10c755f652f710
-rw-r--r--plugins/check_disk.c2
-rw-r--r--plugins/check_disk.d/utils_disk.c62
-rw-r--r--plugins/check_disk.d/utils_disk.h2
3 files changed, 41 insertions, 25 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index e53ec87f..515ddff0 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1112,7 +1112,7 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_
1112 get_unit_string(unit), (uintmax_t)(measurement_unit.total_bytes / unit), get_unit_string(unit)); 1112 get_unit_string(unit), (uintmax_t)(measurement_unit.total_bytes / unit), get_unit_string(unit));
1113 } else { 1113 } else {
1114 xasprintf(&freespace_bytes_sc.output, "Free space absolute: %s (of %s)", humanize_byte_value(measurement_unit.free_bytes, false), 1114 xasprintf(&freespace_bytes_sc.output, "Free space absolute: %s (of %s)", humanize_byte_value(measurement_unit.free_bytes, false),
1115 humanize_byte_value(measurement_unit.total_bytes, false)); 1115 humanize_byte_value((unsigned long long)measurement_unit.total_bytes, false));
1116 } 1116 }
1117 1117
1118 mp_perfdata used_space = perfdata_init(); 1118 mp_perfdata used_space = perfdata_init();
diff --git a/plugins/check_disk.d/utils_disk.c b/plugins/check_disk.d/utils_disk.c
index a78b4eae..eec1282b 100644
--- a/plugins/check_disk.d/utils_disk.c
+++ b/plugins/check_disk.d/utils_disk.c
@@ -309,7 +309,7 @@ measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem fil
309 309
310#define RANDOM_STRING_LENGTH 64 310#define RANDOM_STRING_LENGTH 64
311 311
312char *humanize_byte_value(uintmax_t value, bool use_si_units) { 312char *humanize_byte_value(unsigned long long value, bool use_si_units) {
313 // Idea: A reasonable output should have at most 3 orders of magnitude 313 // Idea: A reasonable output should have at most 3 orders of magnitude
314 // before the decimal separator 314 // before the decimal separator
315 // 353GiB is ok, 2444 GiB should be 2.386 TiB 315 // 353GiB is ok, 2444 GiB should be 2.386 TiB
@@ -317,36 +317,52 @@ char *humanize_byte_value(uintmax_t value, bool use_si_units) {
317 if (result == NULL) { 317 if (result == NULL) {
318 die(STATE_UNKNOWN, _("allocation failed")); 318 die(STATE_UNKNOWN, _("allocation failed"));
319 } 319 }
320 const byte_unit KibiBytes_factor = 1024;
321 const byte_unit MebiBytes_factor = 1048576;
322 const byte_unit GibiBytes_factor = 1073741824;
323 const byte_unit TebiBytes_factor = 1099511627776;
324 const byte_unit PebiBytes_factor = 1125899906842624;
325 const byte_unit ExbiBytes_factor = 1152921504606846976;
326 const byte_unit KiloBytes_factor = 1000;
327 const byte_unit MegaBytes_factor = 1000000;
328 const byte_unit GigaBytes_factor = 1000000000;
329 const byte_unit TeraBytes_factor = 1000000000000;
330 const byte_unit PetaBytes_factor = 1000000000000000;
331 const byte_unit ExaBytes_factor = 1000000000000000000;
320 332
321 if (use_si_units) { 333 if (use_si_units) {
322 // SI units, powers of 10 334 // SI units, powers of 10
323 if (value < KiloBytes) { 335 if (value < KiloBytes_factor) {
324 snprintf(result, RANDOM_STRING_LENGTH, "%ju B", value); 336 snprintf(result, RANDOM_STRING_LENGTH, "%llu B", value);
325 } else if (value < MegaBytes) { 337 } else if (value < MegaBytes_factor) {
326 snprintf(result, RANDOM_STRING_LENGTH, "%ju KB", value / KiloBytes); 338 snprintf(result, RANDOM_STRING_LENGTH, "%llu KB", value / KiloBytes_factor);
327 } else if (value < GigaBytes) { 339 } else if (value < GigaBytes_factor) {
328 snprintf(result, RANDOM_STRING_LENGTH, "%ju MB", value / MegaBytes); 340 snprintf(result, RANDOM_STRING_LENGTH, "%llu MB", value / MegaBytes_factor);
329 } else if (value < TeraBytes) { 341 } else if (value < TeraBytes_factor) {
330 snprintf(result, RANDOM_STRING_LENGTH, "%ju GB", value / GigaBytes); 342 snprintf(result, RANDOM_STRING_LENGTH, "%llu GB", value / GigaBytes_factor);
331 } else if (value < PetaBytes) { 343 } else if (value < PetaBytes_factor) {
332 snprintf(result, RANDOM_STRING_LENGTH, "%ju TB", value / TeraBytes); 344 snprintf(result, RANDOM_STRING_LENGTH, "%llu TB", value / TeraBytes_factor);
345 } else if (value < ExaBytes_factor) {
346 snprintf(result, RANDOM_STRING_LENGTH, "%llu PB", value / PetaBytes_factor);
333 } else { 347 } else {
334 snprintf(result, RANDOM_STRING_LENGTH, "%ju PB", value / PetaBytes); 348 snprintf(result, RANDOM_STRING_LENGTH, "%llu EB", value / ExaBytes_factor);
335 } 349 }
336 } else { 350 } else {
337 // IEC units, powers of 2 ^ 10 351 // IEC units, powers of 2 ^ 10
338 if (value < KibiBytes) { 352 if (value < KibiBytes_factor) {
339 snprintf(result, RANDOM_STRING_LENGTH, "%ju B", value); 353 snprintf(result, RANDOM_STRING_LENGTH, "%llu B", value);
340 } else if (value < MebiBytes) { 354 } else if (value < MebiBytes_factor) {
341 snprintf(result, RANDOM_STRING_LENGTH, "%ju KiB", value / KibiBytes); 355 snprintf(result, RANDOM_STRING_LENGTH, "%llu KiB", value / KibiBytes_factor);
342 } else if (value < GibiBytes) { 356 } else if (value < GibiBytes_factor) {
343 snprintf(result, RANDOM_STRING_LENGTH, "%ju MiB", value / MebiBytes); 357 snprintf(result, RANDOM_STRING_LENGTH, "%llu MiB", value / MebiBytes_factor);
344 } else if (value < TebiBytes) { 358 } else if (value < TebiBytes_factor) {
345 snprintf(result, RANDOM_STRING_LENGTH, "%ju GiB", value / GibiBytes); 359 snprintf(result, RANDOM_STRING_LENGTH, "%llu GiB", value / GibiBytes_factor);
346 } else if (value < PebiBytes) { 360 } else if (value < PebiBytes_factor) {
347 snprintf(result, RANDOM_STRING_LENGTH, "%ju TiB", value / TebiBytes); 361 snprintf(result, RANDOM_STRING_LENGTH, "%llu TiB", value / TebiBytes_factor);
362 } else if (value < ExbiBytes_factor) {
363 snprintf(result, RANDOM_STRING_LENGTH, "%llu PiB", value / PebiBytes_factor);
348 } else { 364 } else {
349 snprintf(result, RANDOM_STRING_LENGTH, "%ju PiB", value / PebiBytes); 365 snprintf(result, RANDOM_STRING_LENGTH, "%llu EiB", value / ExbiBytes_factor);
350 } 366 }
351 } 367 }
352 368
diff --git a/plugins/check_disk.d/utils_disk.h b/plugins/check_disk.d/utils_disk.h
index 1f574695..6831d1fd 100644
--- a/plugins/check_disk.d/utils_disk.h
+++ b/plugins/check_disk.d/utils_disk.h
@@ -154,4 +154,4 @@ bool np_regex_match_mount_entry(struct mount_entry *, regex_t *);
154char *get_unit_string(byte_unit_enum); 154char *get_unit_string(byte_unit_enum);
155check_disk_config check_disk_config_init(); 155check_disk_config check_disk_config_init();
156 156
157char *humanize_byte_value(uintmax_t value, bool use_si_units); 157char *humanize_byte_value(unsigned long long value, bool use_si_units);