Index: branches/czw_branch/20101203/tools/czarpoll.pl
===================================================================
--- branches/czw_branch/20101203/tools/czarpoll.pl	(revision 29907)
+++ branches/czw_branch/20101203/tools/czarpoll.pl	(revision 30118)
@@ -14,5 +14,5 @@
 use czartool::Burntool;
 use czartool::DayMetrics;
-
+use czartool::MetricsIndex;
 
 my $period = 60;
@@ -29,5 +29,5 @@
 my $nebulous = new czartool::Nebulous($czarDb);
 my $pantasks = new czartool::Pantasks();
-my $plotter = new czartool::Plotter($gpc1Db, $czarDb, "%Y%m%d-%H%M%S", "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8", "/tmp", $save_temps); # TODO hardcoded font path
+my $plotter = czartool::Plotter->new_file($gpc1Db, $czarDb, "/tmp", $save_temps); 
 my $burntool = new czartool::Burntool();
 
@@ -108,40 +108,51 @@
     my $newState = undef;
     my $nsStatus = undef;
-    my $lastDay = strftime('%Y-%m-%d', localtime);
     my $today = undef;
-    my $doneMetricsToday = 1;
-
+    my $yesterday = undef;
+    my $newDayTime = "18:00";
+    my $lastDayDailyTasks = "2010-01-01";
+
+    # main polling loop
     while (1) {
 
-        # check whether day has changed. if so, cleanup tables from previous day and optimize
+        # sort out times
         $today = strftime('%Y-%m-%d', localtime);
-        if ($czarDb->isBefore($lastDay, $today)) {
-        
+        $yesterday = $czarDb->subtractInterval($today, "1 DAY");
+        $end = $czarDb->getNowTimestamp();
+
+        # if before 18:00 today, then start plots from 18:00 yesterday
+        if ($czarDb->isBefore($end, "$today $newDayTime")) {$begin = "$yesterday $newDayTime";}
+        # if after 18:00 today, then perform some daily tasks and start plots from 18:00 today
+        else {
+            
+            $begin = "$today $newDayTime";
+
+            # check whether yesterday was cleaned. if not, cleanup tables and optimize
+            if ($lastDayDailyTasks ne $yesterday) {
+   
+                print "* performing daily tasks (clean-up, metrics)";
+
+                # create metrics for last 24 hours
+                print "* Creating metrics for last 24 hours\n";
+                # TODO hardcoded path needs to be in config
+                my $dayMetrics = new czartool::DayMetrics($gpc1Db, 
+                        $czarDb, 
+                        "/data/ipp004.0/ipp/ippMetrics/", 
+                        1, 0, $today); 
+                $dayMetrics->writeHTML();
+
+                # now update metrics index page
+                my $metricsIndex = new czartool::MetricsIndex($gpc1Db, 
+                        $czarDb, 
+                        "/data/ipp004.0/ipp/ippMetrics/", 
+                        1, 0); 
+                $metricsIndex->writeHTML();
+
+                # now cleanup tables from yesterday and optimize
                 print "* New day - performing cleanup\n";
-                $czarDb->cleanupDateRange($lastDay, $lastDay, "30 MINUTE");
+                $czarDb->cleanupDateRange($yesterday, $yesterday, "30 MINUTE");
                 $czarDb->optimize();
-                $lastDay = $today;
-                $doneMetricsToday = 0;
-        }
-
-        # sort out times
-        $begin = strftime('%Y-%m-%d 06:35', localtime);
-        $end = $czarDb->getNowTimestamp();
-
-        # if time now is after 06:35am, then create metrics for past 24 hours
-        if (!$doneMetricsToday && $czarDb->isBefore($begin, $end)) {
-        
-                print "* Creating metrics for last 24 hours\n";
-                my $yesterday = $czarDb->subtractInterval($today, "1 DAY");
-                # TODO hardcoded path needs to be in config
-                my $dayMetrics = new czartool::DayMetrics($gpc1Db, $czarDb, "/data/ipp004.0/ipp/ippMetrics/", 1, 0, $yesterday); 
-                $dayMetrics->writeHTML();
-                $doneMetricsToday = 1;
-        }
-
-        # if time now is before 06:35am, include data from previous day
-        if ($czarDb->isBefore($end, $begin)) {
-
-            $begin = $czarDb->subtractInterval($begin, "1 DAY");
+                $lastDayDailyTasks = $yesterday;
+            }
         }
 
@@ -237,5 +248,5 @@
 
         $plotter->createLogAndLinearTimeSeries($allServerLabels,  $stage, $begin, $end); # TODO must be a neater way...
-        $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
+            $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
     }
 }
@@ -261,5 +272,5 @@
     my $server = undef;
     my $state = undef;
-    
+
     foreach $stage (@stages) {
 
