Query the size of the hw.intrnames mib instead of using of a fixed va… (#11159)
MikaelUrankar committed
May 24, 2021 at 16:40 UTC
4b130034f223a5034c241b8a3e905d8f8031747d
1 file changed
+44
-38
collectors/freebsd.plugin/freebsd_sysctl.c
+44
-38
@@ -641,52 +641,58 @@ int do_hw_intcnt(int update_every, usec_t dt) {
641
static int mib_hw_intrnames[2] = {0, 0};
642
static char *intrnames = NULL;
643
644
- size = nintr * (MAXCOMLEN + 1);
645
- if (unlikely(nintr != old_nintr))
646
- intrnames = reallocz(intrnames, size);
647
- if (unlikely(GETSYSCTL_WSIZE("hw.intrnames", mib_hw_intrnames, intrnames, size))) {
644
+ if (unlikely(GETSYSCTL_SIZE("hw.intrnames", mib_hw_intrnames, size))) {
645
error("DISABLED: system.intr chart");
646
error("DISABLED: system.interrupts chart");
647
error("DISABLED: hw.intrcnt module");
648
return 1;
649
} else {
650
+ if (unlikely(nintr != old_nintr))
651
+ intrnames = reallocz(intrnames, size);
652
+ if (unlikely(GETSYSCTL_WSIZE("hw.intrnames", mib_hw_intrnames, intrnames, size))) {
653
+ error("DISABLED: system.intr chart");
654
+ error("DISABLED: system.interrupts chart");
655
+ error("DISABLED: hw.intrcnt module");
656
+ return 1;
657
+ } else {
658
654
- // --------------------------------------------------------------------
655
-
656
- static RRDSET *st_interrupts = NULL;
657
-
658
- if (unlikely(!st_interrupts))
659
- st_interrupts = rrdset_create_localhost(
660
- "system",
661
- "interrupts",
662
- NULL,
663
- "interrupts",
664
- NULL,
665
- "System interrupts",
666
- "interrupts/s",
667
- "freebsd.plugin",
668
- "hw.intrcnt",
669
- NETDATA_CHART_PRIO_SYSTEM_INTERRUPTS,
670
- update_every,
671
- RRDSET_TYPE_STACKED
672
- );
673
- else
674
- rrdset_next(st_interrupts);
675
-
676
- for (i = 0; i < nintr; i++) {
677
- void *p;
678
-
679
- p = intrnames + i * (MAXCOMLEN + 1);
680
- if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) {
681
- RRDDIM *rd_interrupts = rrddim_find_active(st_interrupts, p);
682
-
683
- if (unlikely(!rd_interrupts))
684
- rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
685
-
686
- rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]);
659
+ // --------------------------------------------------------------------
660
+
661
+ static RRDSET *st_interrupts = NULL;
662
+
663
+ if (unlikely(!st_interrupts))
664
+ st_interrupts = rrdset_create_localhost(
665
+ "system",
666
+ "interrupts",
667
+ NULL,
668
+ "interrupts",
669
+ NULL,
670
+ "System interrupts",
671
+ "interrupts/s",
672
+ "freebsd.plugin",
673
+ "hw.intrcnt",
674
+ NETDATA_CHART_PRIO_SYSTEM_INTERRUPTS,
675
+ update_every,
676
+ RRDSET_TYPE_STACKED
677
+ );
678
+ else
679
+ rrdset_next(st_interrupts);
680
+
681
+ for (i = 0; i < nintr; i++) {
682
+ void *p;
683
+
684
+ p = intrnames + i * (strlen(intrnames) + 1);
685
+ if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) {
686
+ RRDDIM *rd_interrupts = rrddim_find_active(st_interrupts, p);
687
+
688
+ if (unlikely(!rd_interrupts))
689
+ rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
690
+
691
+ rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]);
692
+ }
693
}
694
+ rrdset_done(st_interrupts);
695
}
689
- rrdset_done(st_interrupts);
696
}
697
}
698