Is it good practice to restart Pi every few days?

Hi,
I am running HA on a Pi3B+, but noticed that after 6 days the module hangs.
Ping works fine, HA is unreachable, but SSH after a couple of tries works although with a huge delay.

Noticed also that RAM usage increase by around 2% daily and after 6 days it exceeds 90%, which might be the problem, but I am not sure.
It is a good idea to make a script to restart the Pi every 5 days or I might encounter new problems?

Seems like you have a memory leak.
What addons are you running ?

the below:

You ‘could’ try disabling them one at a time to see which one may be causing the issue.
Other that that, I suppose you have no option but to schedule a reboot.
Seems a bit clunky though. :man_shrugging:

will start with Grafana, Configurator and Samba Share … the others are all required

I don’t think it is an actual problem.

Depending on your setup it will eventually start using more memory, in my case I had the same behavior it will start increasing until it passes 90% then somewhere after 90% it frees up memory and it went back to 60-70%. Sometimes it used to hang or slow quite a bit, a restart solved my issues, same as you.

At the end I actually just did a cleanup of all the stuff I don’t actually need or use, so I did a pretty good cleanup of automations, scripts, addons and optimized the way in which I implemented all my devices. And while I was doing that I started commenting and nicely organizing my code.

The one thing that helped the most is filtering the entities on the recorder. Do NOT record stuff you don’t actually need to record stuff you don’t need like weather, switches, lights, devices that you don’t track and specially those devices whose value changes very often.

The Raspberry Pi 3 B+ is definitely not a device to run tons of stuff but in your case I don’t see what could be eating so many resources aside from having a ton of devices and recording the data for all of them. Try to purge your database as often as possible too.

I used to run on pi3 (now on pi4) and I noticed a gradual memory usage increase the moment I switched from sqlite to mariadb. Over the course of a week or so you could see a trend of mem usage going up. It didn’t drop down again and kept creeping closer to 100% at which point you get the same issues you are seeing. I used to have a cronjob that reboots the pi every couple of days or at least restarts the docker containers.

thanks all of you for the input!
I record only required info that I would need to use in my automations and keep data in the MariaDB for just 4 days.
Currently I am trying to purge to electricity consumption usage stored in InfluxDB but that is work in progress :slight_smile:

Good to know is that if you have a purging strategy of let’s say every 5 days, and you reboot within those 5 days every time, the data will never be purged.

It is a good idea to make a script to restart the Pi every 5 days or I might encounter new problems?

You need to fix the disease, not the symptoms. Try and monitor your RAM usage, and use the ‘htop’ command in order to see what things are using up your RAM.

I may be running the 4GB Rpi 4, but so far I have 24 days uptime, and RAM usage does not increase over time.

1 Like

good to know, thanks.
my purge is of 4 days and my Pi need a reboot after around 6 days

yes that would be ideal … but I am asking here maybe someone had same issue and may guide me into the right direction

I would start at an OS level. Just look into system monitoring programs for the OS you are running HA on, it should have some built in tools, for example:

  • ‘Task Manager’ on Windows
  • ‘Activity Monitor’ on MacOS
  • ‘htop’ and ‘top’ on many flavours of Linux, including Raspian which is what I use.

Just see what process is eating up your RAM and then look into why it is doing so. I did have this issue a while back with a 3rd party node on NodeRED, and as soon as I uninstalled the node, NodeRED memory usage stays below 300Mb most of the time, but with the memory leak it would use 500+Mb after 12 hours.

I have only have a few add-ons (ssh, Samba, & DuckDNS) and my memory utilization stays below 25%.

It looks like you may be on Hassio. If so, you can check the utilzation for each add-on as shown below. As best I can tell, its one at a time.

core-ssh:~# **hassio addons stats core_ssh**
blk_read: 49152
blk_write: 40960
cpu_percent: 0
memory_limit: 971128832
memory_percent: 0.51
memory_usage: 4947968
network_rx: 3369056
network_tx: 197279

The add-on name is the “slug:” entry shown when you run hassio addons list

- available: true
  build: false
  description: Flow-based programming for the Internet of Things
  detached: false
  icon: true
  installed: null
  logo: true
  name: Node-RED
  repository: a0d7b954
  slug: a0d7b954_nodered
  url: https://github.com/hassio-addons/addon-node-red
  version: 5.0.3

You may want to swap your boot SD card. Bad read / writes can cause many different kinds of problems … Besides it wouldn’t hurt to back up your system anyway before you go messing around with the software.

thanks chris … I take a backup daily. the SSD is quite new to be honest

thanks … but I did not find a way to run the commands :slight_smile:

I am running HASSIO through a docker

Sorry, my reference assumed you were running HassIO on HassOS, which is more of an appliance docker environment. You can check out this post for some options that may help either spotcheck or track the resource usage of the various containers.

I think the memory issue is being created with Node-Red, what is your opinion on this?

image

I had the same issue 1/2 weeks ago so I’ve stopped using node-red.
I can confirm.
Had CPU spikes to 100% on my RPI4 with node-red active running only a simple ping automation. After disabling node everything is fine again and usage is under 5%