|
From: Martin Paul on 24 Apr 2008 05:34 For a local script which generates disk usage statistics, I need to collect data about e.g. the size of users' home directories. For UFS, quot was very usable, but unfortunately this doesn't work on ZFS. So I decided to use "zfs list -H -o name,used" instead, but it has the bad habit of making the output user-friendly by showing KB, MB or GB depending on the size of a filesystem. E.g.: data/user1 24.5K data/user2 316M data/user3 1.45G It's not that I don't know how to convert GB into KB, but the problem is that I get different granularity depending on the size of the filesystem. When comparing zfs output from yesterday with the one from today, for user3 to actually see a diff his filesystem must grow by at least 10MB. For user2, a change of 1MB is visible, while for user1 512b make a diff. Is there a way to make "zfs list" show sizes in KB (or at least MB) for *all* filesystems, independent of the size? I think an implementation like used in du (default block, -k KB, -h user-friendly) would be better for scripts. mp. -- SysAdmin | Institute of Scientific Computing, University of Vienna PCA | Analyze, download and install patches for Solaris | http://www.par.univie.ac.at/solaris/pca/
From: Andreas F. Borchert on 24 Apr 2008 19:33 On 2008-04-24, Martin Paul <map(a)par.univie.ac.at> wrote: > Is there a way to make "zfs list" show sizes in KB (or at least MB) for > *all* filesystems, independent of the size? I think an implementation > like used in du (default block, -k KB, -h user-friendly) would be better > for scripts. The used diskspace is one of the properties. These may be retrieved using the "zfs get" sub-command. In combination with "-H" (without headers, tab-separated columns) and "-p" (parsable numbers), you will get what you want: theseus# zfs get -Hp used black-eye/users/borchert black-eye/users/borchert used 15235882314 - theseus# It is also possible to retrieve such values through the libzfs library which happens to be undocumented (with the excuse that interfaces are likely to change): #include <libzfs.h> #include <stdio.h> int main(int argc, char** argv) { char* cmdname = argv[0]; if (argc != 2) { fprintf(stderr, "Usage: %s zfs-filesystem\n", cmdname); exit(1); } char* zfsfs = argv[1]; libzfs_handle_t *libzfs = libzfs_init(); if (libzfs == 0) { perror("libzfs"); exit(1); } zfs_handle_t *zhp; if ((zhp = zfs_open(libzfs, zfsfs, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) == 0) { perror(zfsfs); exit(1); } uint64_t size = zfs_prop_get_int(zhp, ZFS_PROP_USED); printf("%llu\n", size); } Andreas.
|
Pages: 1 Prev: Come join us at CommunityOne - May 5th in San Francisco Next: problem with netra t 105 LOM |