Closed myst3k closed 3 years ago
So this issue could be addressed by the below steps to be fast and efficient.
[ ] Setup a file in each user's home to log the diskusage like the below which is populated from a cron with used disk/mysql/inodes. /home/sitedomain/.cyberpanel/stats/quotausage Format: {"data":[bytes_used,totalAllowed,mysql_bytes_allowed,mysql_kilobytes_used,null,null]} Or this: {"mount_point":"/","blocks":52403200,"percent_used":32,"inodes_percent_used":2,"inodes":26214400,"filesystem":"/","blocks_free":35703564,"blocks_used":16699636,"inodes_used":400590,"inodes_free":25813810}
[ ] Setup a cron to calculate disk/inodes/mysql/mail usage and write to the users file similar to how https://github.com/usmannasir/cyberpanel/blob/stable/plogical/findBWUsage.py works.
[ ] Change the code in https://github.com/usmannasir/cyberpanel/blob/stable/websiteFunctions/website.py to read usage from the cached file in control panel so its not recalculating usage on each page load.
[ ] Change bandwidth calculations to also maybe use cron and cache the information vs calculating on each load of the website management page. https://github.com/usmannasir/cyberpanel/blob/d42d01b0f5abf2a075c9a367a125787ef36b3699/websiteFunctions/website.py#L835
I believe the above things should solve this issue and also not cause other issues. This is similar in how other control panels handle disk quota calculations via a cron and the usage reflected in the panel is always from the cached results of last cron.
I also noticed the disk usage is calculated fine manually when viewing the website https://github.com/usmannasir/cyberpanel/blob/e1bb1bf72f17a788034c3fb2604c0129dc2494ef/plogical/website.py#L625
It looks like all that's actually needed is to store the usage from this function below https://github.com/usmannasir/cyberpanel/blob/e1bb1bf72f17a788034c3fb2604c0129dc2494ef/plogical/virtualHostUtilities.py#L1308-L1324
Into like the below file with just the usage in MB
diskusagemeta = "/home/" + domainName + "/logs/diskquotameta"
Then we can setup the cron and code to reference cache and calculate percentage vs calculating total each time website list or website page is loaded
@usmannasir
I've scheduled the disk calculation to happen every day and save it in website config object. This should fix and speed web website load and search operations.
https://github.com/usmannasir/cyberpanel/commit/dd1c8b23514f3a0cb621b1a0cd36c0cc3907b552
Opened for tracking
457:websiteFunctions/website.py: diskUsed = '1MB' ## to be fixed later