]>
Commit | Line | Data |
---|---|---|
a88f8afe GS |
1 | --- cacti/lib/functions.php 2007/11/16 03:33:22 4350 |
2 | +++ cacti/lib/functions.php 2007/11/19 02:21:59 4351 | |
3 | @@ -1077,27 +1077,19 @@ | |
4 | @returns - the best cf to use */ | |
5 | function generate_graph_best_cf($local_data_id, $requested_cf) { | |
6 | if ($local_data_id > 0) { | |
7 | - $avail_cf_functions = db_fetch_assoc("SELECT DISTINCT | |
8 | - rra_cf.consolidation_function_id AS rra_cf | |
9 | - FROM (data_template_data | |
10 | - INNER JOIN data_template_data_rra ON data_template_data.id=data_template_data_rra.data_template_data_id) | |
11 | - INNER JOIN (rra INNER JOIN rra_cf ON rra.id=rra_cf.rra_id) ON data_template_data_rra.rra_id=rra.id | |
12 | - WHERE data_template_data.local_data_id=$local_data_id | |
13 | - ORDER BY rra_cf ASC"); | |
14 | + $avail_cf_functions = get_rrd_cfs($local_data_id); | |
15 | ||
16 | /* workaround until we hae RRA presets in 0.8.8 */ | |
17 | - if ($requested_cf != 4) { | |
18 | - if (sizeof($avail_cf_functions)) { | |
19 | - /* check through the cf's and get the best */ | |
20 | - foreach($avail_cf_functions as $cf) { | |
21 | - if ($cf["rra_cf"] == $requested_cf) { | |
22 | - return $requested_cf; | |
23 | - } | |
24 | + if (sizeof($avail_cf_functions)) { | |
25 | + /* check through the cf's and get the best */ | |
26 | + foreach($avail_cf_functions as $cf) { | |
27 | + if ($cf["rra_cf"] == $requested_cf) { | |
28 | + return $requested_cf; | |
29 | } | |
30 | - | |
31 | - /* if none was found, take the first */ | |
32 | - return $avail_cf_functions[0]["rra_cf"]; | |
33 | } | |
34 | + | |
35 | + /* if none was found, take the first */ | |
36 | + return $avail_cf_functions[0]["rra_cf"]; | |
37 | } | |
38 | } | |
39 | ||
40 | @@ -1105,6 +1097,66 @@ | |
41 | return "1"; | |
42 | } | |
43 | ||
44 | +/* get_rrd_cfs - reads the RRDfile and get's the RRA's stored in it. | |
45 | + @arg $local_data_id | |
46 | + @returns - array of the CF functions */ | |
47 | +function get_rrd_cfs($local_data_id) { | |
48 | + global $rrd_cfs; | |
49 | + | |
50 | + $rrdfile = get_data_source_path($local_data_id, TRUE); | |
51 | + | |
52 | + if (!isset($rrd_cfs)) { | |
53 | + $rrd_cfs = array(); | |
54 | + }else if (array_key_exists($local_data_id, $rrd_cfs)) { | |
55 | + return $rrd_cfs[$local_data_id]; | |
56 | + } | |
57 | + | |
58 | + $cfs = array(); | |
59 | + | |
60 | + $output = rrdtool_execute("info $rrdfile", FALSE, RRDTOOL_OUTPUT_STDOUT); | |
61 | + | |
62 | + if (strlen($output)) { | |
63 | + $output = explode("\n", $output); | |
64 | + | |
65 | + if (sizeof($output)) { | |
66 | + foreach($output as $line) { | |
67 | + if (substr_count($line, ".cf")) { | |
68 | + $values = explode("=",$line); | |
69 | + | |
70 | + if (!in_array(trim($values[1]), $cfs)) { | |
71 | + $cfs[] = trim($values[1]); | |
72 | + } | |
73 | + } | |
74 | + } | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + $new_cfs = array(); | |
79 | + | |
80 | + if (sizeof($cfs)) { | |
81 | + foreach($cfs as $cf) { | |
82 | + switch($cf) { | |
83 | + case "AVG": | |
84 | + $new_cfs[] = 1; | |
85 | + break; | |
86 | + case "MIN": | |
87 | + $new_cfs[] = 2; | |
88 | + break; | |
89 | + case "MAX": | |
90 | + $new_cfs[] = 3; | |
91 | + break; | |
92 | + case "LAST": | |
93 | + $new_cfs[] = 3; | |
94 | + break; | |
95 | + } | |
96 | + } | |
97 | + } | |
98 | + | |
99 | + $rrd_cfs[$local_data_id] = $new_cfs; | |
100 | + | |
101 | + return $new_cfs; | |
102 | +} | |
103 | + | |
104 | /* generate_graph_def_name - takes a number and turns each digit into its letter-based | |
105 | counterpart for RRDTool DEF names (ex 1 -> a, 2 -> b, etc) | |
106 | @arg $graph_item_id - (int) the ID to generate a letter-based representation of |