LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-19-2011, 06:02 AM   #1
unkie888
Member
 
Registered: Aug 2007
Posts: 67

Rep: Reputation: 24
Question monitoring directory space usage


Code:
du
is a great utility but when dealing with very large filesystems it can take a long time to run.

is there a daemon i can run that will monitor disk usage of select directories, so that i can have real-time or near-real-time stats?
 
Old 08-19-2011, 07:15 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,084

Rep: Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799
You might want to look at the stat utility, possibly with some of its options (see the manual page).

stat dirname will show you, for example
Code:
stat /spares/gnis
  File: `/spares/gnis'
  Size: 12288           Blocks: 24         IO Block: 4096   directory
Device: 809h/2057d      Inode: 5505025     Links: 2                                                 
Access: (0555/dr-xr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)                            
Access: 2011-08-19 07:56:49.657805813 -0400                                                         
Modify: 2007-12-03 17:28:31.000000000 -0500                                                         
Change: 2011-03-14 16:55:16.443481961 -0400                                                         
 Birth: -
On the other hand, if you look at man 2 stat you might be able to roll-your-own utility customized for your needs; here is an example, named status.c, that may be useful:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <grp.h>
#include <pwd.h>
#include <time.h>

main    (int argc, char *argv[])
{
        time_t  now;
        struct  group   *grentry, *getgrgid (gid_t);
        struct  passwd  *pwentry, *getpwuid (uid_t);
        struct  stat    status;
        struct  tm      *tstr, *localtime (const time_t *);

        if (argc != 2) {
                (void) fprintf (stderr, "usage:\t%s file\n", argv [0]);
                return (1);
        }
        /*      get stat structure for specified file   */
        if (stat (argv [1], &status) == -1) {
                (void) fprintf (stderr, "%s:\tcan't stat %s\n",
                    argv [0], argv [1]);
                return (2);
        }
        /*      display the type of file        */
        if (status.st_mode & S_IFREG)
                (void) fprintf (stdout, "Regular File:\t");
        else if (status.st_mode & S_IFDIR)
                (void) fprintf (stdout, "Directory:\t");
        else if (status.st_mode & S_IFIFO)
                (void) fprintf (stdout, "FIFO Special File:\t");
        else if (status.st_mode & S_IFCHR)
                (void) fprintf (stdout, "Character Special File:\t");
        else if (status.st_mode & S_IFBLK)
                (void) fprintf (stdout, "Block Special File:\t");
        else if (status.st_mode & S_IFLNK)
                (void) fprintf (stdout, "Symbolic Link:\t");
        else
                (void) fprintf (stdout, "Unknown File:\t");
        (void) fprintf (stdout, "%s\n", argv [1]);
        (void) fprintf (stdout, "Inode:\t\t%d\n", (int) status.st_ino);
        (void) fprintf (stdout, "Mode:\t\t%d\n", (int) status.st_mode);
        (void) fprintf (stdout, "Device:\t\t%d\n", (int) status.st_dev);
        (void) fprintf (stdout, "Blocksize:\t%d\n", (int) status.st_blksize);
        (void) fprintf (stdout, "Links:\t\t%d\n", (int) status.st_nlink);
        (void) fprintf (stdout, "Owner (%d):\t", (int) status.st_uid);
        /*      look up owner in /etc/passwd    */
        if ((pwentry = getpwuid (status.st_uid)) == (struct passwd *) NULL) {
                (void) fprintf (stdout, "not found\n");
        } else {
                (void) fprintf (stdout, "%s\n", pwentry->pw_name);
        }
        /*      look up group name in /etc/group        */
        (void) fprintf (stdout, "Group (%d):\t", (int) status.st_gid);
        if ((grentry = getgrgid (status.st_gid)) == (struct group *) NULL) {
                (void) fprintf (stdout, "no found\n");
        } else {
                (void) fprintf (stdout, "%s\n", grentry->gr_name);
        }
        (void) fprintf (stdout, "Size:\t\t%d\n", (int) status.st_size);
        now = status.st_atime;
        tstr = localtime (&now);
        (void) fprintf (stdout, "atime:\t\t%02d:%02d:%02d %02d/%02d/%02d\t",
            tstr->tm_hour, tstr->tm_min, tstr->tm_sec,
            tstr->tm_mon+1, tstr->tm_mday, tstr->tm_year);
        (void) fprintf (stdout, "(Last Access)\n");
        now = status.st_ctime;
        tstr = localtime (&now);
        (void) fprintf (stdout, "ctime:\t\t%02d:%02d:%02d %02d/%02d/%02d\t",
            tstr->tm_hour, tstr->tm_min, tstr->tm_sec,
            tstr->tm_mon+1, tstr->tm_mday, tstr->tm_year);
        (void) fprintf (stdout, "(Last Data Modification)\n");
        now = status.st_mtime;
        tstr = localtime (&now);
        (void) fprintf (stdout, "mtime:\t\t%02d:%02d:%02d %02d/%02d/%02d\t",
            tstr->tm_hour, tstr->tm_min, tstr->tm_sec,
            tstr->tm_mon+1, tstr->tm_mday, tstr->tm_year);
        (void) fprintf (stdout, "(Last File Status Change)\n");
        return (0);
}
You could save the above as, say, status.c then enter
Code:
make status
to compile it -- execute it with
Code:
status name
where name is a file or directory. And, of course, you can modify the above as you see fit.

You might also consider using the df utility on the disk partition you're concerned about; if you see growth in the partition that would probably be an indication that you need to take some action.

Hope this helps some.
 
  


Reply

Tags
disk, du


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
partition space and disk space usage and free don't match nsic Linux - Newbie 3 02-22-2013 12:57 PM
Monitoring memory usage kenneho Linux - Server 4 10-02-2008 08:35 AM
Directory Size and Space Usage sidra Red Hat 2 05-11-2007 04:09 PM
Monitoring System Usage dunmarie Linux - Newbie 2 11-11-2003 12:37 AM
Monitoring processor usage bananaman Linux - General 3 04-22-2003 06:21 AM


All times are GMT -5. The time now is 07:01 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration