开发者

How to quickly get directory (and contents) size in cygwin perl

开发者 https://www.devze.com 2023-01-26 18:50 出处:网络
I have a perl script which monitors several windows network share drive usages.It currently monitors the free space of several network drives using the cygwin df command.I\'d like to add the individua

I have a perl script which monitors several windows network share drive usages. It currently monitors the free space of several network drives using the cygwin df command. I'd like to add the individual drive usages as well. When I use the

du -s | grep total

command, it takes for ever. I need to look at the shared drive usages because there are several network drives that are shared from a single 开发者_运维问答drive on the server. Thus, filling one network drive fills them all (yes I know, not the best solution, not my choice).

So, I'd like to know if there is a quicker way to get the folder usage that doesn't take for ever.


du -s works by recursively querying the size of every directory and file. If your filesystem implementation doesn't store this total value somewhere, this is the only way to determine disk usage. Therefore, you should investigate which filesystem and drivers you are using, and see if there is a way to directly query for this data. Otherwise, you're probably SOL and will have to suck up the time it takes to run du.


1) The problem possibly lies in the fact that they are network drives - local du is acceptably fast in most cases. Are you doing du on the exact server where the disk is housed? If not, try to approach the problem from a different angle - run an agent on every server hosting the drives which calculates the local du summaries and then report the totals to a central process (either IPC or heck, by writing a report into a file on that same share filesystem).

2) If one of the drives is taking a significantly larger share of space (on average) than the rest of them, you can optimize by doing du on all but the "biggest" one and then calculate the biggest one by subtracting the sum of others from df results

3) Also, to be perfectly honest, it sounds like a suboptimal solution from design standpoint - while you indicated that it's not your choice, I'd strongly recommend that you post a question on how you can improve the design within the parameters you were given (to ServerFault website, not SO)

0

精彩评论

暂无评论...
验证码 换一张
取 消