APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version


Perl 'kreport' gives details on Kerio Connect Store usage

A Kerio® Connect administrator was recently surprised to find that one user had two Draft messages with large attachments that consumed over a gigabyte of storage by themselves. By itself, that's not necessarily a problem - such messages should be sent by FTP or Dropbox or stored in Kerio Workspace, Google Docs or similar places, but they aren't causing any real problem just sitting there. However, large files like that do add to total disk space used and increase the time needed to make full backups.

So how do you find silly things like that? The Kerio administration console can give you some information about users, but it doesn't actually count everything and it doesn't give any details. You can look at your Store directory using your computer operating system, but that gives you too much information. Wouldn't it be nice to have something a little better?

User's usage from Kerio Admin



Kreport Perl Script

How about something that could give you this for every user in your domains?

- aplawrence.com/sales-support 6 messages 6.25 Mbytes all told, 5.91
Mbytes in .eml's: Largest directory #deleted/#msgs has 5 messages
and is 5.91 Mbytes.  Largest mail message #deleted/#msgs/0000014f.eml
is 1.49 Mbytes

- aplawrence.com/tony 7,810 messages 494.58 Mbytes all told,
360.43 Mbytes in .eml's: Largest directory INBOX/#msgs has
2,447 messages and is 161.31 Mbytes.  Largest mail message
INBOX/2012_06_30/#msgs/0000cd24.eml is 10.72 Mbytes

And if you wanted even more detail, would this help?

kreport tony
aplawrence.com tony
- - aplawrence.com/tony/Sent Items/#msgs 63 messages 0.99 Mbytes
- - aplawrence.com/tony/Deleted Items/#msgs 22 messages 4.37 Mbytes
- - aplawrence.com/tony/Apl RSS/#msgs 2 messages 0.02 Mbytes
- - aplawrence.com/tony/Apl RSS/#assoc 1 messages 0.00 Mbytes
- - aplawrence.com/tony/Apl RSS 1 messages 0.02 Mbytes
- - aplawrence.com/tony/#deleted/#msgs 1973 messages 73.29 Mbytes
- - aplawrence.com/tony/INBOX/2012_06_30/#msgs 1303 messages 79.04 Mbytes
- - aplawrence.com/tony/INBOX/#msgs 2447 messages 161.31 Mbytes
- - aplawrence.com/tony/INBOX/#assoc 8 messages 0.00 Mbytes
- - aplawrence.com/tony/Junk E-mail/#msgs 1591 messages 41.31 Mbytes
- - aplawrence.com/tony/__keriomapi__STORE/__keriomapi__
STORE_ROOT/IPM_VIEWS/#assoc 1 messages 0.00 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/IPM_VIEWS 1 messages 0.02 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/Freebusy Data/#msgs 1 messages 0.00 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/IPM_COMMON_VIEWS/#assoc 3 messages 0.00 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/IPM_COMMON_VIEWS 3 messages 0.02 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT 3 messages 0.03 Mbytes
- - aplawrence.com/tony/__keriomapi__STORE 3 messages 0.05 Mbytes
- - aplawrence.com/tony/Contacts/#msgs 389 messages 0.09 Mbytes
- - aplawrence.com/tony/Contacts/#assoc 1 messages 0.00 Mbytes
- - aplawrence.com/tony/Contacts 1 messages 1.07 Mbytes
- - aplawrence.com/tony/Tasks/#msgs 1 messages 0.00 Mbytes
- - aplawrence.com/tony/Calendar/#msgs 2 messages 0.00 Mbytes
- - aplawrence.com/tony/Calendar/#assoc 2 messages 0.00 Mbytes
- - aplawrence.com/tony/Calendar 2 messages 0.05 Mbytes
- aplawrence.com/tony 7,810 messages 494.58 Mbytes all told,
360.43 Mbytes in .eml's: Largest directory INBOX/#msgs has
2,447 messages and is 161.31 Mbytes.  Largest mail message
INBOX/2012_06_30/#msgs/0000cd24.eml is 10.72 Mbytes
 

You can get that with this simple Perl script. As usual, it's something I dashed off quickly earlier today and could certainly use some improvement, but I think you will find it useful. You'll need to adjust the STORE directory for your environment, but other than that I expect it will run on any platform where you have Perl.


#!/usr/bin/perl
use File::Basename;
$STORE="/opt/kerio/mailserver/store/mail";
my $totsize;
$detail=shift @ARGV;
chdir("$STORE") or die "Fix Kerio store/mail $STORE $!";
foreach(<*>) {
  $domain=$_;
  print "\n$domain $detail\n";
  foreach(<$domain/*>) {
     $totsize=0;
     $count=0;
     $emlsize=0;
     $user=$_;
     next if ($detail and $user !~ /$detail/);
     dodir($user);
      $file{$user}=~ s/$user\///;
      $namelargesteml{$user}=~ s/$user\///;
     next if  (not $count and not $totsize);
     printf "- $user %s messages %0.2f Mbytes all
       told, %0.2f Mbytes in .eml's", commify($count),
       ($totsize/1024/1024),($emlsize/1024/1024);
     printf ": Largest directory %s has %s messages and
       is %0.2f Mbytes.  Largest mail message %s is %0.2f
       Mbytes\n", $file{$user},commify($count{$user}),
       ($largest{$user}/1024/1024),
       $namelargesteml{$user},($largesteml{$user}/1024/1024);
  }
}

# cribbed from http://www.perlmonks.org/?node_id=51836
# modded just a bit for our use here
sub dodir {
opendir(DIR,$_[0]);
my $dir = $_[0];
if ($dir !~ /\/$/) { $dir .= "/"; }
my @List=readdir(DIR); 
closedir(DIR);
splice(@List,0,2);
foreach $file (@List) {
next if ($file eq "." or $file eq "..");
my $file = $dir.$file;
if (-d $file) { 
  $subtotsize=0; 
  $subcount=0;
  dodir($file);
  if ($subtotsize > $largest{$user} ){
    $file{$user}=$file;
    $largest{$user}=$subtotsize ;
    $count{$user}=$subcount;
  }
  printf "- - $file $subcount messages %0.2f Mbytes\n",
     ($subtotsize/1024/1024) if ($detail and $subcount and $subtotsize);
}
else { 
  $size=(-s $file);
  $totsize += $size;
  $subtotsize += $size;
  if ($file =~ /.eml$/) {
    $count++;
    $subcount++;
    $emlsize += $size;
    if ($size > $largesteml{$user}) {
    $largesteml{$user}=$size;
    $namelargesteml{$user}=$file
    }
   }
 }
 }
}

sub commify {
    my $text = reverse $_[0];
    $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
    return scalar reverse $text
}
 

That's it - have fun and let me know about any bugs or errors.


Kerio®, and related trademarks, names and logos are the property of Kerio Technologies, Inc. and are registered and/or used in the U.S. and other countries. Used under license from Kerio Technologies, Inc.


If this page was useful to you, please help others find it:  





1 comment




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments





Wed Jul 25 20:39:34 2012: 11218   TonyLawrence

gravatar


This counts Contacts and Calendar items as well as some Outlook related items; you could easily modify the script to skip those if you wish.

For example, you might add under

foreach $file (@List) {
next if $file =~ /keriomapi/;
next if $file =~ /Contacts/;
next if $file =~ /Calendar/;

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


cartoon
Kerio Connect Recovery

Kerio Connect Mailserver

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - Kerio Connect
       - Kerio
       - Kerio Info
       - Kerio Pricing
       - Kerio RSS Feed
       - Mail
       - Perl


















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals