-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[monit] Build from source and patch to use MemAvailable value if avai…
…lable on system (#3875)
- Loading branch information
Showing
10 changed files
with
157 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
############################################################################### | ||
## Monit configuration for SONiC host OS | ||
## | ||
## This includes system-level monitoring as well as processes which | ||
## run in the host OS (i.e., not inside a Docker container) | ||
############################################################################### | ||
|
||
check filesystem root-overlay with path / | ||
if space usage > 90% for 5 times within 10 cycles then alert | ||
|
||
check filesystem var-log with path /var/log | ||
if space usage > 90% for 5 times within 10 cycles then alert | ||
|
||
check system $HOST | ||
if memory usage > 90% for 5 times within 10 cycles then alert | ||
if cpu usage (user) > 90% for 5 times within 10 cycles then alert | ||
if cpu usage (system) > 90% for 5 times within 10 cycles then alert | ||
|
||
check process rsyslog with pidfile /var/run/rsyslogd.pid | ||
start program = "/bin/systemctl start rsyslog.service" | ||
stop program = "/bin/systemctl stop rsyslog.service" | ||
if totalmem > 800 MB for 5 times within 10 cycles then restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# monit package | ||
|
||
MONIT_VERSION = 5.20.0-6 | ||
|
||
export MONIT_VERSION | ||
|
||
MONIT = monit_$(MONIT_VERSION)_$(CONFIGURED_ARCH).deb | ||
$(MONIT)_SRC_PATH = $(SRC_PATH)/monit | ||
SONIC_MAKE_DEBS += $(MONIT) | ||
|
||
SONIC_STRETCH_DEBS += $(MONIT) | ||
|
||
MONIT_DBG = monit-dbgsym_$(MONIT_VERSION)_$(CONFIGURED_ARCH).deb | ||
$(eval $(call add_derived_package,$(MONIT),$(MONIT_DBG))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.ONESHELL: | ||
SHELL = /bin/bash | ||
.SHELLFLAGS += -e | ||
|
||
MAIN_TARGET = monit_$(MONIT_VERSION)_$(CONFIGURED_ARCH).deb | ||
DERIVED_TARGETS = monit-dbgsym_$(MONIT_VERSION)_$(CONFIGURED_ARCH).deb | ||
|
||
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : | ||
# Remove any stale files | ||
rm -rf ./monit | ||
|
||
# Clone monit repo | ||
git clone https://salsa.debian.org/sk-guest/monit.git | ||
pushd ./monit | ||
|
||
# Reset HEAD to the commit of the proper tag | ||
# NOTE: Using "git checkout <tag_name>" here detaches our HEAD, | ||
# which stg doesn't like, so we use this method instead | ||
# NOTE: For some reason, tags in the Debian monit repo are prefixed with "1%" | ||
git reset --hard debian/1\%$(MONIT_VERSION) | ||
|
||
# Apply patches | ||
stg init | ||
stg import -s ../patch/series | ||
|
||
# Build source and Debian packages | ||
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS) | ||
popd | ||
|
||
# Move the newly-built .deb packages to the destination directory | ||
mv $(DERIVED_TARGETS) $* $(DEST)/ | ||
|
||
$(addprefix $(DEST)/, $(DERIVED_TARGETS)): $(DEST)/% : $(DEST)/$(MAIN_TARGET) |
70 changes: 70 additions & 0 deletions
70
src/monit/patch/0001-used_system_memory_sysdep-Use-MemAvailable-value-if-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
From c392362c9c1d57256b7e8ab7c77926824677fd73 Mon Sep 17 00:00:00 2001 | ||
From: Joe LeVeque <[email protected]> | ||
Date: Tue, 19 Nov 2019 01:51:13 +0000 | ||
Subject: [PATCH] [used_system_memory_sysdep] Use 'MemAvailable' value if | ||
available | ||
|
||
--- | ||
src/process/sysdep_LINUX.c | 35 +++++++++++++++++++++++------------ | ||
1 file changed, 23 insertions(+), 12 deletions(-) | ||
|
||
diff --git a/src/process/sysdep_LINUX.c b/src/process/sysdep_LINUX.c | ||
index 0d18f85..221e785 100644 | ||
--- a/src/process/sysdep_LINUX.c | ||
+++ b/src/process/sysdep_LINUX.c | ||
@@ -335,6 +335,7 @@ int getloadavg_sysdep(double *loadv, int nelem) { | ||
boolean_t used_system_memory_sysdep(SystemInfo_T *si) { | ||
char *ptr; | ||
char buf[2048]; | ||
+ unsigned long mem_available = 0UL; | ||
unsigned long mem_free = 0UL; | ||
unsigned long buffers = 0UL; | ||
unsigned long cached = 0UL; | ||
@@ -343,22 +344,32 @@ boolean_t used_system_memory_sysdep(SystemInfo_T *si) { | ||
unsigned long swap_free = 0UL; | ||
|
||
if (! file_readProc(buf, sizeof(buf), "meminfo", -1, NULL)) { | ||
- LogError("system statistic error -- cannot get real memory free amount\n"); | ||
+ LogError("system statistic error -- cannot read /proc/meminfo\n"); | ||
goto error; | ||
} | ||
|
||
- /* Memory */ | ||
- if (! (ptr = strstr(buf, "MemFree:")) || sscanf(ptr + 8, "%ld", &mem_free) != 1) { | ||
- LogError("system statistic error -- cannot get real memory free amount\n"); | ||
- goto error; | ||
+ /* | ||
+ * Memory | ||
+ * | ||
+ * First, check if the "MemAvailable" value is available on this system. If it is, we will | ||
+ * use it. Otherwise we will attempt to calculate the amount of available memory ourself. | ||
+ */ | ||
+ if ((ptr = strstr(buf, "MemAvailable:")) && sscanf(ptr + 13, "%ld", &mem_available) == 1) { | ||
+ si->total_mem = systeminfo.mem_max - (uint64_t)mem_available * 1024; | ||
+ } else { | ||
+ DEBUG("'MemAvailable' value not available on this system. Attempting to calculate available memory manually...\n"); | ||
+ if (! (ptr = strstr(buf, "MemFree:")) || sscanf(ptr + 8, "%ld", &mem_free) != 1) { | ||
+ LogError("system statistic error -- cannot get real memory free amount\n"); | ||
+ goto error; | ||
+ } | ||
+ if (! (ptr = strstr(buf, "Buffers:")) || sscanf(ptr + 8, "%ld", &buffers) != 1) | ||
+ DEBUG("system statistic error -- cannot get real memory buffers amount\n"); | ||
+ if (! (ptr = strstr(buf, "Cached:")) || sscanf(ptr + 7, "%ld", &cached) != 1) | ||
+ DEBUG("system statistic error -- cannot get real memory cache amount\n"); | ||
+ if (! (ptr = strstr(buf, "SReclaimable:")) || sscanf(ptr + 13, "%ld", &slabreclaimable) != 1) | ||
+ DEBUG("system statistic error -- cannot get slab reclaimable memory amount\n"); | ||
+ si->total_mem = systeminfo.mem_max - (uint64_t)(mem_free + buffers + cached + slabreclaimable) * 1024; | ||
} | ||
- if (! (ptr = strstr(buf, "Buffers:")) || sscanf(ptr + 8, "%ld", &buffers) != 1) | ||
- DEBUG("system statistic error -- cannot get real memory buffers amount\n"); | ||
- if (! (ptr = strstr(buf, "Cached:")) || sscanf(ptr + 7, "%ld", &cached) != 1) | ||
- DEBUG("system statistic error -- cannot get real memory cache amount\n"); | ||
- if (! (ptr = strstr(buf, "SReclaimable:")) || sscanf(ptr + 13, "%ld", &slabreclaimable) != 1) | ||
- DEBUG("system statistic error -- cannot get slab reclaimable memory amount\n"); | ||
- si->total_mem = systeminfo.mem_max - (uint64_t)(mem_free + buffers + cached + slabreclaimable) * 1024; | ||
|
||
/* Swap */ | ||
if (! (ptr = strstr(buf, "SwapTotal:")) || sscanf(ptr + 10, "%ld", &swap_total) != 1) { | ||
-- | ||
2.17.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This series applies on GIT commit dc9bc1c949125140d967edfc598dfad47eedc552 | ||
0001-used_system_memory_sysdep-Use-MemAvailable-value-if-.patch |