eval 'exec /home/jsoc/bin/$JSOC_MACHINE/perl -d -S $0 "$@"' if 0; use DBI; use Term::ReadKey; #$DB = "jsoc_sums"; $PGPORT=5434; sub usage { print "Get info of /SUMs partitions by group_id\n"; print "Usage: look.pl sums_db\n"; exit(1); } sub commify { local $_ = shift; 1 while s/^([-+]?\d+)(\d{3})/$1,$2/; return $_; } if($#ARGV != 0) { &usage; } $DB = $ARGV[0]; $user = "jim"; $hostdb = "hmidb"; #host where Postgres runs @df = `/bin/df /SUM*`; $f = shift(@df); #skip title line #$total = 0; while( $f = shift(@df)) { ($a, $b, $c, $avail, $used, $mnt) = split(/\s+/, $f); chomp($mnt); if($mnt) { #print "$mnt\n"; push(@mnt, $mnt); } #$total += $avail; } #First connect to database $dbh = DBI->connect("dbi:Pg:dbname=$DB;host=$hostdb;port=$PGPORT", "$user", ""); if ( !defined $dbh ) { die "Cannot do \$dbh->connect: $DBI::errstr\n"; } print "Connected to Postgres OK\n"; while($mnt = shift(@mnt)) { $sqlcmd = "select distinct(group_id) from sum_partn_alloc where wd like '$mnt/%' order by group_id"; print "SQL: $sqlcmd\n"; $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $row = $sth->fetchrow(); #if($row == 0) { push(@row, $row); } push(@row, $row); #allow for group = 0 while($row = $sth->fetchrow()) { push(@row, $row); #print "row: $row\n"; } $total = 0; $gcnt = $#row+1; for($i=0; $i < $gcnt; $i++) { $grp = shift(@row); print "$grp\n"; $sql = "select sum(bytes) from sum_partn_alloc where group_id=$grp and wd like '$mnt/%'"; print "$sql\n"; $sth = $dbh->prepare($sql); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $bytes = $sth->fetchrow(); $tby = $bytes/1099511627776; print "Group $grp: $tby\n"; $total += $tby; } $tx = commify(int($total)); print "total TB $mnt = $tx\n"; } if(defined $sth) { $sth->finish; } $dbh->disconnect();