IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28843


Ignore:
Timestamp:
Aug 5, 2010, 9:08:08 AM (16 years ago)
Author:
rhenders
Message:

Added cluster storage tables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czartool/CzarDb.pm

    r28830 r28843  
    152152    }
    153153}
     154
     155###########################################################################
     156#
     157# Updates hosts table
     158#
     159###########################################################################
     160sub updateHost {
     161    my ($self, $host, $total, $available, $used) = @_;
     162
     163    my $query = $self->{_db}->prepare(<<SQL);
     164    DELETE FROM hosts WHERE host LIKE '$host';
     165SQL
     166
     167    $query->execute;
     168    $query = $self->{_db}->prepare(<<SQL);
     169    INSERT INTO hosts
     170        (host, total, available, used)
     171        VALUES
     172        ('$host', $total, $available, $used);
     173SQL
     174    $query->execute;
     175
     176}
     177
     178###########################################################################
     179#
     180# Inserts new cluster space info
     181#
     182###########################################################################
     183sub insertNewClusterSpace {
     184    my ($self, $total, $available, $used, $hostsOver98) = @_;
     185
     186    my $query = $self->{_db}->prepare(<<SQL);
     187    INSERT INTO cluster_space
     188        (total, available, used, hostsOver98)
     189        VALUES
     190        ( $total, $available, $used, $hostsOver98);
     191SQL
     192
     193        $query->execute;
     194}
     195
    154196###########################################################################
    155197#
     
    193235SQL
    194236
    195 
    196 
    197237    if (!$query->execute) {return undef;}
    198238
     
    308348###########################################################################
    309349#
     350# Gets host data and stores it to temp file
     351#
     352###########################################################################
     353sub createHostsData {
     354    my ($self) = @_;
     355
     356    my $dataFile = "/tmp/czarplot_hosts.dat";
     357    open (GNUDAT, ">$dataFile");
     358
     359    my $query = $self->{_db}->prepare(<<SQL);
     360    SELECT
     361        host, used, available
     362        FROM hosts
     363        ORDER BY host;
     364SQL
     365
     366    $query->execute;
     367
     368    # loop round results
     369    while (my @row = $query->fetchrow_array()) {
     370
     371        my ($host, $used, $available) = @row;
     372        print GNUDAT "$host $used $available\n";
     373    }
     374    close(GNUDAT);
     375
     376    return $dataFile;
     377}
     378
     379###########################################################################
     380#
     381# Gets time series data for cluster storage and saves it to file
     382#
     383###########################################################################
     384sub createStorageTimeSeriesData {
     385    my ($self, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff) = @_;
     386
     387    my $dataFile = "/tmp/czarplot_gnuplot_storage_timeseries.dat";
     388    open (GNUDAT, ">$dataFile");
     389
     390    my $query = $self->{_db}->prepare(<<SQL);
     391    SELECT
     392        MAX(available), MIN(available), 
     393        DATE_FORMAT(MAX(timestamp),'$self->{_dateFormat}'),
     394        DATE_FORMAT(MIN(timestamp),'$self->{_dateFormat}'),
     395        TIME_TO_SEC(TIMEDIFF(max(timestamp ), min(timestamp)))
     396            FROM cluster_space
     397            WHERE timestamp >= '$fromTime' AND timestamp <= '$toTime';
     398SQL
     399
     400
     401    if (!$query->execute) {return undef;}
     402
     403    (${$maxY}, ${$minY}, ${$maxX}, ${$minX}, ${$timeDiff}) = $query->fetchrow_array();
     404
     405
     406    $query = $self->{_db}->prepare(<<SQL);
     407    SELECT
     408        DATE_FORMAT(timestamp, '$self->{_dateFormat}'), available
     409        FROM cluster_space
     410        WHERE timestamp >= '$fromTime' AND timestamp <= '$toTime'
     411        ORDER BY timestamp;
     412SQL
     413
     414    $query->execute;
     415
     416    # loop round results
     417    while (my @row = $query->fetchrow_array()) {
     418
     419        my ($timestamp, $available) = @row;
     420        print GNUDAT "$timestamp $available\n";
     421    }
     422    close(GNUDAT);
     423
     424    return $dataFile;
     425}
     426###########################################################################
     427#
    310428# Determines how much has been processed in the provided interval of time
    311429# (format: 1 HOUR, 1 MINUTE 1 DAY etc)
     
    336454
    337455    my $currentRevision = -1;
    338     my $latestRevision = 8;
     456    my $latestRevision = 9;
    339457
    340458    while ($currentRevision != $latestRevision) {
     
    351469        elsif ($currentRevision == 6) {$self->createRevision_7();}
    352470        elsif ($currentRevision == 7) {$self->createRevision_8();}
     471        elsif ($currentRevision == 8) {$self->createRevision_9();}
    353472    }
    354473}
     
    581700#######################################################################################
    582701#
     702# Create revision 9 of the database
     703#
     704#######################################################################################
     705sub createRevision_9 {
     706    my ($self) = @_;
     707
     708    print "* Creating revision 9 of '$self->{_dbName}'\n";
     709
     710    my $query = $self->{_db}->prepare(<<SQL);
     711    CREATE TABLE cluster_space (
     712            timestamp TIMESTAMP DEFAULT NOW(),
     713            total FLOAT,
     714            available FLOAT,
     715            used FLOAT,
     716            hostsOver98 SMALLINT);
     717SQL
     718
     719      $query->execute;
     720    $query = $self->{_db}->prepare(<<SQL);
     721    CREATE TABLE hosts (
     722            host VARCHAR(128),
     723            total FLOAT,
     724            available FLOAT,
     725            used FLOAT);
     726SQL
     727
     728      $query->execute;
     729
     730        $query = $self->{_db}->prepare(<<SQL);
     731        CREATE INDEX clusterSpaceIndex ON cluster_space (timestamp);
     732SQL
     733
     734      $query->execute;
     735
     736    $self->setRevision(9);
     737}
     738
     739#######################################################################################
     740#
    583741# Sets current revision of ippToPsps database
    584742#
Note: See TracChangeset for help on using the changeset viewer.