Separate getifaddrs module with simple patterns adopted
Vladimir Kobal committed
Mar 16, 2017 at 01:53 UTC
e86fe357adb9fb88f8e83950c52efaf95800a5ac
3 files changed
+425
-173
src/freebsd_sysctl.c
+418
-168
@@ -2719,13 +2719,13 @@ int do_getmntinfo(int update_every, usec_t dt) {
2719
#define DELAULT_EXLUDED_PATHS "/proc/*"
2720
// taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes
2721
#define DEFAULT_EXCLUDED_FILESYSTEMS "autofs procfs subfs devfs none"
2722
-#define CONFIG_SECTION_DISKSPACE "plugin:freebsd:getmntinfo"
2722
+#define CONFIG_SECTION_GETMNTINFO "plugin:freebsd:getmntinfo"
2723
2724
static int do_space = -1, do_inodes = -1;
2725
2726
if (unlikely(do_space == -1)) {
2727
- do_space = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
2728
- do_inodes = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
2727
+ do_space = config_get_boolean_ondemand(CONFIG_SECTION_GETMNTINFO, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
2728
+ do_inodes = config_get_boolean_ondemand(CONFIG_SECTION_GETMNTINFO, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
2729
}
2730
2731
if (likely(do_space || do_inodes)) {
@@ -2767,13 +2767,13 @@ int do_getmntinfo(int update_every, usec_t dt) {
2767
if(unlikely(!mount_points)) {
2768
2769
excluded_mountpoints = simple_pattern_create(
2770
- config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths",
2770
+ config_get(CONFIG_SECTION_GETMNTINFO, "exclude space metrics on paths",
2771
DELAULT_EXLUDED_PATHS),
2772
SIMPLE_PATTERN_EXACT
2773
);
2774
2775
excluded_filesystems = simple_pattern_create(
2776
- config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on filesystems",
2776
+ config_get(CONFIG_SECTION_GETMNTINFO, "exclude space metrics on filesystems",
2777
DEFAULT_EXCLUDED_FILESYSTEMS),
2778
SIMPLE_PATTERN_EXACT
2779
);
@@ -2789,7 +2789,7 @@ int do_getmntinfo(int update_every, usec_t dt) {
2789
struct mount_point_metadata *m = dictionary_get(mount_points, mntbuf[i].f_mntonname);
2790
if(unlikely(!m)) {
2791
char var_name[4096 + 1];
2792
- snprintfz(var_name, 4096, "plugin:freebsd:getmntinfo:%s", mntbuf[i].f_mntonname);
2792
+ snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETMNTINFO, mntbuf[i].f_mntonname);
2793
2794
def_space = do_space;
2795
def_inodes = do_space;
@@ -2915,21 +2915,427 @@ int do_getmntinfo(int update_every, usec_t dt) {
2915
}
2916
2917
// --------------------------------------------------------------------------------------------------------------------
2918
-// old sources
2918
+// getifaddrs
2919
2920
-int do_freebsd_sysctl_old(int update_every, usec_t dt) {
2921
- static int do_disk_io = -1, do_bandwidth = -1;
2920
+int do_getifaddrs(int update_every, usec_t dt) {
2921
+
2922
+#define DELAULT_EXLUDED_INTERFACES "lo*"
2923
+#define CONFIG_SECTION_GETIFADDRS "plugin:freebsd:getifaddrs"
2924
+
2925
+ static int do_bandwidth_ipv4 = -1, do_bandwidth_ipv6 = -1, do_bandwidth = -1, do_packets = -1,
2926
+ do_errors = -1, do_drops = -1, do_events = -1;
2927
+
2928
+ if (unlikely(do_bandwidth_ipv4 == -1)) {
2929
+ do_bandwidth_ipv4 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv4 interfaces",
2930
+ CONFIG_BOOLEAN_AUTO);
2931
+ do_bandwidth_ipv6 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv6 interfaces",
2932
+ CONFIG_BOOLEAN_AUTO);
2933
+ do_bandwidth = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "bandwidth for all interfaces",
2934
+ CONFIG_BOOLEAN_AUTO);
2935
+ do_packets = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "packets for all interfaces",
2936
+ CONFIG_BOOLEAN_AUTO);
2937
+ do_errors = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "errors for all interfaces",
2938
+ CONFIG_BOOLEAN_AUTO);
2939
+ do_drops = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "drops for all interfaces",
2940
+ CONFIG_BOOLEAN_AUTO);
2941
+ do_events = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "collisions for all interfaces",
2942
+ CONFIG_BOOLEAN_AUTO);
2943
+ }
2944
+
2945
+ if (likely(do_bandwidth_ipv4 || do_bandwidth_ipv6 || do_bandwidth || do_packets || do_errors ||
2946
+ do_drops || do_events)) {
2947
+ struct ifaddrs *ifap;
2948
+
2949
+ if (unlikely(getifaddrs(&ifap))) {
2950
+ error("FREEBSD: getifaddrs() failed");
2951
+ do_bandwidth_ipv4 = 0;
2952
+ error("DISABLED: system.ipv4 chart");
2953
+ do_bandwidth_ipv6 = 0;
2954
+ error("DISABLED: system.ipv6 chart");
2955
+ do_bandwidth = 0;
2956
+ error("DISABLED: net.* charts");
2957
+ do_packets = 0;
2958
+ error("DISABLED: net_packets.* charts");
2959
+ do_errors = 0;
2960
+ error("DISABLED: net_errors.* charts");
2961
+ do_drops = 0;
2962
+ error("DISABLED: net_drops.* charts");
2963
+ do_events = 0;
2964
+ error("DISABLED: net_events.* charts");
2965
+ error("DISABLED: getifaddrs module");
2966
+ return 1;
2967
+ } else {
2968
+ #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
2969
+ struct ifaddrs *ifa;
2970
+ struct iftot {
2971
+ u_long ift_ibytes;
2972
+ u_long ift_obytes;
2973
+ } iftot = {0, 0};
2974
+
2975
+ // --------------------------------------------------------------------
2976
+
2977
+ if (likely(do_bandwidth_ipv4)) {
2978
+ iftot.ift_ibytes = iftot.ift_obytes = 0;
2979
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
2980
+ if (ifa->ifa_addr->sa_family != AF_INET)
2981
+ continue;
2982
+ iftot.ift_ibytes += IFA_DATA(ibytes);
2983
+ iftot.ift_obytes += IFA_DATA(obytes);
2984
+ }
2985
+
2986
+ static RRDSET *st = NULL;
2987
+ static RRDDIM *rd_in = NULL, *rd_out = NULL;
2988
+
2989
+ if (unlikely(!st)) {
2990
+ st = rrdset_create_localhost("system",
2991
+ "ipv4",
2992
+ NULL,
2993
+ "network",
2994
+ NULL,
2995
+ "IPv4 Bandwidth",
2996
+ "kilobits/s",
2997
+ 500,
2998
+ update_every,
2999
+ RRDSET_TYPE_AREA
3000
+ );
3001
+
3002
+ rd_in = rrddim_add(st, "InOctets", "received", 8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3003
+ rd_out = rrddim_add(st, "OutOctets", "sent", -8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3004
+ } else
3005
+ rrdset_next(st);
3006
+
3007
+ rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
3008
+ rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
3009
+ rrdset_done(st);
3010
+ }
3011
+
3012
+ // --------------------------------------------------------------------
3013
+
3014
+ if (likely(do_bandwidth_ipv6)) {
3015
+ iftot.ift_ibytes = iftot.ift_obytes = 0;
3016
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3017
+ if (ifa->ifa_addr->sa_family != AF_INET6)
3018
+ continue;
3019
+ iftot.ift_ibytes += IFA_DATA(ibytes);
3020
+ iftot.ift_obytes += IFA_DATA(obytes);
3021
+ }
3022
+
3023
+ static RRDSET *st = NULL;
3024
+ static RRDDIM *rd_in = NULL, *rd_out = NULL;
3025
+
3026
+ if (unlikely(!st)) {
3027
+ st = rrdset_create_localhost("system",
3028
+ "ipv6",
3029
+ NULL,
3030
+ "network",
3031
+ NULL,
3032
+ "IPv6 Bandwidth",
3033
+ "kilobits/s",
3034
+ 500,
3035
+ update_every,
3036
+ RRDSET_TYPE_AREA
3037
+ );
3038
+
3039
+ rd_in = rrddim_add(st, "received", NULL, 8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3040
+ rd_out = rrddim_add(st, "sent", NULL, -8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3041
+ } else
3042
+ rrdset_next(st);
3043
+
3044
+ rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
3045
+ rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
3046
+ rrdset_done(st);
3047
+ }
3048
+
3049
+ // --------------------------------------------------------------------
3050
+
3051
+ // Data to be stored in DICTIONARY interfaces.
3052
+ // This DICTIONARY is used to lookup the settings of the interfaces on each iteration.
3053
+ struct interfaces_metadata {
3054
+ int do_bandwidth;
3055
+ int do_packets;
3056
+ int do_errors;
3057
+ int do_drops;
3058
+ int do_events;
3059
+
3060
+ RRDSET *st_bandwidth;
3061
+ RRDDIM *rd_bandwidth_in;
3062
+ RRDDIM *rd_bandwidth_out;
3063
+
3064
+ RRDSET *st_packets;
3065
+ RRDDIM *rd_packets_in;
3066
+ RRDDIM *rd_packets_out;
3067
+ RRDDIM *rd_packets_m_in;
3068
+ RRDDIM *rd_packets_m_out;
3069
+
3070
+ RRDSET *st_errors;
3071
+ RRDDIM *rd_errors_in;
3072
+ RRDDIM *rd_errors_out;
3073
+
3074
+ RRDSET *st_drops;
3075
+ RRDDIM *rd_drops_in;
3076
+ RRDDIM *rd_drops_out;
3077
+
3078
+ RRDSET *st_events;
3079
+ RRDDIM *rd_events_coll;
3080
+ };
3081
+ static DICTIONARY *interfaces = NULL;
3082
+ static SIMPLE_PATTERN *excluded_interfaces = NULL;
3083
+
3084
+ if(unlikely(!interfaces)) {
3085
+
3086
+ excluded_interfaces = simple_pattern_create(
3087
+ config_get(CONFIG_SECTION_GETIFADDRS, "disable by default interfaces matching",
3088
+ DELAULT_EXLUDED_INTERFACES)
3089
+ , SIMPLE_PATTERN_EXACT
3090
+ );
3091
+
3092
+ interfaces = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
3093
+ }
3094
+
3095
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3096
+ if (ifa->ifa_addr->sa_family != AF_LINK)
3097
+ continue;
3098
+
3099
+ int def_bandwidth, def_packets, def_errors, def_drops, def_events,
3100
+ iter_bandwidth, iter_packets, iter_errors, iter_drops, iter_events;
3101
+
3102
+ struct interfaces_metadata *ifm = dictionary_get(interfaces, ifa->ifa_name);
3103
+ if(unlikely(!ifm)) {
3104
+ char var_name[4096 + 1];
3105
+ snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETIFADDRS, ifa->ifa_name);
3106
+
3107
+ def_bandwidth = do_bandwidth;
3108
+ def_packets = do_packets;
3109
+ def_errors = do_errors;
3110
+ def_drops = do_drops;
3111
+ def_events = do_events;
3112
+
3113
+ if(unlikely(simple_pattern_matches(excluded_interfaces, ifa->ifa_name))) {
3114
+ def_bandwidth = CONFIG_BOOLEAN_NO;
3115
+ def_packets = CONFIG_BOOLEAN_NO;
3116
+ def_errors = CONFIG_BOOLEAN_NO;
3117
+ def_drops = CONFIG_BOOLEAN_NO;
3118
+ def_events = CONFIG_BOOLEAN_NO;
3119
+ }
3120
+
3121
+ iter_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", def_bandwidth);
3122
+ iter_packets = config_get_boolean_ondemand(var_name, "packets", def_packets);
3123
+ iter_errors = config_get_boolean_ondemand(var_name, "errors", def_errors);
3124
+ iter_drops = config_get_boolean_ondemand(var_name, "drops", def_drops);
3125
+ iter_events = config_get_boolean_ondemand(var_name, "events", def_events);
3126
+
3127
+ struct interfaces_metadata ifmp = {
3128
+ .do_bandwidth = iter_bandwidth,
3129
+ .do_packets = iter_packets,
3130
+ .do_errors = iter_errors,
3131
+ .do_drops = iter_drops,
3132
+ .do_events = iter_events,
3133
+
3134
+ .st_bandwidth = NULL,
3135
+ .rd_bandwidth_in = NULL,
3136
+ .rd_bandwidth_out = NULL,
3137
+
3138
+ .st_packets = NULL,
3139
+ .rd_packets_in = NULL,
3140
+ .rd_packets_out = NULL,
3141
+ .rd_packets_m_in = NULL,
3142
+ .rd_packets_m_out = NULL,
3143
+
3144
+ .st_errors = NULL,
3145
+ .rd_errors_in = NULL,
3146
+ .rd_errors_out = NULL,
3147
+
3148
+ .st_drops = NULL,
3149
+ .rd_drops_in = NULL,
3150
+ .rd_drops_out = NULL,
3151
+
3152
+ .st_events = NULL,
3153
+ .rd_events_coll = NULL,
3154
+ };
3155
+
3156
+ ifm = dictionary_set(interfaces, ifa->ifa_name, &ifmp, sizeof(struct interfaces_metadata));
3157
+ }
3158
+
3159
+ // --------------------------------------------------------------------
3160
+
3161
+ if (ifm->do_bandwidth == CONFIG_BOOLEAN_YES || (ifm->do_bandwidth == CONFIG_BOOLEAN_AUTO &&
3162
+ (IFA_DATA(ibytes) || IFA_DATA(obytes)))) {
3163
+ if (unlikely(!ifm->st_bandwidth)) {
3164
+ ifm->st_bandwidth = rrdset_create_localhost("net",
3165
+ ifa->ifa_name,
3166
+ NULL,
3167
+ ifa->ifa_name,
3168
+ "net.net",
3169
+ "Bandwidth",
3170
+ "kilobits/s",
3171
+ 7000,
3172
+ update_every,
3173
+ RRDSET_TYPE_AREA
3174
+ );
3175
+
3176
+ ifm->rd_bandwidth_in = rrddim_add(ifm->st_bandwidth, "received", NULL, 8, KILO_FACTOR,
3177
+ RRD_ALGORITHM_INCREMENTAL);
3178
+ ifm->rd_bandwidth_out = rrddim_add(ifm->st_bandwidth, "sent", NULL, -8, KILO_FACTOR,
3179
+ RRD_ALGORITHM_INCREMENTAL);
3180
+ } else
3181
+ rrdset_next(ifm->st_bandwidth);
3182
+
3183
+ rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_in, IFA_DATA(ibytes));
3184
+ rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_out, IFA_DATA(obytes));
3185
+ rrdset_done(ifm->st_bandwidth);
3186
+ }
3187
+
3188
+ // --------------------------------------------------------------------
3189
+
3190
+ if (ifm->do_packets == CONFIG_BOOLEAN_YES || (ifm->do_packets == CONFIG_BOOLEAN_AUTO &&
3191
+ (IFA_DATA(ipackets) || IFA_DATA(opackets) || IFA_DATA(imcasts) || IFA_DATA(omcasts)))) {
3192
+ if (unlikely(!ifm->st_packets)) {
3193
+ ifm->st_packets = rrdset_create_localhost("net_packets",
3194
+ ifa->ifa_name,
3195
+ NULL,
3196
+ ifa->ifa_name,
3197
+ "net.packets",
3198
+ "Packets",
3199
+ "packets/s",
3200
+ 7001,
3201
+ update_every,
3202
+ RRDSET_TYPE_LINE
3203
+ );
3204
+
3205
+ rrdset_flag_set(ifm->st_packets, RRDSET_FLAG_DETAIL);
3206
+
3207
+ ifm->rd_packets_in = rrddim_add(ifm->st_packets, "received", NULL, 1, 1,
3208
+ RRD_ALGORITHM_INCREMENTAL);
3209
+ ifm->rd_packets_out = rrddim_add(ifm->st_packets, "sent", NULL, -1, 1,
3210
+ RRD_ALGORITHM_INCREMENTAL);
3211
+ ifm->rd_packets_m_in = rrddim_add(ifm->st_packets, "multicast_received", NULL, 1, 1,
3212
+ RRD_ALGORITHM_INCREMENTAL);
3213
+ ifm->rd_packets_m_out = rrddim_add(ifm->st_packets, "multicast_sent", NULL, -1, 1,
3214
+ RRD_ALGORITHM_INCREMENTAL);
3215
+ } else
3216
+ rrdset_next(ifm->st_packets);
3217
+
3218
+ rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_in, IFA_DATA(ipackets));
3219
+ rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_out, IFA_DATA(opackets));
3220
+ rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_in, IFA_DATA(imcasts));
3221
+ rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_out, IFA_DATA(omcasts));
3222
+ rrdset_done(ifm->st_packets);
3223
+ }
3224
+
3225
+ // --------------------------------------------------------------------
3226
+
3227
+ if (ifm->do_errors == CONFIG_BOOLEAN_YES || (ifm->do_errors == CONFIG_BOOLEAN_AUTO &&
3228
+ (IFA_DATA(ierrors) || IFA_DATA(oerrors)))) {
3229
+ if (unlikely(!ifm->st_errors)) {
3230
+ ifm->st_errors = rrdset_create_localhost("net_errors",
3231
+ ifa->ifa_name,
3232
+ NULL,
3233
+ ifa->ifa_name,
3234
+ "net.errors",
3235
+ "Interface Errors",
3236
+ "errors/s",
3237
+ 7002,
3238
+ update_every,
3239
+ RRDSET_TYPE_LINE
3240
+ );
3241
+
3242
+ rrdset_flag_set(ifm->st_errors, RRDSET_FLAG_DETAIL);
3243
+
3244
+ ifm->rd_errors_in = rrddim_add(ifm->st_errors, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3245
+ ifm->rd_errors_out = rrddim_add(ifm->st_errors, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3246
+ } else
3247
+ rrdset_next(ifm->st_errors);
3248
+
3249
+ rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_in, IFA_DATA(ierrors));
3250
+ rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_out, IFA_DATA(oerrors));
3251
+ rrdset_done(ifm->st_errors);
3252
+ }
3253
+ // --------------------------------------------------------------------
3254
+
3255
+ if (ifm->do_drops == CONFIG_BOOLEAN_YES || (ifm->do_drops == CONFIG_BOOLEAN_AUTO &&
3256
+ (IFA_DATA(iqdrops) || IFA_DATA(oqdrops)))) {
3257
+ if (unlikely(!ifm->st_drops)) {
3258
+ ifm->st_drops = rrdset_create_localhost("net_drops",
3259
+ ifa->ifa_name,
3260
+ NULL,
3261
+ ifa->ifa_name,
3262
+ "net.drops",
3263
+ "Interface Drops",
3264
+ "drops/s",
3265
+ 7003,
3266
+ update_every,
3267
+ RRDSET_TYPE_LINE
3268
+ );
3269
+
3270
+ rrdset_flag_set(ifm->st_drops, RRDSET_FLAG_DETAIL);
3271
+
3272
+ ifm->rd_drops_in = rrddim_add(ifm->st_drops, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3273
+#if __FreeBSD__ >= 11
3274
+ ifm->rd_drops_out = rrddim_add(ifm->st_drops, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3275
+#endif
3276
+ } else
3277
+ rrdset_next(ifm->st_drops);
3278
+
3279
+ rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_in, IFA_DATA(iqdrops));
3280
+#if __FreeBSD__ >= 11
3281
+ rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_out, IFA_DATA(oqdrops));
3282
+#endif
3283
+ rrdset_done(ifm->st_drops);
3284
+ }
3285
+
3286
+ // --------------------------------------------------------------------
3287
+
3288
+ if (ifm->do_events == CONFIG_BOOLEAN_YES || (ifm->do_events == CONFIG_BOOLEAN_AUTO &&
3289
+ IFA_DATA(collisions))) {
3290
+ if (unlikely(!ifm->st_events)) {
3291
+ ifm->st_events = rrdset_create_localhost("net_events",
3292
+ ifa->ifa_name,
3293
+ NULL,
3294
+ ifa->ifa_name,
3295
+ "net.events",
3296
+ "Network Interface Events",
3297
+ "events/s",
3298
+ 7006,
3299
+ update_every,
3300
+ RRDSET_TYPE_LINE
3301
+ );
3302
+
3303
+ rrdset_flag_set(ifm->st_events, RRDSET_FLAG_DETAIL);
3304
+
3305
+ ifm->rd_events_coll = rrddim_add(ifm->st_events, "collisions", NULL, -1, 1,
3306
+ RRD_ALGORITHM_INCREMENTAL);
3307
+ } else
3308
+ rrdset_next(ifm->st_events);
3309
+
3310
+ rrddim_set_by_pointer(ifm->st_events, ifm->rd_events_coll, IFA_DATA(collisions));
3311
+ rrdset_done(ifm->st_events);
3312
+ }
3313
+ }
3314
+
3315
+ freeifaddrs(ifap);
3316
+ }
3317
+ } else {
3318
+ error("DISABLED: getifaddrs module");
3319
+ return 1;
3320
+ }
3321
+
3322
+ return 0;
3323
+}
3324
+
3325
+// --------------------------------------------------------------------------------------------------------------------
3326
+// kern.devstat
3327
+
3328
+int do_kern_devstat(int update_every, usec_t dt) {
3329
+ static int do_disk_io = -1;
3330
3331
if (unlikely(do_disk_io == -1)) {
2924
- do_disk_io = config_get_boolean("plugin:freebsd:sysctl", "stats for all disks", 1);
2925
- do_bandwidth = config_get_boolean("plugin:freebsd:sysctl", "bandwidth", 1);
3332
+ do_disk_io = config_get_boolean("plugin:freebsd:kern.devstat", "stats for all disks", 1);
3333
}
3334
3335
RRDSET *st;
3336
3337
int i;
3338
2932
- // NEEDED BY: do_disk_io
3339
#define RRD_TYPE_DISK "disk"
3340
#define BINTIME_SCALE 5.42101086242752217003726400434970855712890625e-17 // this is 1000/2^64
3341
int numdevs;
@@ -2951,14 +3357,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
3357
collected_number busy_time_ms;
3358
} prev_dstat;
3359
2954
- // NEEDED BY: do_bandwidth
2955
- #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
2956
- struct ifaddrs *ifa, *ifap;
2957
- struct iftot {
2958
- u_long ift_ibytes;
2959
- u_long ift_obytes;
2960
- } iftot = {0, 0};
2961
-
3360
// --------------------------------------------------------------------
3361
3362
if (likely(do_disk_io)) {
@@ -3137,153 +3535,5 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
3535
}
3536
}
3537
3140
- // --------------------------------------------------------------------
3141
-
3142
- if (likely(do_bandwidth)) {
3143
- if (unlikely(getifaddrs(&ifap))) {
3144
- error("FREEBSD: getifaddrs()");
3145
- do_bandwidth = 0;
3146
- error("DISABLED: system.ipv4");
3147
- } else {
3148
- iftot.ift_ibytes = iftot.ift_obytes = 0;
3149
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3150
- if (ifa->ifa_addr->sa_family != AF_INET)
3151
- continue;
3152
- iftot.ift_ibytes += IFA_DATA(ibytes);
3153
- iftot.ift_obytes += IFA_DATA(obytes);
3154
- }
3155
-
3156
- st = rrdset_find_localhost("system.ipv4");
3157
- if (unlikely(!st)) {
3158
- st = rrdset_create_localhost("system", "ipv4", NULL, "network", NULL, "IPv4 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
3159
-
3160
- rrddim_add(st, "InOctets", "received", 8, 1024, RRD_ALGORITHM_INCREMENTAL);
3161
- rrddim_add(st, "OutOctets", "sent", -8, 1024, RRD_ALGORITHM_INCREMENTAL);
3162
- }
3163
- else rrdset_next(st);
3164
-
3165
- rrddim_set(st, "InOctets", iftot.ift_ibytes);
3166
- rrddim_set(st, "OutOctets", iftot.ift_obytes);
3167
- rrdset_done(st);
3168
-
3169
- // --------------------------------------------------------------------
3170
-
3171
- iftot.ift_ibytes = iftot.ift_obytes = 0;
3172
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3173
- if (ifa->ifa_addr->sa_family != AF_INET6)
3174
- continue;
3175
- iftot.ift_ibytes += IFA_DATA(ibytes);
3176
- iftot.ift_obytes += IFA_DATA(obytes);
3177
- }
3178
-
3179
- st = rrdset_find_localhost("system.ipv6");
3180
- if (unlikely(!st)) {
3181
- st = rrdset_create_localhost("system", "ipv6", NULL, "network", NULL, "IPv6 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
3182
-
3183
- rrddim_add(st, "received", NULL, 8, 1024, RRD_ALGORITHM_INCREMENTAL);
3184
- rrddim_add(st, "sent", NULL, -8, 1024, RRD_ALGORITHM_INCREMENTAL);
3185
- }
3186
- else rrdset_next(st);
3187
-
3188
- rrddim_set(st, "sent", iftot.ift_obytes);
3189
- rrddim_set(st, "received", iftot.ift_ibytes);
3190
- rrdset_done(st);
3191
-
3192
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3193
- if (ifa->ifa_addr->sa_family != AF_LINK)
3194
- continue;
3195
-
3196
- // --------------------------------------------------------------------
3197
-
3198
- st = rrdset_find_bytype_localhost("net", ifa->ifa_name);
3199
- if (unlikely(!st)) {
3200
- st = rrdset_create_localhost("net", ifa->ifa_name, NULL, ifa->ifa_name, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
3201
-
3202
- rrddim_add(st, "received", NULL, 8, 1024, RRD_ALGORITHM_INCREMENTAL);
3203
- rrddim_add(st, "sent", NULL, -8, 1024, RRD_ALGORITHM_INCREMENTAL);
3204
- }
3205
- else rrdset_next(st);
3206
-
3207
- rrddim_set(st, "received", IFA_DATA(ibytes));
3208
- rrddim_set(st, "sent", IFA_DATA(obytes));
3209
- rrdset_done(st);
3210
-
3211
- // --------------------------------------------------------------------
3212
-
3213
- st = rrdset_find_bytype_localhost("net_packets", ifa->ifa_name);
3214
- if (unlikely(!st)) {
3215
- st = rrdset_create_localhost("net_packets", ifa->ifa_name, NULL, ifa->ifa_name, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
3216
- rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3217
-
3218
- rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3219
- rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3220
- rrddim_add(st, "multicast_received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3221
- rrddim_add(st, "multicast_sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3222
- }
3223
- else rrdset_next(st);
3224
-
3225
- rrddim_set(st, "received", IFA_DATA(ipackets));
3226
- rrddim_set(st, "sent", IFA_DATA(opackets));
3227
- rrddim_set(st, "multicast_received", IFA_DATA(imcasts));
3228
- rrddim_set(st, "multicast_sent", IFA_DATA(omcasts));
3229
- rrdset_done(st);
3230
-
3231
- // --------------------------------------------------------------------
3232
-
3233
- st = rrdset_find_bytype_localhost("net_errors", ifa->ifa_name);
3234
- if (unlikely(!st)) {
3235
- st = rrdset_create_localhost("net_errors", ifa->ifa_name, NULL, ifa->ifa_name, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
3236
- rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3237
-
3238
- rrddim_add(st, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3239
- rrddim_add(st, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3240
- }
3241
- else rrdset_next(st);
3242
-
3243
- rrddim_set(st, "inbound", IFA_DATA(ierrors));
3244
- rrddim_set(st, "outbound", IFA_DATA(oerrors));
3245
- rrdset_done(st);
3246
-
3247
- // --------------------------------------------------------------------
3248
-
3249
- st = rrdset_find_bytype_localhost("net_drops", ifa->ifa_name);
3250
- if (unlikely(!st)) {
3251
- st = rrdset_create_localhost("net_drops", ifa->ifa_name, NULL, ifa->ifa_name, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
3252
- rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3253
-
3254
- rrddim_add(st, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3255
-#if __FreeBSD__ >= 11
3256
- rrddim_add(st, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3257
-#endif
3258
- }
3259
- else rrdset_next(st);
3260
-
3261
- rrddim_set(st, "inbound", IFA_DATA(iqdrops));
3262
-#if __FreeBSD__ >= 11
3263
- rrddim_set(st, "outbound", IFA_DATA(oqdrops));
3264
-#endif
3265
- rrdset_done(st);
3266
-
3267
- // --------------------------------------------------------------------
3268
-
3269
- st = rrdset_find_bytype_localhost("net_events", ifa->ifa_name);
3270
- if (unlikely(!st)) {
3271
- st = rrdset_create_localhost("net_events", ifa->ifa_name, NULL, ifa->ifa_name, "net.events", "Network Interface Events", "events/s", 7006, update_every, RRDSET_TYPE_LINE);
3272
- rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3273
-
3274
- rrddim_add(st, "frames", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3275
- rrddim_add(st, "collisions", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3276
- rrddim_add(st, "carrier", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3277
- }
3278
- else rrdset_next(st);
3279
-
3280
- rrddim_set(st, "collisions", IFA_DATA(collisions));
3281
- rrdset_done(st);
3282
- }
3283
-
3284
- freeifaddrs(ifap);
3285
- }
3286
- }
3287
-
3538
return 0;
3539
}
src/plugin_freebsd.c
+5
-3
@@ -13,8 +13,6 @@ static struct freebsd_module {
13
14
} freebsd_modules[] = {
15
16
- { .name = "freebsd_old", .dim = "freebsd_old", .enabled = 1, .func = do_freebsd_sysctl_old },
17
-
16
// system metrics
17
{ .name = "vm.loadavg", .dim = "loadavg", .enabled = 1, .func = do_vm_loadavg },
18
{ .name = "vm.vmtotal", .dim = "vmtotal", .enabled = 1, .func = do_vm_vmtotal },
@@ -48,8 +46,12 @@ static struct freebsd_module {
46
{ .name = "net.inet6.ip6.stats", .dim = "ip6_stats", .enabled = 1, .func = do_net_inet6_ip6_stats },
47
{ .name = "net.inet6.icmp6.stats", .dim = "icmp6_stats", .enabled = 1, .func = do_net_inet6_icmp6_stats },
48
49
+ // network interfaces metrics
50
+ { .name = "getifaddrs", .dim = "getifaddrs", .enabled = 1, .func = do_getifaddrs },
51
+
52
// disk metrics
52
- { .name = "getmntinfo", .dim = "getmntinfo", .enabled = 1, .func = do_getmntinfo },
53
+ { .name = "getmntinfo", .dim = "getmntinfo", .enabled = 1, .func = do_getmntinfo },
54
+ { .name = "kern.devstat", .dim = "kern_devstat", .enabled = 1, .func = do_kern_devstat },
55
56
// the terminator of this array
57
{ .name = NULL, .dim = NULL, .enabled = 0, .func = NULL }
src/plugin_freebsd.h
+2
-2
@@ -32,9 +32,9 @@ 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_getifaddrs(int update_every, usec_t dt);
36
extern int do_getmntinfo(int update_every, usec_t dt);
36
-
37
-extern int do_freebsd_sysctl_old(int update_every, usec_t dt);
37
+extern int do_kern_devstat(int update_every, usec_t dt);
38
39
#define GETSYSCTL_MIB(name, mib) getsysctl_mib(name, mib, sizeof(mib)/sizeof(int))
40