Read the statement by Michael Teeuw here.
Strange issue
-
Hi,
Investigating crashes and freezes, etc, can be very difficult.
When everything is running fine and you collect data, you will see that everything is more or less okay.
When it crashed or is frozen, you are too late.Since a few weeks I had the problem that my MM was frozen and I could not enter any commands or a command took painstakingly long to return output.
A command like top was out of the question for example.
Using a script running as a cron job, I was able to identify a memory issue with electron.js.
I then decide to use a usb stick on which I created a swap device.
Since then my MM is not freezing anymore.
And I am able to see electron.js using up my memory and sometimes I see spikes in CPU usage.Mind you, that crashing is something different then freezing, but the tools to use are more or less the same, provided the MM application or a MM module is not the culprit.
My script to check memory usage, very basic and simple:
pi@MagicPi:~ $ cat top.sh #!/bin/sh date >> /home/pi/top.txt top -b -o +%MEM | head -n 22 >> /home/pi/top.txt echo "=============================================" >> /home/pi/top.txt
The cron job:
00,05,10,15,20,25,30,35,40,45,50,55 * * * * /home/pi/top.sh >/dev/null 2>&1
%CPU will sort on CPU usage.
Concerning swap space, top will show the usage, but this gives a quick view:
$ free -h
Swap details via:
$ swapon -s
There are many more commands and settings to look at, but one has to start somewhere :-)
Good luck.
-
@evroom Thank you for your reply and i want to try all that you have written as i really feel it may help my case … but i am having a hard time decoding your steps.
Please walk me through it, on a step by step all the way to the end on how to even increase the swap file, and what to put on my scrip and make it executable and what is a cron job?? that will be my first one actually :)
Denis
-
@richland007
Since you managed to setup MM to the point that it is running, but crashing, I take it you know a little bit of Linux.
Otherwise it will be more like a Linux workshop.Do you know how to use nano and/or vi to edit files?
Know what for example cat, tail and head does?
Just some Linux basics.I do not want to sound like a smartarse and knowitall, am a hobbyist just like you.
Just to know the level of describing that is needed. -
@evroom Hahah dont’ worry about coming out the wrong way … i know a little bit and i do know what nano and vi does …i use nano.
I am not familiar with cats and tails etc but i am a fast learner and i have set up quite a bit of MM modules some stubborn ones as well but i am no expert by all means.I couldn’t read your first response at the beginning for some reason it wasn’t structured properly or my browser wasn’t reading it right now its a bit better but i still need some guidance
So i need to set up a script called “top” and make it executable right??
Than i have no idea what to do with cron :) !!!Lets start somewhere :)
Denis
-
Then let’s give it a try :slightly_smiling_face:
First create the script:
pi@MagicPi:~ $ cd pi@MagicPi:~ $ nano top.sh
Copy-paste this:
!/bin/sh date >> /home/pi/top.txt top -b -o +%MEM | head -n 22 >> /home/pi/top.txt top -b -o +%MEM | head -n 22 >> /home/pi/top.txt echo "=============================================" >> /home/pi/top.txt
Make it executable:
pi@MagicPi:~ $ chmod 755 top.sh
Perhaps a good idea to prepare the output file in order to be sure the cron user can write in it:
pi@MagicPi:~ $ touch /home/pi/top.txt pi@MagicPi:~ $ chmod 666 /home/pi/top.txt
Now we add a cronjob:
pi@MagicPi:~ $ crontab -e
Add this line at the end:
00,05,10,15,20,25,30,35,40,45,50,55 * * * * /home/pi/top.sh >/dev/null 2>&1
To verify:
pi@MagicPi:~ $ crontab -l
To verify if the cronjob is actually running:
pi@MagicPi:~ $ tail -F /var/log/syslog
To check if something comes in your output file:
pi@MagicPi:~ $ tail -F top.txt
The script will run every 5 minutes, every hour, every day.
It will output the top 15 MEMory usage and the top 15 CPU usage.In your case, it will be interesting to look at the last entries before the crash.
Need to identify first if it is an CPU or MEM issue, or both.
Then we can modify the script.Please do not post lengthy output.
Better we minimise the output by grepping and sorting, etc.Success!
-
@evroom Ahhh you are a great man
I will set it up as soon as i get home
thanks in advance
Denis -
Ha ha, not that great, my MM is as slow as a turtle again.
The used swap on my USB stick in the meanwhile is 1GB.
Cannot use any commands to investigate further.
Not very satisfactory. :frowning_face: -
@evroom Mine is not slow it works “fine” it just keeps restarting
I am really curious to see the output of that file and see whats causing this behavior
D -
If previous suggestions dont help, try removing the MMM-WatchDog module and see if it crashes anymore.
-
@richland007
I re-read your first post and your problem is more restarting then actual crashing.
Of course a restart can be caused by a crash …
MMM-WatchDog tends to restart MM, so I too would suggest to remove this module.
In principle all it does is sending a ping and restarting MM using pm2 when a timeout occurs.
I also would expect to see some lines in the pm2 logs on WatchDog.
Can you do ?:pi@MagicPi:~ $ grep -i watchdog /home/pi/.pm2/logs/mm-out.log pi@MagicPi:~ $ grep -i watchdog /home/pi/.pm2/logs/mm-error.log
What is alo a good package to install is sysstat:
pi@MagicPi:~ $ sudo apt-get install sysstat
This allows for commands like iostat and sar.
vmstat 10 10 iostat 10 10 sar 10 10