Hey everyone, I've been keeping an eye on our "moon" server lately, and the CPU usage metrics have been consistently high, suggesting it might be time to invest in a new, more powerful machine. Before making that decision, I wanted to dig into the data to see exactly what was going on. For some time now, I've been running a custom Python script, [`server_metrics.py`](https://gist.github.com/TheCrazyGM/9c5945224d89152827036b76e84bbbb1), at frequent intervals to collect data on system performance and store it in a SQLite database. This has given me a fantastic historical dataset to work with. #### Visualizing the Problem The first step was to visualize the trend. A picture is worth a thousand words, and plotting the data from the last two weeks confirmed my suspicions immediately.  As you can see, the CPU usage is frequently spiking and sustaining high levels, which isn't ideal for a server running multiple applications. The question now is: what's causing it? #### Digging into the Data To find the culprits, I wrote a SQL query to go through the collected metrics. The goal was to find which process names appeared most often as the top CPU consumer, what their average CPU usage was in those moments, and their maximum recorded spike. The results were immediate and unambiguous: ```sql -- Count how many samples each process was the top-CPU process SELECT top_cpu_name, COUNT(*) AS samples_as_top, AVG(top_cpu_percent) AS avg_top_pct, MAX(top_cpu_percent) AS max_top_pct FROM metrics -- restrict to last two weeks WHERE timestamp >= datetime('now', '-14 days') GROUP BY top_cpu_name ORDER BY samples_as_top DESC LIMIT 10; ``` | top_cpu_name | samples_as_top | avg_top_pct | max_top_pct | | :----------------- | -------------: | ----------: | ----------: | | python3 | 14852 | 65.1 | 705.4 | | systemd | 2905 | 0.1 | 246.2 | | mariadbd | 661 | 2.86 | 150.0 | | php-fpm7.4 | 96 | 6.59 | 633.1 | | fail2ban-server | 93 | 0.0 | 0.0 | | caddy | 91 | 0.0 | 0.0 | | kworker/0:0-events | 33 | 0.0 | 0.0 | | kworker/0:2-events | 24 | 0.0 | 0.0 | | kworker/0:1-events | 23 | 0.0 | 0.0 | | multipathd | 22 | 0.0 | 0.0 | As the data clearly shows, `python3` processes are the runaway top consumer of CPU resources on this server. It was the top process in over 14,800 samples, with an average CPU usage of 65% during those times. Most strikingly, it had a maximum spike of over 700%, indicating that at certain moments, Python scripts were consuming the equivalent of 7 full CPU cores. This analysis narrows down the problem significantly. It's not a system-level issue with something like Caddy or the database (`mariadbd`); the load is coming directly from the Python applications I'm running. The next logical step in this investigation is to dig deeper and differentiate _between_ the various `python3` processes to see which specific scripts are the heaviest hitters. But for now, we have a very clear answer to "What's using the CPU?". The answer is: Python. #### Next Steps I have added more verbose data gathering to `server_metrics.py` to track the command line argments of each process, so we know which one is which. I'll continue to monitor the data and report back to you as I find new insights. As always, Michael Garcia a.k.a. TheCrazyGM
author | thecrazygm |
---|---|
permlink | investigating-high-cpu-usage-on-the-moon-server |
category | hive-186392 |
json_metadata | {"app":"peakd/2025.7.1","format":"markdown","image":["https://files.peakd.com/file/peakd-hive/thecrazygm/23w3CrDCxfPgxXuPxK5CSyQAqWHU1yixukVc7poYh1v6fqcomrPpBanQcCJ1AfmLb9iYo.png"],"tags":["dev","tribes","archon","pimp","proofofbrain","musing"],"users":[]} |
created | 2025-07-15 15:34:39 |
last_update | 2025-07-15 16:27:09 |
depth | 0 |
children | 4 |
last_payout | 2025-07-22 15:34:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 5.476 HBD |
curator_payout_value | 5.453 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,798 |
author_reputation | 104,038,979,497,749 |
root_title | "Investigating High CPU Usage on the "Moon" Server" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 144,083,377 |
net_rshares | 31,211,411,761,355 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
jacor | 0 | 25,348,953,462 | 50% | ||
penguinpablo | 0 | 143,260,584,199 | 14% | ||
funnyman | 0 | 1,553,643,448 | 5.6% | ||
eforucom | 0 | 21,095,987,259 | 100% | ||
moretea | 0 | 2,632,941,295 | 10% | ||
gamer00 | 0 | 19,256,013,146 | 5% | ||
ganjafarmer | 0 | 24,943,502,520 | 12.5% | ||
thatsweeneyguy | 0 | 449,998,303 | 100% | ||
mes | 0 | 493,605,669,983 | 24% | ||
calmphoenix | 0 | 1,461,942,806 | 30% | ||
ecoinstant | 0 | 17,027,643,112 | 100% | ||
cryptoknight12 | 0 | 39,691,694,239 | 100% | ||
alphacore | 0 | 7,391,383,876 | 7.12% | ||
robtheranger | 0 | 5,910,191,477 | 100% | ||
techken | 0 | 23,640,853,646 | 25% | ||
joeyarnoldvn | 0 | 450,897,967 | 1.47% | ||
pixelfan | 0 | 48,654,821,356 | 5.8% | ||
likedeeler | 0 | 251,272,282,238 | 100% | ||
hdmed | 0 | 5,367,371,993 | 50% | ||
noloafing | 0 | 3,280,477,777 | 49.76% | ||
artlover | 0 | 1,706,242,675 | 100% | ||
morwhale | 0 | 832,777,244 | 50% | ||
morwhaleplus | 0 | 592,198,730 | 50% | ||
coolguy123 | 0 | 2,738,459,853 | 1% | ||
morwhalebonus | 0 | 587,922,802 | 50% | ||
mytechtrail | 0 | 13,441,958,388 | 10% | ||
jozefkrichards | 0 | 4,816,399,163 | 50% | ||
elderson | 0 | 468,474,201 | 6.25% | ||
sneakyninja | 0 | 18,835,643,329 | 24.88% | ||
najat | 0 | 3,097,345,470 | 50% | ||
steembasicincome | 0 | 8,876,377,759,787 | 100% | ||
cryptonized | 0 | 236,820,493 | 14% | ||
deepresearch | 0 | 680,277,483,141 | 17% | ||
hetty-rowan | 0 | 47,441,333,954 | 50% | ||
irisworld | 0 | 1,150,969,265 | 7.5% | ||
careassaktart | 0 | 4,159,141,532 | 12.5% | ||
anikys3reasure | 0 | 2,992,125,472 | 50% | ||
russellstockley | 0 | 13,221,401,510 | 10% | ||
jglake | 0 | 6,721,867,958 | 20% | ||
blockchainyouth | 0 | 22,680,782,165 | 25% | ||
abrockman | 0 | 2,775,116,242,772 | 100% | ||
sbi2 | 0 | 5,995,134,516,790 | 100% | ||
braaiboy | 0 | 115,604,113,103 | 25% | ||
awesomegames007 | 0 | 1,283,602,644 | 50% | ||
tsnaks | 0 | 24,270,183,959 | 100% | ||
sbi3 | 0 | 973,084,345,586 | 33.53% | ||
beco132 | 0 | 1,723,339,235 | 54% | ||
fw206 | 0 | 2,995,146,770,633 | 36% | ||
netzisde | 0 | 4,682,895,846 | 100% | ||
dailyspam | 0 | 23,807,472,942 | 20% | ||
bububoomt | 0 | 7,423,876,802 | 100% | ||
thedailysneak | 0 | 25,696,925,572 | 24.88% | ||
smartvote | 0 | 134,255,193,899 | 6.2% | ||
vixmemon | 0 | 9,390,190,317 | 29.56% | ||
babysavage | 0 | 9,521,174,377 | 49.76% | ||
ravensavage | 0 | 5,239,282,632 | 49.76% | ||
mk992039 | 0 | 671,667,078 | 4% | ||
guurry123 | 0 | 7,221,877,446 | 10% | ||
ecoinstats | 0 | 57,832,112,647 | 100% | ||
athunderstruck | 0 | 3,974,757,126 | 10% | ||
piestrikesback | 0 | 749,399,278 | 100% | ||
kind.network | 0 | 927,194,385 | 25% | ||
buildingpies | 0 | 56,322,146,848 | 100% | ||
jacuzzi | 0 | 701,761,225 | 1.4% | ||
slothlydoesit | 0 | 15,891,866,104 | 10% | ||
synergized | 0 | 4,436,284,695 | 50% | ||
instagram-models | 0 | 503,668,710,962 | 100% | ||
hungrybear | 0 | 624,755,735 | 14% | ||
afternoondrinks | 0 | 18,858,145,316 | 100% | ||
thelogicaldude | 0 | 25,867,093,159 | 50% | ||
ilanisnapshots | 0 | 12,231,617,305 | 100% | ||
shauner | 0 | 537,141,966 | 50% | ||
gurseerat | 0 | 5,344,045,063 | 20% | ||
lrekt01 | 0 | 5,048,989,948 | 80% | ||
everythingsmgirl | 0 | 8,087,378,397 | 50% | ||
maddogmike | 0 | 15,916,956,611 | 10% | ||
lisamgentile1961 | 0 | 8,527,726,910 | 3% | ||
sbi-tokens | 0 | 68,298,046,977 | 49.76% | ||
successchar | 0 | 3,016,134,135 | 10% | ||
stem.alfa | 0 | 2,401,962,137 | 50% | ||
bilpcoin.pay | 0 | 547,007,724 | 10% | ||
qwertm | 0 | 5,451,989,112 | 50% | ||
bilpcoinbpc | 0 | 888,129,026 | 5% | ||
treasure.hoard | 0 | 459,796,519,690 | 100% | ||
dpend.active | 0 | 3,773,364,499 | 10% | ||
ykretz | 0 | 1,408,621,679 | 15% | ||
thepeakstudio | 0 | 511,643,201 | 10% | ||
sketching | 0 | 5,791,953,311 | 50% | ||
hivelist | 0 | 52,503,187,757 | 25% | ||
kiemis | 0 | 8,908,720,609 | 2.5% | ||
woelfchen | 0 | 139,654,105,623 | 36% | ||
hivehustlers | 0 | 5,775,081,502 | 20% | ||
archon-gov | 0 | 104,609,726,514 | 50% | ||
martial.media | 0 | 652,860,456 | 12.5% | ||
rudy-dj | 0 | 2,704,820,776 | 30% | ||
barbyjr | 0 | 1,785,465,663 | 25% | ||
cryptounicorn420 | 0 | 50,890,604,147 | 100% | ||
youloseagain | 0 | 523,604,270 | 5% | ||
szukamnemo | 0 | 27,028,167,732 | 8.5% | ||
esmeesmith | 0 | 2,736,026,310 | 50% | ||
tikki00taffi | 0 | 1,394,491,043 | 75% | ||
emsenn0 | 0 | 4,057,318,067 | 20% | ||
thecryptopimp | 0 | 5,657,205,873 | 20% | ||
tokenpimp | 0 | 286,584,693,978 | 20% | ||
pimptoken | 0 | 3,681,565,288 | 20% | ||
wynella | 0 | 11,290,751,324 | 25% | ||
pimp.token | 0 | 2,337,400,750 | 20% | ||
biglove | 0 | 451,803,470 | 10% | ||
holovision.stem | 0 | 739,399,138 | 50% | ||
alkirua | 0 | 34,200,163,332 | 100% | ||
dibblers.dabs | 0 | 45,741,028,512 | 10% | ||
pishio | 0 | 580,954,109,667 | 15% | ||
olympicdragon | 0 | 869,347,860 | 100% | ||
trashyomen | 0 | 748,313,691 | 75% | ||
wongi | 0 | 73,800,211,991 | 50% | ||
adulruna | 0 | 20,368,394,432 | 100% | ||
vrezyy | 0 | 9,076,949,953 | 25% | ||
tub3r0 | 0 | 756,478,337 | 10% | ||
mxm0unite | 0 | 1,602,373,945 | 50% | ||
dstampede | 0 | 1,887,200,876 | 100% | ||
techguard | 0 | 524,679,275 | 8.5% | ||
silentriot | 0 | 88,115,986,698 | 100% | ||
tydynrain | 0 | 16,250,434,762 | 10% | ||
svanbo | 0 | 1,788,500,514 | 1% | ||
noctury | 0 | 23,899,941,502 | 50% | ||
rulivyxo | 0 | 555,184,907 | 30% | ||
woodathegsd | 0 | 1,473,914,530 | 12.5% | ||
chrisly.social | 0 | 59,066,251,058 | 50% | ||
pimpdistrict | 0 | 1,010,836,059 | 20% | ||
thepimpdistrict | 0 | 1,839,850,391 | 20% | ||
ryosai | 0 | 5,804,713,827 | 24% | ||
boeltermc | 0 | 6,862,430,071 | 100% | ||
beststart | 0 | 15,355,609,248 | 5% | ||
fonestreet | 0 | 3,227,980,424 | 25% | ||
holdeck2 | 0 | 1,621,275,594 | 100% | ||
vrezion | 0 | 576,624,391 | 100% | ||
magic.bee | 0 | 126,719,981 | 100% | ||
caelum1infernum | 0 | 537,831,146 | 2.5% | ||
casimodo | 0 | 928,156,837 | 100% | ||
kam5iz | 0 | 1,268,376,943 | 10% | ||
juliasjohn | 0 | 1,613,502,016 | 100% | ||
sieghard1990 | 0 | 4,152,266,363 | 100% | ||
poplar-22 | 0 | 3,552,877,867 | 25% | ||
monsterrerentals | 0 | 34,078,633,639 | 100% | ||
deggial | 0 | 850,369,394 | 100% | ||
ngwinndave | 0 | 14,773,318,226 | 50% | ||
katiebeth | 0 | 450,219,905 | 40% | ||
gornat | 0 | 37,503,921,332 | 100% | ||
kasih-sayang | 0 | 866,244,960 | 30% | ||
whitneyalexx | 0 | 17,510,933,403 | 50% | ||
ganjafrmer | 0 | 3,568,524,620 | 25% | ||
pof.archon | 0 | 464,649,181 | 50% | ||
slothburn | 0 | 1,320,016,956 | 10% | ||
freecompliments | 0 | 3,094,502,733,310 | 100% | ||
georgesantana73 | 0 | 1,064,295,071 | 100% | ||
tengolotodo.leo | 0 | 1,474,216,352 | 50% | ||
hive-140084 | 0 | 79,307,651,555 | 100% | ||
timix648 | 0 | 1,140,410,016 | 70% | ||
briefmarken | 0 | 60,167,300,036 | 100% | ||
converter.bonus | 0 | 836,168,620 | 50% | ||
pepetoken | 0 | 777,168,679 | 10% | ||
mviews | 0 | 28,143,387,562 | 100% | ||
ijebest | 0 | 466,917,233 | 5% | ||
lordnasty | 0 | -24,133,298,628 | -100% | ||
bankrobbery | 0 | 629,193,723 | 50% | ||
fc-curation | 0 | 5,762,207,577 | 100% | ||
spoonies | 0 | 39,430,313,786 | 100% | ||
fc-rewards | 0 | 4,128,316,816 | 100% | ||
d-a-d | 0 | 10,575,143,138 | 50% | ||
zvaleska | 0 | 906,585,276 | 100% | ||
pepe.voter | 0 | 22,154,745,929 | 50% | ||
blessskateshop | 0 | 57,449,897,988 | 12% | ||
claudiavb | 0 | 18,160,837,207 | 50% | ||
fc-arbitration | 0 | 771,931,878 | 100% | ||
murtaza-7868 | 0 | 823,221,403 | 50% | ||
learn2code | 0 | 1,131,688,691 | 50% | ||
lolz.byte | 0 | 0 | 100% | ||
bbarelyseal | 0 | 0 | 100% | ||
indiasierra | 0 | 13,140,349,508 | 50% | ||
partytime.inleo | 0 | 6,964,803,577 | 10% | ||
magicalex | 0 | 3,956,943,388 | 70% | ||
calebmarvel24 | 0 | 2,586,470,801 | 10% | ||
indeedly | 0 | 3,386,489,330 | 50% | ||
pakx | 0 | 669,365,354,107 | 50% | ||
trovepower | 0 | 2,386,771,338 | 50% | ||
mmbbot | 0 | 2,251,502,644 | 50% | ||
digi-alt | 0 | 4,206,270,748 | 50% | ||
michael561 | 0 | 5,483,968,721 | 20% | ||
thecrazygm.bank | 0 | 7,904,621,960 | 100% | ||
longhunter | 0 | 2,056,166,809 | 100% | ||
magic.byte | 0 | 0 | 100% | ||
sports.power.bot | 0 | 0 | 0.01% | ||
savvyfrog | 0 | 764,008,495 | 25% | ||
caro-lina | 0 | 393,569,767 | 100% |
Keep us in the loop, this is a fascinating case since my expectation would be we should be using less CPU now with less active player base between seasons. !PAKX !PIMP !PIZZA
author | ecoinstant |
---|---|
permlink | re-thecrazygm-szg630 |
category | hive-186392 |
json_metadata | {"tags":["hive-186392"],"app":"peakd/2025.7.1","image":[],"users":[]} |
created | 2025-07-15 15:37:51 |
last_update | 2025-07-15 15:37:51 |
depth | 1 |
children | 1 |
last_payout | 2025-07-22 15:37:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.010 HBD |
curator_payout_value | 0.010 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 175 |
author_reputation | 862,982,692,690,250 |
root_title | "Investigating High CPU Usage on the "Moon" Server" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 144,083,420 |
net_rshares | 59,769,004,405 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
thecrazygm | 0 | 51,684,791,270 | 100% | ||
tydynrain | 0 | 8,084,213,135 | 5% |
<center><table><tr></tr><tr><td><center><img src='https://files.peakd.com/file/peakd-hive/pakx/PakX-logo-transparent.png'><p><sup><a href='https://hive-engine.com/?p=market&t=PAKX'>View or trade </a> <code>PAKX</code> tokens.</sup></p></center></td><td><center>@ecoinstant, PAKX has voted the post by @thecrazygm. (2/2 calls)</p><br><br><p>Use !PAKX command if you hold enough balance to call for a @pakx vote on worthy posts! More details available on <a href='/@pakx'>PAKX Blog</a>.</p></center></td></tr></table></center>
author | pakx |
---|---|
permlink | re-ecoinstant-1752593926 |
category | hive-186392 |
json_metadata | "{"tags": ["pakx", "hivepakistan"], "app": "HiveDiscoMod"}" |
created | 2025-07-15 15:38:45 |
last_update | 2025-07-15 15:38:45 |
depth | 2 |
children | 0 |
last_payout | 2025-07-22 15:38:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 524 |
author_reputation | 90,359,712,187 |
root_title | "Investigating High CPU Usage on the "Moon" Server" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 144,083,435 |
net_rshares | 51,387,305,894 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
thecrazygm | 0 | 51,387,305,894 | 100% |
<center>PIZZA! $PIZZA slices delivered: @ecoinstant<sub>(2/20)</sub> tipped @thecrazygm <sub>Come get [MOON](https://moon.hive.pizza)ed!</sub></center>
author | pizzabot |
---|---|
permlink | re-investigating-high-cpu-usage-on-the-moon-server-20250715t153814z |
category | hive-186392 |
json_metadata | "{"app": "pizzabot"}" |
created | 2025-07-15 15:38:15 |
last_update | 2025-07-15 15:38:15 |
depth | 1 |
children | 0 |
last_payout | 2025-07-22 15:38:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.011 HBD |
curator_payout_value | 0.011 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 156 |
author_reputation | 7,607,704,952,650 |
root_title | "Investigating High CPU Usage on the "Moon" Server" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 144,083,428 |
net_rshares | 67,245,331,721 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
thecrazygm | 0 | 67,245,331,721 | 100% |
I've been through that process of narrowing down possible causes to issues countless times, and I know how challenging it can be sometimes, so congratulations on finding part of the cause. I'm sure that you'll noodle out the last specifics in no time! 😁🙏💚✨🤙
author | tydynrain |
---|---|
permlink | re-thecrazygm-2025715t195810128z |
category | hive-186392 |
json_metadata | {"tags":["dev","tribes","archon","pimp","proofofbrain","musing"],"app":"ecency/4.2.1-vision","format":"markdown+html"} |
created | 2025-07-16 05:58:09 |
last_update | 2025-07-16 05:58:09 |
depth | 1 |
children | 0 |
last_payout | 2025-07-23 05:58:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.010 HBD |
curator_payout_value | 0.011 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 257 |
author_reputation | 204,843,050,088,836 |
root_title | "Investigating High CPU Usage on the "Moon" Server" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 144,099,638 |
net_rshares | 66,521,836,340 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
thecrazygm | 0 | 66,521,836,340 | 100% |