$endDateEp) {
echo "" .
"End date must be after begin date.
";
} elseif ($beginDateEp < $firstDP || $endDateEp > $lastDP) {
echo "" .
"Date range must be between " .
date('m / d / Y', $firstDP) . " and " .
date('m / d / Y', $lastDP) . ".
";
} else {
# Generate charts from validated user supplied dates.
if (_DEBUG) {
echo "Date range: " . $beginDateEp . " thru " .
$endDateEp . "
";
}
createChart('custom_current', 'CUR', 'Amps',
'Current', $beginDateEp, $endDateEp,
0, 0, 2, false);
createChart('custom_voltage', 'VOLT', 'Volts',
'Voltage', $beginDateEp, $endDateEp,
0, 0, 2, false);
createChart('custom_power', 'PWR', 'Watts',
'Power', $beginDateEp, $endDateEp,
0, 0, 2, false);
createChart('custom_battemp', 'BTMP', 'deg\ F',
'Battery\ Temperature', $beginDateEp, $endDateEp,
0, 0, 2, false);
createChart('custom_ambtemp', 'ATMP', 'deg\ F',
'Ambient\ Temperature', $beginDateEp, $endDateEp,
0, 0, 2, false);
# Send html commands to client browser.
echo "" .
"
" .
"
";
echo "" .
"
" .
"
";
echo "" .
"
" .
"
";
echo "" .
"
" .
"
";
echo "" .
"
" .
"
";
}
function createChart($chartFile, $dataItem, $label, $title, $begin,
$end, $lower, $upper, $addTrend, $autoScale) {
/*
Uses rrdtool to create a chart of specified aredn node data item.
Parameters:
fileName - name of the created chart file
dataItem - data item to be charted
label - string containing a label for the item to be charted
title - string containing a title for the chart
begin - beginning time of the chart data
end - ending time of the data to be charted
lower - lower bound for chart ordinate #NOT USED
upper - upper bound for chart ordinate #NOT USED
addTrend - 0, show only chart data
1, show only a trend line
2, show a trend line and the chart data
autoScale - if True, then use vertical axis auto scaling
(lower and upper parameters are ignored), otherwise use
lower and upper parameters to set vertical axis scale
Returns: True if successful, False otherwise
*/
# Define path on server to chart files.
$chartPath = _CHART_DIRECTORY . $chartFile . ".png";
# Format the rrdtool chart command.
# Set chart file name, start time, end time, height, and width.
$cmdfmt = "rrdtool graph %s -a PNG -s %s -e %s -w %s -h %s ";
$cmd = sprintf($cmdfmt, $chartPath, $begin, $end, _CHART_WIDTH,
_CHART_HEIGHT);
$cmdfmt = "-l %s -u %s -r ";
# Set upper and lower ordinate bounds.
if ($lower < $upper) {
$cmd .= sprintf($cmdfmt, $lower, $upper);
} elseif ($autoScale) {
$cmd .= "-A ";
}
$cmd .= "-Y ";
# Set the chart ordinate label and chart title.
$cmdfmt = "-v %s -t %s ";
$cmd .= sprintf($cmdfmt, $label, $title);
# Define moving average window width.
$trendWindow = floor(($end - $begin) / 12);
# Show the data, or a moving average trend line over
# the data, or both.
$cmdfmt = "DEF:dSeries=%s:%s:LAST ";
$cmd .= sprintf($cmdfmt, _RRD_FILE, $dataItem);
if ($addTrend == 0) {
$cmd .= "LINE1:dSeries#0400ff ";
} elseif ($addTrend == 1) {
$cmdfmt = "CDEF:smoothed=dSeries,%s,TREND LINE3:smoothed#006600 ";
$cmd .= sprintf($cmdfmt, $trendWindow);
} elseif ($addTrend == 2) {
$cmd .= "LINE1:dSeries#0400ff ";
$cmdfmt = "CDEF:smoothed=dSeries,%s,TREND LINE3:smoothed#006600 ";
$cmd .= sprintf($cmdfmt, $trendWindow);
}
# Execute the formatted rrdtool command in the shell. The rrdtool
# command will complete execution before the html image tags get
# sent to the browser. This assures that the charts are available
# when the client browser executes the html code that loads the
# charts into the document displayed by the client browser.
if (_DEBUG) {
echo "chart command:
" . $cmd . "
";
}
$result = shell_exec($cmd . " 2>&1");
if (_DEBUG) {
echo "result:
" . $result . "
";
}
}
?>