I'm no expert in tuning a Raspberry Pi but the 100% swap space usage looks really bad news.
I suspect that until you fix that, there's little point in hunting for guilty processes.
Not sure, I think it has something to do with sharding in the database but I'm no expert in this area I'm afraid. I think that the db just got too complex. At least as an experiment, you might want to create a new db with the config as recommended previously and see how that looks. Also check the db sizes. My combined size for all dbs is currently 378M.
Unsurprisingly, the Telegraf db is largest since it is capturing loads of system data every 10s or so. Even though I only keep the data for a week. The home db is split into 2 as mentioned previously.
If it is continually outputing data then perhaps it is not keeping up with what it is trying to do.
Running sudo iotop may be interesting. That will show you (in the IO> column) how much of a processes time is spent waiting for IO (so waiting for the SD card in this case).
If iotop is not installed then sudo apt install iotop
I now think that something went wrong about 2 or maybe 3 weeks ago during minor change and consecutive incremental compile. I have experienced wrongful compiles before, but only minor faults. One time a changed node gives completely weird messages, after replacing node with new one and compile problem was over. One time a changed or placed new node and after compile this node gave 2 output messages with 1 input message. So I am worried something must have gone wrong during this minor change, that resulted in high cpu usage.
As I might never find this problem, I have decided to rebuild my project on second RPI. And I am now in the process of doing just that.
I think I can manage that, but I have just one question for now. I have a lot of settings in global data.
Is it possible to backup the data to a file in order to restore later on new system?