417 reputation
213
bio website github.com/maxim
location New York, NY
age 28
visits member for 3 years, 8 months
seen Dec 15 at 6:27

Rubyist, bard, fancier.

twittergithubblog


Dec
9
awarded  Curious
Dec
4
comment One line script to check and react to memory usage
@MatijaNalis unconditionally restarting daemon nightly is what I'm doing now. Stats show that this daemon causes a slow, gradual memory leak over the course of days, so restart won't need to be frequent. Since I have multiple VPS'es running this daemon, restart won't break things, and in fact this avoids restarting them at the same time, as was the case with nightly. Your PID-based line is nice, but the perl one seems complex (compared to chosen answer), could it be done simpler with awk? If you were to simplify the first line, and reformat the answer to bring lines to the top, I'd pick yours.
Dec
4
accepted One line script to check and react to memory usage
Dec
4
awarded  Yearling
Dec
4
comment One line script to check and react to memory usage
"Checking for free memory is definitely wrong for that, as it will give false positives." — false positives isn't the issue, as long as there are no false negatives. As far as ulimit - I should learn more about this resource management, thanks for pointing at it, but it's not exactly what the question is asking.
Dec
4
revised One line script to check and react to memory usage
Clarify question
Dec
4
comment One line script to check and react to memory usage
Note the edit I made to my comment to the OP, where I mentioned more complex my_command.
Dec
4
comment One line script to check and react to memory usage
@ewwhite in this case any_command would be service sidekiq restart for example, but could also be kill [SIG] sidekiq && sleep 5 && kill [SIG2] sidekiq. The service already runs with runit, and "teaching" monit to do this seems very unnecessary.
Dec
4
comment One line script to check and react to memory usage
@AntonyGibbs sounds right, and for process, RSS is fine.
Dec
4
comment One line script to check and react to memory usage
@Zoredache Monit, bluepill, god, and related programs are high ceremony. They "want to" fully control processes, not just monitor them, need to be disabled during deploys, etc. One interesting tool that's trying to avoid doing too much is github.com/mperham/inspeqtor, but it's still very young. Cron seems like the simplest, most elegant solution for now.
Dec
4
comment One line script to check and react to memory usage
You are spot on about RAM in principle, but when you are running a single-purpose VPS in a highly resource-controlled environment, with no swap, and you know that your daemon leaks over time, and you know based on simple graph metrics that VPS consistently crashes when RAM usage reaches beyond certain point, and you can easily avoid this by restarting the daemon, then this might be an ok thing to do. Leaks are hard to find :(, but the show must go on regardless.
Dec
4
comment One line script to check and react to memory usage
Looks great, I'll wait a little before accepting in case you or somebody wants to include more cases (the bonus part for specific process, maybe alternative for exact bytes) listed in a single answer. Would be perfect.
Dec
4
revised One line script to check and react to memory usage
rephrase intro
Dec
4
asked One line script to check and react to memory usage
Oct
8
awarded  Popular Question
Jul
12
answered Chef clients time out trying to connect to server
Jul
10
asked Chef clients time out trying to connect to server
Jul
5
awarded  Commentator
Jul
4
accepted Managing hosts and iptables in scalable architecture
Jul
4
answered Managing hosts and iptables in scalable architecture