Fix data type and mib for coretemp sysctl in FreeBSD plugin
Vladimir Kobal committed
Aug 17, 2017 at 21:18 UTC
1d2e795ddcc1a70ceca24e9550d6fc0c49c2c139
1 file changed
+12
-9
src/freebsd_sysctl.c
+12
-9
@@ -379,18 +379,21 @@ int do_dev_cpu_temperature(int update_every, usec_t dt) {
379
(void)dt;
380
381
int i;
382
- static int mib[4] = {0, 0, 0, 0};
383
- static long *pcpu_temperature = NULL;
382
+ static int *mib = NULL;
383
+ static int *pcpu_temperature = NULL;
384
static int old_number_of_cpus = 0;
385
char char_mib[MAX_INT_DIGITS + 21];
386
char char_rd[MAX_INT_DIGITS + 9];
387
388
- if(unlikely(number_of_cpus != old_number_of_cpus))
389
- pcpu_temperature = reallocz(pcpu_temperature, sizeof(long) * number_of_cpus);
388
+ if(unlikely(number_of_cpus != old_number_of_cpus)) {
389
+ pcpu_temperature = reallocz(pcpu_temperature, sizeof(int) * number_of_cpus);
390
+ mib = reallocz(mib, sizeof(int) * number_of_cpus * 4);
391
+ if (unlikely(number_of_cpus > old_number_of_cpus))
392
+ memset(&mib[old_number_of_cpus * 4], 0, sizeof(RRDDIM) * (number_of_cpus - old_number_of_cpus));
393
+ }
394
for (i = 0; i < number_of_cpus; i++) {
391
- mib[2] = i;
395
sprintf(char_mib, "dev.cpu.%d.temperature", i);
393
- if (unlikely(GETSYSCTL_SIMPLE(char_mib, mib, pcpu_temperature[i]))) {
396
+ if (unlikely(getsysctl_simple(char_mib, &mib[i * 4], 4, &pcpu_temperature[i], sizeof(int)))) {
397
error("DISABLED: cpu.temperature chart");
398
error("DISABLED: dev.cpu.temperature module");
399
return 1;
@@ -418,17 +421,17 @@ int do_dev_cpu_temperature(int update_every, usec_t dt) {
421
"degree",
422
1050,
423
update_every,
421
- RRDSET_TYPE_STACKED
424
+ RRDSET_TYPE_LINE
425
);
426
} else rrdset_next(st);
427
428
for (i = 0; i < number_of_cpus; i++) {
429
if (unlikely(!rd_pcpu_temperature[i])) {
430
sprintf(char_rd, "cpu%d.temp", i);
428
- rd_pcpu_temperature[i] = rrddim_add(st, char_rd, NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
431
+ rd_pcpu_temperature[i] = rrddim_add(st, char_rd, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
432
}
433
431
- rrddim_set_by_pointer(st, rd_pcpu_temperature[i], pcpu_temperature[i]);
434
+ rrddim_set_by_pointer(st, rd_pcpu_temperature[i], (collected_number) ((double)pcpu_temperature[i] / 10 - 273.15));
435
}
436
437
rrdset_done(st);