So, my use of LMT.pm is rudimentary. With it I can query the DB from <start> to <end> where those are two time stamps. Be sure to look at the place in LMT.pm where the MySQL connection is established, it may need some configuring before you can use it.
First, you need a connection and your Perl script needs to know about the LMT.pm module:
use lib '/usr/share/lmt/lib/perl';
use LMT;
# details about creating a Perl "object" elided
$self->{lmt} = LMT->new();
# You may want to parse /usr/share/lmt/etc/lmtrc to get the filesystem name
$self->{lmt}->connect($self->{filesystem});
If I query the OST_DATA table (which is the only one I really mess with), then I get a set of rows from the table. It is useful to know beforehand what the OST names are so:
my $ost_query = "SELECT * FROM OST_INFO";
my $ost_sth = $self->{lmt}->execQuery($ost_query);
$self->{num_osts} = 0;
while( my $ost_ref = $ost_sth->fetchrow_hashref() )
{
my $ost_name = $ost_ref->{"OST_NAME"};
$self->{num_osts}++;
...
}
Now you can get the actual data. $start and $end are LMT "TIMESTAMP" values, which are recorded as text in the format, eg. "2011-02-14 08:00:00":
my $query = $self->{lmt}->generateGetDataWindowQuery(
"OST_DATA", $start, $end,
("TS_ID", "TIMESTAMP", "OST_ID", "READ_BYTES", "WRITE_BYTES", "PCT_CPU", "KBYTES_FREE", "KBYTES_USED", "INODES_FREE", "INODES_USED"));
my $query_result = $self->{lmt}->execQuery($query);
while( my $row = $query_result->fetchrow_hashref() )
{
# the row data is a hash, this is just to exhibit it
$row_hash = {
ost_id => $row->{"OST_ID"},
timestamp => $row->{"TIMESTAMP"},
ts_id => $row->{"TS_ID"},
read_bytes => $row->{"READ_BYTES"},
write_bytes => $row->{"WRITE_BYTES"},
pct_cpu => $row->{"PCT_CPU"},
kbytes_free => $row->{"KBYTES_FREE"},
kbytes_used => $row->{"KBYTES_USED"},
inodes_free => $row->{"INODES_FREE"},
inodes_used => $row->{"INODES_USED"}
};
# Now go do something useful with the data
}
For a given OST_ID and TIMESTAMP you will have two counters: READ_BYTES and WRITE_BYTES. Since they are counters they are always increasing. You can calculate a data rate for the OST_ID by taking the difference in the counter from one TIMESTAMP to the next. You can sum up those differences across all OST_IDs and get an aggregate data rate for the entire file system for that interval. Keep in mind that the counters are reset at the time a server is rebooted, otherwise the difference should never be negative. Also keep in mind that the values are sent to the DB via UDP, which means there can be data loss. You may have incomplete data for some interval, and how you handle that will affect what your differential and aggregate values look like. Have fun!
Cheers,
Andrew