Skip to content

Commit

Permalink
Initial support for timeshift overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
vuksanv committed May 16, 2012
1 parent 63ebfd6 commit 07f7f00
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ function build_graphite_series( $config, $host_cluster = "" ) {
$summary = isset($_GET["su"]) ? 1 : 0;
$debug = isset($_GET['debug']) ? clean_number(sanitize($_GET["debug"])) : 0;
$showEvents = isset($_GET["event"]) ? sanitize ($_GET["event"]) : "show";
$user['time_shift'] = isset($_GET['ts']) ? 1 : NULL;

$command = '';
$graphite_url = '';
Expand Down Expand Up @@ -1125,14 +1126,40 @@ function build_graphite_series( $config, $host_cluster = "" ) {
} //End check for array
}

////////////////////////////////////////////////////////////////////////////////
// Add a trend line
////////////////////////////////////////////////////////////////////////////////
if ( $user['trend_line'] ) {

$command .= " VDEF:D2=sum,LSLSLOPE VDEF:H2=sum,LSLINT CDEF:avg2=sum,POP,D2,COUNT,*,H2,+";
$command .= " 'LINE3:avg2#53E2FF:Trend:dashes'";

}

////////////////////////////////////////////////////////////////////////////////
// Add a trend line
////////////////////////////////////////////////////////////////////////////////
if ( $user['time_shift'] ) {

preg_match_all("/(DEF|CDEF):(.*)(:AVERAGE )/",
" " . $rrdtool_graph['series'],
$matches);

$start = intval(abs(str_replace("s", "", $rrdtool_graph['start'])));
$offset = 2 * $start;

$def = str_replace("DEF:'sum'", "DEF:'sum2'", trim($matches[0][0])) . ":start=end-" . $offset;



$command .= " " . $def . " SHIFT:sum2:" . $start;
$command .= " 'LINE3:sum2#FFE466:Previous:dashes'";

}

////////////////////////////////////////////////////////////////////////////////
// Add warning and critical lines
////////////////////////////////////////////////////////////////////////////////
if ( $warning ) {
$command .= " 'HRULE:" . $warning . "#FFF600:Warning:dashes'";
}
Expand Down

0 comments on commit 07f7f00

Please sign in to comment.