コード例 #1
0
 public function testNumberFormatting()
 {
     $this->assertEquals("1", WMUtility::formatNumberWithMetricPrefix(1));
     $this->assertEquals("300", WMUtility::formatNumberWithMetricPrefix(300));
     $this->assertEquals("1K", WMUtility::formatNumberWithMetricPrefix(1000));
     $this->assertEquals("10K", WMUtility::formatNumberWithMetricPrefix(10000));
     $this->assertEquals("500K", WMUtility::formatNumberWithMetricPrefix(500000));
     $this->assertEquals("5M", WMUtility::formatNumberWithMetricPrefix(5000000));
     $this->assertEquals("500M", WMUtility::formatNumberWithMetricPrefix(500000000));
     $this->assertEquals("5G", WMUtility::formatNumberWithMetricPrefix(5000000000));
     $this->assertEquals("500G", WMUtility::formatNumberWithMetricPrefix(500000000000));
     $this->assertEquals("50T", WMUtility::formatNumberWithMetricPrefix(50000000000000));
     $this->assertEquals("1.5K", WMUtility::formatNumberWithMetricPrefix(1500));
     // multiple levels of precision
     $this->assertEquals("1.6K", WMUtility::formatNumberWithMetricPrefix(1625));
     $this->assertEquals("1.63K", WMUtility::formatNumberWithMetricPrefix(1625, 1000, 2));
     // base-2 vs base-10
     $this->assertEquals("2K", WMUtility::formatNumberWithMetricPrefix(2048, 1024, 2));
     $this->assertEquals("2.05K", WMUtility::formatNumberWithMetricPrefix(2048, 1000, 2));
     // fractional formatting...
     $this->assertEquals("1m", WMUtility::formatNumberWithMetricPrefix(0.001, 1000, 2));
     $this->assertEquals("1u", WMUtility::formatNumberWithMetricPrefix(1.0E-6, 1000, 2));
     $this->assertEquals("1n", WMUtility::formatNumberWithMetricPrefix(1.0E-9, 1000, 2));
     // negatives
     $this->assertEquals("-2K", WMUtility::formatNumberWithMetricPrefix(-2048, 1024, 2));
     $this->assertEquals("-2", WMUtility::formatNumber(-2));
 }
コード例 #2
0
 public function getConfig()
 {
     assert(isset($this->owner));
     // TODO - These should all check against the defaults
     $output = "# All settings for scale " . $this->name . "\n";
     if (1 == 0) {
         if (null === $this->keypos) {
             $output .= sprintf("\tKEYPOS %s %s %s\n", $this->name, "-1 -1", $this->keytitle);
         } else {
             $output .= sprintf("\tKEYPOS %s %s %s\n", $this->name, $this->keypos->asConfig(), $this->keytitle);
         }
         // TODO - need to add size if non-standard
         $output .= sprintf("\tKEYSTYLE %s %s\n", $this->name, $this->keystyle);
         $output .= sprintf("\tKEYBGCOLOR %s %s\n", $this->name, $this->keybgcolour->asConfig());
         $output .= sprintf("\tKEYTEXTCOLOR %s %s\n", $this->name, $this->keytextcolour->asConfig());
         $output .= sprintf("\tKEYOUTLINECOLOR %s %s\n", $this->name, $this->keyoutlinecolour->asConfig());
         $output .= sprintf("\tSCALEMISSCOLOR %s %s\n", $this->name, $this->scalemisscolour->asConfig());
     }
     $locale = localeconv();
     $decimal_point = $locale['decimal_point'];
     $output .= "\n";
     foreach ($this->colours as $scaleEntry) {
         $top = rtrim(rtrim(sprintf("%f", $scaleEntry['top']), "0"), $decimal_point);
         $bottom = rtrim(rtrim(sprintf("%f", $scaleEntry['bottom']), "0"), $decimal_point);
         if ($bottom > $this->owner->kilo) {
             $bottom = WMUtility::formatNumberWithMetricPrefix($scaleEntry['bottom'], $this->owner->kilo);
         }
         if ($top > $this->owner->kilo) {
             $top = WMUtility::formatNumberWithMetricPrefix($scaleEntry['top'], $this->owner->kilo);
         }
         $tag = isset($scaleEntry['tag']) ? $scaleEntry['tag'] : '';
         // Non-real colour, c1==c2 and c2==null all mean a single SCALE colour
         if (!$scaleEntry['c1']->isRealColour() || null === $scaleEntry['c2'] || $scaleEntry['c1']->equals($scaleEntry['c2'])) {
             $output .= sprintf("\tSCALE %s %-4s %-4s  %s  %s\n", $this->name, $bottom, $top, $scaleEntry['c1']->asConfig(), $tag);
         } else {
             $output .= sprintf("\tSCALE %s %-4s %-4s  %s  %s  %s\n", $this->name, $bottom, $top, $scaleEntry['c1']->asConfig(), $scaleEntry['c2']->asConfig(), $tag);
         }
     }
     $output .= "\n";
     return $output;
 }
コード例 #3
0
function weathermap_run_maps($mydir, $map_id = -1)
{
    global $weathermap_debugging;
    global $WEATHERMAP_VERSION;
    global $weathermap_warncount;
    global $weathermap_poller_start_time;
    global $weathermap_error_suppress;
    global $weathermap_mem_highwater;
    $weathermap_mem_highwater = 0;
    // This one makes Cacti's database.php puke...
    // WMMemoryNote('weathermap_initial_memory');
    require_once "all.php";
    // and this..
    // WMMemoryNote('weathermap_loaded_memory');
    $total_warnings = 0;
    $warning_notes = "";
    $start_time = microtime(true);
    if ($weathermap_poller_start_time == 0) {
        $weathermap_poller_start_time = $start_time;
    }
    $outputDirectory = realpath($mydir . DIRECTORY_SEPARATOR . 'output');
    $configDirectory = realpath($mydir . DIRECTORY_SEPARATOR . 'configs');
    $mapCount = 0;
    // take our debugging cue from the poller - turn on Poller debugging to get weathermap debugging
    if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
        $weathermap_debugging = true;
        $mode_message = "DEBUG mode is on";
        $global_debug = true;
    } else {
        $mode_message = "Normal logging mode. Turn on DEBUG in Cacti for more information";
        $global_debug = false;
    }
    $quietLogging = intval(WMCactiAPI::getConfigOption("weathermap_quiet_logging"), 0);
    // moved this outside the module_checks, so there should always be something in the logs!
    if ($quietLogging == 0) {
        cacti_log("Weathermap {$WEATHERMAP_VERSION} starting - {$mode_message}\n", true, "WEATHERMAP");
    }
    if (!wm_module_checks()) {
        wm_warn("Required modules for PHP Weathermap {$WEATHERMAP_VERSION} were not present. Not running. [WMPOLL08]\n");
        return;
    }
    weathermap_memory_check("MEM Initial");
    // move to the weathermap folder so all those relatives paths don't *have* to be absolute
    $orig_cwd = getcwd();
    chdir($mydir);
    WMCactiAPI::setConfigOption("weathermap_last_start_time", $start_time);
    // first, see if the output directory exists and is writable
    if (weathermap_directory_writeable($outputDirectory)) {
        $mapList = weathermap_get_runlist($map_id, $quietLogging);
        wm_debug("Iterating all maps.");
        $imageFormat = strtolower(WMCactiAPI::getConfigOption("weathermap_output_format", "png"));
        $rrdtool_path = read_config_option("path_rrdtool");
        foreach ($mapList as $mapParameters) {
            $weathermap_warncount = 0;
            weathermap_run_map($mapParameters, $configDirectory, $outputDirectory, $imageFormat, $quietLogging, $global_debug, $mapCount, $rrdtool_path, $weathermap_error_suppress, $weathermap_poller_start_time, $total_warnings);
            $total_warnings += $weathermap_warncount;
            $mapCount++;
        }
        wm_debug("Iterated all {$mapCount} maps.\n");
    } else {
        wm_warn("Output directory ({$outputDirectory}) doesn't exist!. No maps created. You probably need to create that directory, and make it writable by the poller process (like you did with the RRA directory) [WMPOLL07]\n");
        $total_warnings++;
        $warning_notes .= " (Output directory problem prevents any maps running WMPOLL07)";
    }
    weathermap_memory_check("MEM Final");
    chdir($orig_cwd);
    $end_time = microtime(true);
    $duration = $end_time - $start_time;
    $stats_string = sprintf('%s: %d maps were run in %.2f seconds with %d warnings', date(DATE_RFC822), $mapCount, $duration, $total_warnings);
    if (true === function_exists("memory_get_peak_usage")) {
        $peak_memory = memory_get_peak_usage();
        WMCactiAPI::setConfigOption("weathermap_peak_memory", WMUtility::formatNumberWithMetricPrefix($peak_memory));
        $stats_string .= sprintf(" using %sbytes peak memory", $peak_memory);
    }
    if ($quietLogging == 0) {
        wm_warn("STATS: Weathermap {$WEATHERMAP_VERSION} run complete - {$stats_string}\n", true);
    }
    WMCactiAPI::setConfigOption("weathermap_last_stats", $stats_string);
    WMCactiAPI::setConfigOption("weathermap_last_finish_time", $end_time);
    WMCactiAPI::setConfigOption("weathermap_last_map_count", $mapCount);
    if (true === function_exists('memory_get_usage')) {
        WMCactiAPI::setConfigOption("weathermap_final_memory", memory_get_usage());
        WMCactiAPI::setConfigOption("weathermap_highwater_memory", $weathermap_mem_highwater);
    }
    if (true === function_exists("memory_get_peak_usage")) {
        WMCactiAPI::setConfigOption("weathermap_peak_memory", memory_get_peak_usage());
    }
}
コード例 #4
0
                         $map->links[$name]->overliburl[OUT][] = $overlib;
                         $map->links[$name]->infourl[IN] = $infourl;
                         $map->links[$name]->infourl[OUT] = $infourl;
                     } else {
                         print " Couldn't find a graph that uses this rrd??\n";
                     }
                 } else {
                     print "  Failed to find RRD file for {$tgt_host}/{$interface}\n";
                 }
             }
             print "    SPEED {$total_speed}\n";
             if ($total_speed > 0) {
                 $map->links[$name]->max_bandwidth_in = $total_speed;
                 $map->links[$name]->max_bandwidth_out = $total_speed;
                 $map->links[$name]->max_bandwidth_in_cfg = WMUtility::formatNumberWithMetricPrefix($total_speed);
                 $map->links[$name]->max_bandwidth_out_cfg = WMUtility::formatNumberWithMetricPrefix($total_speed);
                 if ($map_widths) {
                     foreach ($width_map as $map_speed => $map_width) {
                         if ($total_speed <= $map_speed) {
                             $map->links[$name]->width = $width_map[$map_speed];
                             print "    WIDTH " . $width_map[$map_speed] . "\n";
                             continue 2;
                         }
                     }
                 }
             }
         }
     } else {
         print "Skipping link with targets\n";
     }
 }