File descr alarm v01 (#10192)
Fotis Voutsas committed
Dec 3, 2020 at 17:33 UTC
04dbf7039e16a174983917f2d01e45d9b0daf98f
4 files changed
+26
-1
collectors/apps.plugin/apps_plugin.c
+12
@@ -508,6 +508,7 @@ struct file_descriptor {
508
static int
509
all_files_len = 0,
510
all_files_size = 0;
511
+ long double currentmaxfds = 0;
512
513
// ----------------------------------------------------------------------------
514
// read users and groups from files
@@ -2998,6 +2999,7 @@ static inline void aggregate_pid_fds_on_targets(struct pid_stat *p) {
2999
reallocate_target_fds(u);
3000
reallocate_target_fds(g);
3001
3002
+ long double currentfds = 0;
3003
size_t c, size = p->fds_size;
3004
struct pid_fd *fds = p->fds;
3005
for(c = 0; c < size ;c++) {
@@ -3006,10 +3008,15 @@ static inline void aggregate_pid_fds_on_targets(struct pid_stat *p) {
3008
if(likely(fd <= 0 || fd >= all_files_size))
3009
continue;
3010
3011
+ currentfds++;
3012
+
3013
aggregate_fd_on_target(fd, w);
3014
aggregate_fd_on_target(fd, u);
3015
aggregate_fd_on_target(fd, g);
3016
}
3017
+
3018
+ if (currentfds >= currentmaxfds)
3019
+ currentmaxfds = currentfds;
3020
}
3021
3022
static inline void aggregate_pid_on_target(struct target *w, struct pid_stat *p, struct target *o) {
@@ -3607,6 +3614,10 @@ static void send_collected_data_to_netdata(struct target *root, const char *type
3614
if (unlikely(w->exposed && w->processes))
3615
send_SET(w->name, w->openfiles);
3616
}
3617
+ if (!strcmp("apps", type)){
3618
+ kernel_uint_t usedfdpercentage = (kernel_uint_t) ((currentmaxfds * 100) / sysconf(_SC_OPEN_MAX));
3619
+ fprintf(stdout, "VARIABLE fdperc = " KERNEL_UINT_FORMAT "\n", usedfdpercentage);
3620
+ }
3621
send_END();
3622
3623
send_BEGIN(type, "sockets", dt);
@@ -4184,6 +4195,7 @@ int main(int argc, char **argv) {
4195
exit(1);
4196
}
4197
4198
+ currentmaxfds = 0;
4199
calculate_netdata_statistics();
4200
normalize_utilization(apps_groups_root_target);
4201
health/Makefile.am
+1
@@ -29,6 +29,7 @@ dist_healthconfig_DATA = \
29
health.d/anomalies.conf \
30
health.d/apache.conf \
31
health.d/apcupsd.conf \
32
+ health.d/apps_plugin.conf \
33
health.d/backend.conf \
34
health.d/bcache.conf \
35
health.d/beanstalkd.conf \
health/health.d/apps_plugin.conf
new
+13
@@ -0,0 +1,13 @@
1
+# you can disable an alarm notification by setting the 'to' line to: silent
2
+
3
+ alarm: used_file_descriptors
4
+ on: apps.files
5
+ hosts: *
6
+ calc: $fdperc
7
+ units: %
8
+ every: 5s
9
+ warn: $this > (($status >= $WARNING) ? (75) : (80))
10
+ crit: $this > (($status == $CRITICAL) ? (85) : (90))
11
+ delay: down 5m multiplier 1.5 max 1h
12
+ info: Peak percentage of file descriptors used
13
+ to: sysadmin
libnetdata/os.c
-1
@@ -215,4 +215,3 @@ int getsysctl_by_name(const char *name, void *ptr, size_t len) {
215
}
216
217
#endif // (TARGET_OS == OS_MACOS)
218
-