Separate getmntinfo module with simple patterns adopted
Vladimir Kobal committed
Mar 15, 2017 at 20:26 UTC
36afe35696f97f9dadbaebb85c9441a7659e847c
3 files changed
+215
-84
src/freebsd_sysctl.c
+206
-79
@@ -2701,23 +2701,223 @@ int do_net_inet6_icmp6_stats(int update_every, usec_t dt) {
2701
return 0;
2702
}
2703
2704
+// --------------------------------------------------------------------------------------------------------------------
2705
+// getmntinfo
2706
+
2707
+int do_getmntinfo(int update_every, usec_t dt) {
2708
+
2709
+#define DELAULT_EXLUDED_PATHS "/proc/*"
2710
+// taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes
2711
+#define DEFAULT_EXCLUDED_FILESYSTEMS "autofs procfs subfs devfs none"
2712
+#define CONFIG_SECTION_DISKSPACE "plugin:freebsd:getmntinfo"
2713
+
2714
+ static int do_space = -1, do_inodes = -1;
2715
+
2716
+ if (unlikely(do_space == -1)) {
2717
+ do_space = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
2718
+ do_inodes = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
2719
+ }
2720
+
2721
+ if (likely(do_space || do_inodes)) {
2722
+ struct statfs *mntbuf;
2723
+ int mntsize;
2724
+
2725
+ // there is no mount info in sysctl MIBs
2726
+ if (unlikely(!(mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)))) {
2727
+ error("FREEBSD: getmntinfo() failed");
2728
+ do_space = 0;
2729
+ error("DISABLED: disk_space.* charts");
2730
+ do_inodes = 0;
2731
+ error("DISABLED: disk_inodes.* charts");
2732
+ error("DISABLED: getmntinfo module");
2733
+ return 1;
2734
+ } else {
2735
+ // Data to be stored in DICTIONARY mount_points.
2736
+ // This DICTIONARY is used to lookup the settings of the mount point on each iteration.
2737
+ struct mount_point_metadata {
2738
+ int do_space;
2739
+ int do_inodes;
2740
+
2741
+ size_t collected; // the number of times this has been collected
2742
+
2743
+ RRDSET *st_space;
2744
+ RRDDIM *rd_space_used;
2745
+ RRDDIM *rd_space_avail;
2746
+ RRDDIM *rd_space_reserved;
2747
+
2748
+ RRDSET *st_inodes;
2749
+ RRDDIM *rd_inodes_used;
2750
+ RRDDIM *rd_inodes_avail;
2751
+ };
2752
+ static DICTIONARY *mount_points = NULL;
2753
+ static SIMPLE_PATTERN *excluded_mountpoints = NULL;
2754
+ static SIMPLE_PATTERN *excluded_filesystems = NULL;
2755
+ int i;
2756
+
2757
+ if(unlikely(!mount_points)) {
2758
+
2759
+ excluded_mountpoints = simple_pattern_create(
2760
+ config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths",
2761
+ DELAULT_EXLUDED_PATHS),
2762
+ SIMPLE_PATTERN_EXACT
2763
+ );
2764
+
2765
+ excluded_filesystems = simple_pattern_create(
2766
+ config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on filesystems",
2767
+ DEFAULT_EXCLUDED_FILESYSTEMS),
2768
+ SIMPLE_PATTERN_EXACT
2769
+ );
2770
+
2771
+ mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
2772
+ }
2773
+
2774
+ for (i = 0; i < mntsize; i++) {
2775
+
2776
+ char title[4096 + 1];
2777
+ int def_space, def_inodes, iter_space, iter_inodes;
2778
+
2779
+ struct mount_point_metadata *m = dictionary_get(mount_points, mntbuf[i].f_mntonname);
2780
+ if(unlikely(!m)) {
2781
+ char var_name[4096 + 1];
2782
+ snprintfz(var_name, 4096, "plugin:freebsd:getmntinfo:%s", mntbuf[i].f_mntonname);
2783
+
2784
+ def_space = do_space;
2785
+ def_inodes = do_space;
2786
+
2787
+ if(unlikely(simple_pattern_matches(excluded_mountpoints, mntbuf[i].f_mntonname))) {
2788
+ def_space = CONFIG_BOOLEAN_NO;
2789
+ def_inodes = CONFIG_BOOLEAN_NO;
2790
+ }
2791
+
2792
+ if(unlikely(simple_pattern_matches(excluded_filesystems, mntbuf[i].f_fstypename))) {
2793
+ def_space = CONFIG_BOOLEAN_NO;
2794
+ def_inodes = CONFIG_BOOLEAN_NO;
2795
+ }
2796
+
2797
+ iter_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
2798
+ iter_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
2799
+
2800
+ struct mount_point_metadata mp = {
2801
+ .do_space = iter_space,
2802
+ .do_inodes = iter_inodes,
2803
+
2804
+ .collected = 0,
2805
+
2806
+ .st_space = NULL,
2807
+ .rd_space_avail = NULL,
2808
+ .rd_space_used = NULL,
2809
+ .rd_space_reserved = NULL,
2810
+
2811
+ .st_inodes = NULL,
2812
+ .rd_inodes_avail = NULL,
2813
+ .rd_inodes_used = NULL,
2814
+ };
2815
+
2816
+ m = dictionary_set(mount_points, mntbuf[i].f_mntonname, &mp, sizeof(struct mount_point_metadata));
2817
+ }
2818
+
2819
+ if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
2820
+ continue;
2821
+
2822
+ if(unlikely(mntbuf[i].f_flags & MNT_RDONLY && !m->collected))
2823
+ continue;
2824
+
2825
+ // --------------------------------------------------------------------------
2826
+
2827
+ int rendered = 0;
2828
+
2829
+ if (m->do_space == CONFIG_BOOLEAN_YES || (m->do_space == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_blocks > 2))) {
2830
+ if (unlikely(!m->st_space)) {
2831
+ snprintfz(title, 4096, "Disk Space Usage for %s [%s]",
2832
+ mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2833
+ m->st_space = rrdset_create_localhost("disk_space",
2834
+ mntbuf[i].f_mntonname,
2835
+ NULL,
2836
+ mntbuf[i].f_mntonname,
2837
+ "disk.space",
2838
+ title,
2839
+ "GB",
2840
+ 2023,
2841
+ update_every,
2842
+ RRDSET_TYPE_STACKED
2843
+ );
2844
+
2845
+ m->rd_space_avail = rrddim_add(m->st_space, "avail", NULL,
2846
+ mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2847
+ m->rd_space_used = rrddim_add(m->st_space, "used", NULL,
2848
+ mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2849
+ m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root",
2850
+ mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2851
+ } else
2852
+ rrdset_next(m->st_space);
2853
+
2854
+ rrddim_set_by_pointer(m->st_space, m->rd_space_avail, (collected_number) mntbuf[i].f_bavail);
2855
+ rrddim_set_by_pointer(m->st_space, m->rd_space_used, (collected_number) (mntbuf[i].f_blocks -
2856
+ mntbuf[i].f_bfree));
2857
+ rrddim_set_by_pointer(m->st_space, m->rd_space_reserved, (collected_number) (mntbuf[i].f_bfree -
2858
+ mntbuf[i].f_bavail));
2859
+ rrdset_done(m->st_space);
2860
+
2861
+ rendered++;
2862
+ }
2863
+
2864
+ // --------------------------------------------------------------------------
2865
+
2866
+ if (m->do_inodes == CONFIG_BOOLEAN_YES || (m->do_inodes == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_files > 1))) {
2867
+ if (unlikely(!m->st_inodes)) {
2868
+ snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]",
2869
+ mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2870
+ m->st_inodes = rrdset_create_localhost("disk_inodes",
2871
+ mntbuf[i].f_mntonname,
2872
+ NULL,
2873
+ mntbuf[i].f_mntonname,
2874
+ "disk.inodes",
2875
+ title,
2876
+ "Inodes",
2877
+ 2024,
2878
+ update_every,
2879
+ RRDSET_TYPE_STACKED
2880
+ );
2881
+
2882
+ m->rd_inodes_avail = rrddim_add(m->st_inodes, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2883
+ m->rd_inodes_used = rrddim_add(m->st_inodes, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2884
+ } else
2885
+ rrdset_next(m->st_inodes);
2886
+
2887
+ rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_avail, (collected_number) mntbuf[i].f_ffree);
2888
+ rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_used, (collected_number) (mntbuf[i].f_files -
2889
+ mntbuf[i].f_ffree));
2890
+ rrdset_done(m->st_inodes);
2891
+
2892
+ rendered++;
2893
+ }
2894
+
2895
+ if(likely(rendered))
2896
+ m->collected++;
2897
+ }
2898
+ }
2899
+ } else {
2900
+ error("DISABLED: getmntinfo module");
2901
+ return 1;
2902
+ }
2903
+
2904
+ return 0;
2905
+}
2906
+
2907
// --------------------------------------------------------------------------------------------------------------------
2908
// old sources
2909
2910
int do_freebsd_sysctl_old(int update_every, usec_t dt) {
2708
- static int do_disk_io = -1, do_bandwidth = -1, do_space = -1, do_inodes = -1;
2911
+ static int do_disk_io = -1, do_bandwidth = -1;
2912
2913
if (unlikely(do_disk_io == -1)) {
2711
- do_disk_io = config_get_boolean("plugin:freebsd:sysctl", "stats for all disks", 1);
2712
- do_bandwidth = config_get_boolean("plugin:freebsd:sysctl", "bandwidth", 1);
2713
- do_space = config_get_boolean("plugin:freebsd:sysctl", "space usage for all disks", 1);
2714
- do_inodes = config_get_boolean("plugin:freebsd:sysctl", "inodes usage for all disks", 1);
2914
+ do_disk_io = config_get_boolean("plugin:freebsd:sysctl", "stats for all disks", 1);
2915
+ do_bandwidth = config_get_boolean("plugin:freebsd:sysctl", "bandwidth", 1);
2916
}
2917
2918
RRDSET *st;
2919
2920
int i;
2720
- char title[4096 + 1];
2921
2922
// NEEDED BY: do_disk_io
2923
#define RRD_TYPE_DISK "disk"
@@ -2749,11 +2949,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
2949
u_long ift_obytes;
2950
} iftot = {0, 0};
2951
2752
- // NEEDED BY: do_space, do_inodes
2753
- struct statfs *mntbuf;
2754
- int mntsize;
2755
- char mntonname[MNAMELEN + 1];
2756
-
2952
// --------------------------------------------------------------------
2953
2954
if (likely(do_disk_io)) {
@@ -3080,73 +3275,5 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
3275
}
3276
}
3277
3083
- // --------------------------------------------------------------------------
3084
-
3085
- if (likely(do_space || do_inodes)) {
3086
- // there is no mount info in sysctl MIBs
3087
- if (unlikely(!(mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)))) {
3088
- error("FREEBSD: getmntinfo() failed");
3089
- do_space = 0;
3090
- error("DISABLED: disk_space.X");
3091
- do_inodes = 0;
3092
- error("DISABLED: disk_inodes.X");
3093
- } else {
3094
- for (i = 0; i < mntsize; i++) {
3095
- if (mntbuf[i].f_flags == MNT_RDONLY ||
3096
- mntbuf[i].f_blocks == 0 ||
3097
- // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes
3098
- strcmp(mntbuf[i].f_fstypename, "autofs") == 0 ||
3099
- strcmp(mntbuf[i].f_fstypename, "procfs") == 0 ||
3100
- strcmp(mntbuf[i].f_fstypename, "subfs") == 0 ||
3101
- strcmp(mntbuf[i].f_fstypename, "devfs") == 0 ||
3102
- strcmp(mntbuf[i].f_fstypename, "none") == 0)
3103
- continue;
3104
-
3105
- // --------------------------------------------------------------------------
3106
-
3107
- if (likely(do_space)) {
3108
- st = rrdset_find_bytype_localhost("disk_space", mntbuf[i].f_mntonname);
3109
- if (unlikely(!st)) {
3110
- snprintfz(title, 4096, "Disk Space Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
3111
- st = rrdset_create_localhost("disk_space", mntbuf[i].f_mntonname, NULL, mntbuf[i].f_mntonname, "disk.space", title, "GB", 2023,
3112
- update_every,
3113
- RRDSET_TYPE_STACKED);
3114
-
3115
- rrddim_add(st, "avail", NULL, mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
3116
- rrddim_add(st, "used", NULL, mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
3117
- rrddim_add(st, "reserved_for_root", "reserved for root", mntbuf[i].f_bsize, GIGA_FACTOR,
3118
- RRD_ALGORITHM_ABSOLUTE);
3119
- } else
3120
- rrdset_next(st);
3121
-
3122
- rrddim_set(st, "avail", (collected_number) mntbuf[i].f_bavail);
3123
- rrddim_set(st, "used", (collected_number) (mntbuf[i].f_blocks - mntbuf[i].f_bfree));
3124
- rrddim_set(st, "reserved_for_root", (collected_number) (mntbuf[i].f_bfree - mntbuf[i].f_bavail));
3125
- rrdset_done(st);
3126
- }
3127
-
3128
- // --------------------------------------------------------------------------
3129
-
3130
- if (likely(do_inodes)) {
3131
- st = rrdset_find_bytype_localhost("disk_inodes", mntbuf[i].f_mntonname);
3132
- if (unlikely(!st)) {
3133
- snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
3134
- st = rrdset_create_localhost("disk_inodes", mntbuf[i].f_mntonname, NULL, mntbuf[i].f_mntonname, "disk.inodes", title, "Inodes", 2024,
3135
- update_every, RRDSET_TYPE_STACKED);
3136
-
3137
- rrddim_add(st, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3138
- rrddim_add(st, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3139
- rrddim_add(st, "reserved_for_root", "reserved for root", 1, 1, RRD_ALGORITHM_ABSOLUTE);
3140
- } else
3141
- rrdset_next(st);
3142
-
3143
- rrddim_set(st, "avail", (collected_number) mntbuf[i].f_ffree);
3144
- rrddim_set(st, "used", (collected_number) (mntbuf[i].f_files - mntbuf[i].f_ffree));
3145
- rrdset_done(st);
3146
- }
3147
- }
3148
- }
3149
- }
3150
-
3278
return 0;
3279
}
src/plugin_freebsd.c
+8
-5
@@ -33,6 +33,12 @@ static struct freebsd_module {
33
{ .name = "uptime", .dim = "uptime", .enabled = 1, .func = do_uptime },
34
{ .name = "net.isr", .dim = "net_isr", .enabled = 1, .func = do_net_isr },
35
36
+ // CPU metrics
37
+ { .name = "kern.cp_times", .dim = "cp_times", .enabled = 1, .func = do_kern_cp_times },
38
+
39
+ // memory metrics
40
+ { .name = "vm.stats.vm.v_pgfaults", .dim = "pgfaults", .enabled = 1, .func = do_vm_stats_sys_v_pgfaults },
41
+
42
// network metrics
43
{ .name = "net.inet.tcp.states", .dim = "tcp_states", .enabled = 1, .func = do_net_inet_tcp_states },
44
{ .name = "net.inet.tcp.stats", .dim = "tcp_stats", .enabled = 1, .func = do_net_inet_tcp_stats },
@@ -42,11 +48,8 @@ static struct freebsd_module {
48
{ .name = "net.inet6.ip6.stats", .dim = "ip6_stats", .enabled = 1, .func = do_net_inet6_ip6_stats },
49
{ .name = "net.inet6.icmp6.stats", .dim = "icmp6_stats", .enabled = 1, .func = do_net_inet6_icmp6_stats },
50
45
- // CPU metrics
46
- { .name = "kern.cp_times", .dim = "cp_times", .enabled = 1, .func = do_kern_cp_times },
47
-
48
- // memory metrics
49
- { .name = "vm.stats.vm.v_pgfaults", .dim = "pgfaults", .enabled = 1, .func = do_vm_stats_sys_v_pgfaults },
51
+ // disk metrics
52
+ { .name = "getmntinfo", .dim = "getmntinfo", .enabled = 1, .func = do_getmntinfo },
53
54
// the terminator of this array
55
{ .name = NULL, .dim = NULL, .enabled = 0, .func = NULL }
src/plugin_freebsd.h
+1
@@ -32,6 +32,7 @@ extern int do_net_inet_icmp_stats(int update_every, usec_t dt);
32
extern int do_net_inet_ip_stats(int update_every, usec_t dt);
33
extern int do_net_inet6_ip6_stats(int update_every, usec_t dt);
34
extern int do_net_inet6_icmp6_stats(int update_every, usec_t dt);
35
+extern int do_getmntinfo(int update_every, usec_t dt);
36
37
extern int do_freebsd_sysctl_old(int update_every, usec_t dt);
38