Number of bitcoind peers drops precipitously every 30 days or so
Being doing my own diagnosis on this issue. I have bitcoind and lnd running on the same raspberry pi, as per the excellent Raspibolt guide by Staticus. I wrote the following script to log both daemons' cpu usage, mem usage and total number of bitcoind peers:
#!/bin/bash
echo \
&quot;$(date +%D,%T),&quot;\
&quot;$(ps -U satoshi -o comm= -o %cpu= | grep bitcoind | awk '{print $2}'),&quot;\
&quot;$(ps -U satoshi -o comm= -o %mem= | grep bitcoind | awk '{print $2}'),&quot;\
&quot;$(ps -U satoshi -o comm= -o %cpu= | grep lnd | awk '{print $2}'),&quot;\
&quot;$(ps -U satoshi -o comm= -o %mem= | grep lnd | awk '{print $2}'),&quot;\
&quot;$(/usr/local/bin/bitcoin-cli -conf=/etc/bitcoin.conf getconnectioncount)&quot; &gt;&gt; /home/satoshi/bitcoin_connections

My issue may be simply allowing too many connections to my daemon. As peer count grows, mem usage does as well. When it gets to 130+ peers total system memory usage is &gt;80%. My issue may simply be an issue with running out of memory. I'll edit this post when I have more results.
Edit:
It seems that as I get to around 120-130 peers the combined mem usage of bitcoind and lnd exceed 60% of the 1 gig on my RPi, pushing total mem usage over 90%. At that point peer count drops off. I presume the daemon starts to respond very slowly as memory runs out and other peers drop mine. I set maxconnections=125 (default) and the daemon has run for weeks without issues. Since 125 is the default, the same result could be achieved by commenting out the maxconnections line in bitcoin.conf completely.