Skip to content

Commit

Permalink
re-wrote /proc/net/snmp using ARL; added alarm for max TCP connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsaou committed Nov 7, 2017
1 parent 0f46833 commit 0f9cc9f
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 422 deletions.
1 change: 1 addition & 0 deletions conf.d/Makefile.am
Expand Up @@ -102,6 +102,7 @@ dist_healthconfig_DATA = \
health.d/softnet.conf \
health.d/squid.conf \
health.d/swap.conf \
health.d/tcp_conn.conf \
health.d/tcp_listen.conf \
health.d/tcp_orphans.conf \
health.d/tcp_resets.conf \
Expand Down
19 changes: 19 additions & 0 deletions conf.d/health.d/tcp_conn.conf
@@ -0,0 +1,19 @@

#
# ${tcp_max_connections} may be nan or -1 if the system
# supports dynamic threshold for TCP connections.
# In this case, the alarm will always be zero.
#

alarm: tcp_connections
on: ipv4.tcpsock
os: linux
hosts: *
calc: (${tcp_max_connections} > 0) ? ( ${connections} * 100 / ${tcp_max_connections} ) : 0
units: %
every: 10s
warn: $this > (($status >= $WARNING ) ? ( 60 ) : ( 80 ))
crit: $this > (($status >= $CRITICAL) ? ( 80 ) : ( 90 ))
delay: up 0 down 5m multiplier 1.5 max 1h
info: the percentage of IPv4 TCP connections over the max allowed
to: sysadmin
4 changes: 2 additions & 2 deletions conf.d/health.d/tcp_orphans.conf
Expand Up @@ -7,7 +7,7 @@
# so we alarm warning at 25% and critical at 50%
#

alarm: tcp_orphans_percentage
alarm: tcp_orphans
on: ipv4.sockstat_tcp_sockets
os: linux
hosts: *
Expand All @@ -17,5 +17,5 @@
warn: $this > (($status >= $WARNING ) ? ( 20 ) : ( 25 ))
crit: $this > (($status >= $CRITICAL) ? ( 25 ) : ( 50 ))
delay: up 0 down 5m multiplier 1.5 max 1h
info: the percentage of orphan IPv4 TCP sockets over the max allowed (this may lead to out-of-socket-memory errors)
info: the percentage of orphan IPv4 TCP sockets over the max allowed (this may lead to too-many-orphans errors)
to: sysadmin
11 changes: 10 additions & 1 deletion src/adaptive_resortable_list.c
Expand Up @@ -2,7 +2,7 @@

// the default processor() of the ARL
// can be overwritten at arl_create()
static inline void arl_callback_str2ull(const char *name, uint32_t hash, const char *value, void *dst) {
inline void arl_callback_str2ull(const char *name, uint32_t hash, const char *value, void *dst) {
(void)name;
(void)hash;

Expand All @@ -11,6 +11,15 @@ static inline void arl_callback_str2ull(const char *name, uint32_t hash, const c
// fprintf(stderr, "name '%s' with hash %u and value '%s' is %llu\n", name, hash, value, *d);
}

inline void arl_callback_str2kernel_uint_t(const char *name, uint32_t hash, const char *value, void *dst) {
(void)name;
(void)hash;

register kernel_uint_t *d = dst;
*d = str2kernel_uint_t(value);
// fprintf(stderr, "name '%s' with hash %u and value '%s' is %llu\n", name, hash, value, (unsigned long long)*d);
}

// create a new ARL
ARL_BASE *arl_create(const char *name, void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks) {
ARL_BASE *base = callocz(1, sizeof(ARL_BASE));
Expand Down
3 changes: 3 additions & 0 deletions src/adaptive_resortable_list.h
Expand Up @@ -110,6 +110,9 @@ extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, const ch
// begin an ARL iteration
extern void arl_begin(ARL_BASE *base);

extern void arl_callback_str2ull(const char *name, uint32_t hash, const char *value, void *dst);
extern void arl_callback_str2kernel_uint_t(const char *name, uint32_t hash, const char *value, void *dst);

// check a keyword against the ARL
// this is to be called for each keyword read from source data
// s = the keyword, as collected
Expand Down

0 comments on commit 0f9cc9f

Please sign in to comment.