Ejemplo n.º 1
0
 }
 foreach ($customer["graphs"] as $graph_key => $graph) {
     $graph_items = "";
     if (isset($graph["graph_item_id"])) {
         foreach ($graph["graph_item_id"] as $graph_item) {
             debug("    Graph: " . $graph["id"] . " Item: " . $graph_item);
         }
         $graph_items = join(",", $graph["graph_item_id"]);
     } else {
         debug("    Graph: " . $graph["id"] . " Items: ALL");
     }
     /* Process graph */
     if ($process_billing) {
         $graph_values = process_graph($graph["id"], $graph_items, $customer_time["start"], $customer_time["end"]);
     } elseif ($process_threshold) {
         $graph_values = process_graph($graph["id"], $graph_items, $customer_time["threshold_start"], $customer_time["threshold_end"]);
     } else {
         $graph_values = array();
     }
     if (sizeof($graph_values) > 0 && is_array($graph_values)) {
         if ($debug) {
             /* just to show progress */
             foreach ($graph_values as $field => $field_data) {
                 debug("      Item: " . $field . " Value: " . $field_data["value_text"]);
             }
         }
         /* add customer graph values to processing matrix */
         $config_customers[$customer_key]["graphs"][$graph_key]["values"] = $graph_values;
         /* Graph title needs to be in graph */
         $graph_title_key = array_keys($graph_values);
         $config_customers[$customer_key]["graphs"][$graph_key]["graph_title"] = $graph_values[$graph_title_key[0]]["graph_title"];
Ejemplo n.º 2
0
function process_graph_threshold($customer_key, $graph_id, $graph_item_ids, $start_time, $end_time, $current_time, $threshold_value = 0)
{
    global $config_track;
    global $config_customers;
    global $config_globals;
    global $rrd_fetch_cache;
    $output = array();
    $interval = 600;
    /* 10 minute resolution, reduce caching needs by 50% */
    /* current time should not exceed the end time - we will process beyond the billing range */
    if ($current_time > $end_time) {
        $current_time = $end_time;
    }
    /* get graph items id for processing */
    $where = "";
    if (!empty($graph_item_ids)) {
        $where .= " AND i.id IN(" . $graph_item_ids . ")";
    }
    $where .= " AND g.local_graph_id = " . $graph_id;
    $graph_items = db_fetch_assoc("SELECT \n\t\t\ti.id AS item_id, \n\t\t\ti.local_graph_id, \n\t\t\ti.task_item_id, \n\t\t\ti.text_format, \n\t\t\tg.id AS graph_id, \n\t\t\tg.title_cache,\n\t\t\td.local_data_id,\n\t\t\td.data_source_name\n\t\tFROM \n\t\t\tgraph_templates_graph AS g,\n\t\t\tgraph_templates_item AS i LEFT JOIN data_template_rrd as d ON i.task_item_id = d.id \n\t\tWHERE \n\t\t\ti.local_graph_id = g.local_graph_id AND \n\t\t\ti.local_graph_id <> 0 AND \n\t\t\ti.graph_type_id = 1 AND \n\t\t\ttext_format LIKE '%|%:%:%|%'\n\t\t\t" . $where . "\n\t\tORDER BY\n\t\t\ti.local_graph_id;");
    /* Process times based on interval for each graph item */
    $customer_description = $config_customers[$customer_key]["description"];
    /* Cycle through graph items */
    foreach ($graph_items as $graph_item) {
        /* Record the graph item type we are dealing with */
        $graph_type = "";
        $match = array();
        if (preg_match('/\\|sum\\:([0-9]+|auto)\\:(current|total)\\:([0-9]+)\\:([0-9]+|auto)\\|/', $graph_item["text_format"], $match) > 0) {
            $graph_type = "Sum";
            $graph_description = "Bandwidth Summation";
        } elseif (preg_match('/\\|([0-9]{1,2})\\:(\\S+)\\:([0-9]+)\\:(\\S+)\\:([0-9]+)\\|/', $graph_item["text_format"], $match) > 0) {
            $graph_type = "Nth";
            $graph_description = get_pretty_nth_value($match[1]);
        }
        /* Time loop - Can be slow and uses lots of memory */
        for ($i = $start_time + $interval; $i <= $current_time; $i = $i + $interval) {
            /* check for cached values */
            if (!isset($config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i])) {
                /* fetch data sets from graph for specific graph item id */
                $rrd_fetch_cache = array();
                /* No need to cache, we are changing end time which make cache grow exponentially */
                $graph_data = process_graph($graph_id, $graph_item["item_id"], $start_time, $i);
                /* update cache */
                $config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i] = $graph_data[$graph_item["item_id"]]["value_bits"];
            }
            /* Process threshold time stamp search in cache */
            debug("        Processing cache (" . $graph_item["item_id"] . "): " . $i . "        ", 0);
            if ($config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i] >= $threshold_value) {
                if ($graph_type == "Sum") {
                    $output[$graph_item["item_id"]]["value"] = $config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i];
                    $output[$graph_item["item_id"]]["start"] = $start_time;
                    $output[$graph_item["item_id"]]["end"] = $i;
                    /* No need to continue, we found what we need, let's not waste cpu and memory */
                    break;
                }
                if ($graph_type == "Nth") {
                    if (!isset($output[$graph_item["item_id"]]["threshold"])) {
                        $output[$graph_item["item_id"]]["value"] = $config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i];
                        $output[$graph_item["item_id"]]["start"] = $start_time;
                        $output[$graph_item["item_id"]]["end"] = $i;
                    }
                }
            } else {
                /* as we progress through time, if we do not exceed the threshold, clear previous stored thresholds */
                if ($graph_type == "Nth") {
                    $output[$graph_item["item_id"]] = array();
                }
            }
        }
        /* Pass the type of graph item we have */
        if (isset($output[$graph_item["item_id"]]["value"])) {
            $output[$graph_item["item_id"]]["type"] = $graph_type;
            $output[$graph_item["item_id"]]["description"] = $graph_description;
        }
        debug("        Processing cache (" . $graph_item["item_id"] . "): done                        ");
        if (isset($config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i])) {
            debug("          Threshold Calculation (" . $graph_type . "): " . $config_track[$customer_description][$graph_id][$graph_item["item_id"]][$start_time][$i] . " >= " . $threshold_value);
        }
    }
    /* Return output array */
    return $output;
}