Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the capability to control the timezone used to display rrd metric graphs #245

Merged
merged 12 commits into from
Sep 9, 2014
Merged
Binary file removed css/smoothness/images/animated-overlay.gif
Binary file not shown.
Binary file modified css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_glass_75_dadada_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions css/smoothness/jquery-ui-1.10.2.custom.min.css

This file was deleted.

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions css/smoothness/jquery-ui.min.css

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions events.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,24 @@ function refreshOverlayEvent() {
center: '',
right: 'today prev next basicDay basicWeek month'},
eventRender: function(event, element) {
var fmt = "HH:mm:ss";

if ('end_time' in event) {
var startDate = new Date(event.start_time * 1000);
var endDate = new Date(event.end_time * 1000);
if (startDate.getFullYear() != endDate.getFullYear()) {
fmt = "MM/dd/yyyy " + fmt;
} else {
if ((startDate.getDate() != endDate.getDate()) ||
(startDate.getMonth() != endDate.getMonth()))
fmt = "MM/dd " + fmt;
}
}

var tipText = event.title +
'<br>Start: ' + $.fullCalendar.formatDate(new Date(event.start_time * 1000), "HH:mm:ss");
'<br>Start: ' + $.fullCalendar.formatDate(new Date(event.start_time * 1000), fmt);
if ('end_time' in event)
tipText += '<br>End: ' + $.fullCalendar.formatDate(new Date(event.end_time * 1000), "HH:mm:ss");
tipText += '<br>End: ' + $.fullCalendar.formatDate(new Date(event.end_time * 1000), fmt);

element.qtip({
content : {
Expand Down Expand Up @@ -155,7 +169,7 @@ function eventActions(action) {
alert("You must specify a regular expression describing the host(s) to which this event should be associated.");
return false;
}
queryString += "&host_regex=" + host_regex;
queryString += "&host_regex=" + encodeURIComponent(host_regex);

/*
alert('api/events.php' +
Expand All @@ -166,7 +180,7 @@ function eventActions(action) {
$("#event-message").html('<img src="img/spinner.gif">');
$.get('api/events.php',
"action=" + action +
"&summary=" + summary + queryString, function(data) {
"&summary=" + encodeURIComponent(summary) + queryString, function(data) {
$("#event-message").html(data);
});
}
Expand Down
10 changes: 10 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,4 +1398,14 @@ function my_passthru($command) {
unlink($tf);
}

// Get timestamp of textual date/time specified relative to gweb timezone
function tzTimeToTimestamp($tzTime) {
if (isset($_SESSION['tz']) && ($_SESSION['tz'] != '')) {
$dtz = new DateTimeZone($_SESSION['tz']);
$dt = new DateTime($tzTime, $dtz);
return $dt->getTimestamp();
} else {
return strtotime($tzTime); // server timezone
}
}
?>
25 changes: 13 additions & 12 deletions graph.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
// vim: tabstop=2:softtabstop=2:shiftwidth=2:expandtab

session_start();

include_once "./eval_conf.php";
include_once "./get_context.php";
include_once "./functions.php";
Expand Down Expand Up @@ -501,11 +503,11 @@ function build_graphite_url($rrd_graphite_link,
}
}

if ($cs)
$start = date("H:i_Ymd", strtotime($cs));
if ($cs)
$start = date("H:i_Ymd", tzTimeToTimestamp($cs));

if ($ce)
$end = date("H:i_Ymd", strtotime($ce));
$end = date("H:i_Ymd", tzTimeToTimestamp($ce));

if ($max == 0)
$max = "";
Expand Down Expand Up @@ -539,12 +541,7 @@ function get_timestamp($time) {
} else if (is_numeric($time)) {
$timestamp = $time;
} else {
$t = strtotime($time);
if ($t !== FALSE)
$timestamp = $t;
else
error_log("get_timestamp: ".
"Unable to convert time ${time} to Unix timestamp");
$timestamp = tzTimeToTimestamp($time);
}
return $timestamp;
}
Expand Down Expand Up @@ -753,7 +750,7 @@ function rrdgraph_cmd_add_overlay_events($command,
// We need a dummpy DEF statement, because RRDtool is too stupid
// to plot graphs without a DEF statement.
// We can't count on a static name, so we have to "find" one.
if (preg_match("/DEF:['\"]?(\w+)['\"]?=/", $command, $matches)) {
if (preg_match("/DEF:['\"]?([-\w]+)['\"]?=/", $command, $matches)) {
// stupid rrdtool limitation.
$area_cdef =
" CDEF:area_$counter=$matches[1],POP," .
Expand All @@ -764,7 +761,7 @@ function rrdgraph_cmd_add_overlay_events($command,
$area .= ':"' . $summary . '"';
$command .= "$area_cdef $area $start_vrule $end_vrule";
} else {
error_log("No DEF statements found in \$command?!");
error_log("No DEF statements found in $command?!");
}
} else {
$command .= " VRULE:" . $evt_start . "#" . $color .
Expand Down Expand Up @@ -938,7 +935,11 @@ function rrdgraph_cmd_build($rrdtool_graph,
" last $range";
}

$command =
$command = '';
if (isset($_SESSION['tz']) && ($_SESSION['tz'] != ''))
$command .= "TZ='" . $_SESSION['tz'] . "' ";

$command .=
$conf['rrdtool'] .
" graph" .
(isset($_GET["verbose"]) ? 'v' : '') .
Expand Down
4 changes: 2 additions & 2 deletions graph_all_periods.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<title>Ganglia: Graph all periods</title>
<link rel="stylesheet" href="./styles.css" type="text/css" />
<script TYPE="text/javascript" SRC="js/jquery-1.9.1.min.js"></script>
<script TYPE="text/javascript" SRC="js/jquery-1.11.1.min.js"></script>
<script>$.uiBackCompat = false;</script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.livesearch.min.js"></script>
Expand All @@ -14,7 +14,7 @@
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/jquery.ba-bbq.min.js"></script>
<link type="text/css" href="css/smoothness/jquery-ui-1.10.2.custom.min.css" rel="stylesheet" />
<link type="text/css" href="css/smoothness/jquery-ui.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/jquery.multiselect.css" type="text/css" />
<?php
} // if (!isset($_REQUEST['embed']) && !isset($_REQUEST['mobile'])) {
Expand Down
109 changes: 70 additions & 39 deletions header.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
session_start();

if (isset($_GET['tz'])) {
$_SESSION['tz'] = $_GET['tz'];
}

if (isset($_GET['date_only'])) {
$d = date("r");
echo $d;
Expand Down Expand Up @@ -103,6 +107,30 @@ function make_range_menu($physical, $jobrange, $cs, $ce, $range) {
return $range_menu;
}

function make_custom_time_selector($cs, $ce) {
$examples = "Feb 27 2007 00:00, 2/27/2007, 27.2.2007, now -1 week,"
. " -2 days, start + 1 hour, etc.";

$custom_time = "or <span class=\"nobr\">from <input type=\"TEXT\" title=\"$examples\" NAME=\"cs\" ID=\"datepicker-cs\" SIZE=\"17\"";
if ($cs)
$custom_time .= " value=\"$cs\"";
$custom_time .= "> to <input type=\"TEXT\" title=\"$examples\" name=\"ce\" ID=\"datepicker-ce\" SIZE=\"17\"";
if ($ce)
$custom_time .= " value=\"$ce\"";
$custom_time .= "> <input type=\"submit\" value=\"Go\">\n";
$custom_time .= "<input type=\"button\" value=\"Clear\" onclick=\"ganglia_submit(1)\"></span>\n";
return $custom_time;
}

function make_timezone_picker() {
$picker = "Timezone:&nbsp;";
$picker .= '<select id="timezone-picker" style="width:100px;">';
$picker .= '<option value="browser">Browser</option>';
$picker .= '<option value="server">Server</option>';
$picker .= '</select>';
return $picker;
}

function make_alt_view($context, $clustername, $hostname, $get_metric_string) {
global $conf;

Expand Down Expand Up @@ -286,13 +314,17 @@ function make_node_menu($self,
$tpl = new Dwoo_Template_File( template("$header.tpl") );
$data = new Dwoo_Data();

if (isset($_GET["hide-hf"]) && filter_input(INPUT_GET, "hide-hf", FILTER_VALIDATE_BOOLEAN, array("flags" => FILTER_NULL_ON_FAILURE))) {
if (isset($_GET["hide-hf"]) &&
filter_input(INPUT_GET,
"hide-hf",
FILTER_VALIDATE_BOOLEAN,
array("flags" => FILTER_NULL_ON_FAILURE))) {
$data->assign("hide_header", true);
}

// Server offset used in generating pretty dates and times when zooming
$data->assign("server_utc_offset", date('Z'));
//
// Server timezone used in generating pretty dates and times when zooming
$data->assign("server_timezone", date_default_timezone_get());

$data->assign("page_title", $title);
$data->assign("refresh", $conf['default_refresh']);

Expand All @@ -314,33 +346,34 @@ function make_node_menu($self,

$get_metric_string = "m={$user['metricname']}&amp;r=$range&amp;s=$sort_url&amp;hc=${conf['hostcols']}&amp;mc=${conf['metriccols']}";
if ($jobrange and $jobstart)
$get_metric_string .= "&amp;jr=$jobrange&amp;js=$jobstart";
$get_metric_string .= "&amp;jr=$jobrange&amp;js=$jobstart";
if ($cs)
$get_metric_string .= "&amp;cs=" . rawurlencode($cs);
$get_metric_string .= "&amp;cs=" . rawurlencode($cs);
if ($ce)
$get_metric_string .= "&amp;ce=" . rawurlencode($ce);
$get_metric_string .= "&amp;ce=" . rawurlencode($ce);

// Timestamps are used for graph zoom calculations
$start_timestamp = null;
$end_timestamp = null;
if ($cs) {
if (! is_numeric($cs)) {
$start_timestamp = strtotime($cs);
} else {
$start_timestamp = $cs;
}
if (! is_numeric($cs)) {
$start_timestamp = tzTimeToTimestamp($cs);
} else {
$start_timestamp = $cs;
}

if ($ce) {
if (! is_numeric($ce)) {
$end_timestamp = strtotime($ce);
} else {
$end_timestamp = $ce;
}
if ($ce) {
if (! is_numeric($ce)) {
$end_timestamp = tzTimeToTimestamp($ce);
} else {
$end_timestamp = $start_timestamp - $conf['time_ranges'][$range];
$end_timestamp = $ce;
}
} else {
$end_timestamp = $start_timestamp - $conf['time_ranges'][$range];
}
} else {
$end_timestamp = time();
$start_timestamp = $end_timestamp - $conf['time_ranges'][$range];
$end_timestamp = time();
$start_timestamp = $end_timestamp - $conf['time_ranges'][$range];
}

$data->assign("start_timestamp", $start_timestamp);
Expand Down Expand Up @@ -398,34 +431,32 @@ function make_node_menu($self,
}

$custom_time = "";

$timezone_picker = "";
if (in_array($context, array ("meta",
"cluster",
"cluster-summary",
"host",
"views",
"decompose_graph",
"compare_hosts"))) {
$examples = "Feb 27 2007 00:00, 2/27/2007, 27.2.2007, now -1 week,"
. " -2 days, start + 1 hour, etc.";
$custom_time = "or <span class=\"nobr\">from <input type=\"TEXT\" title=\"$examples\" NAME=\"cs\" ID=\"datepicker-cs\" SIZE=\"17\"";
if ($cs)
$custom_time .= " value=\"$cs\"";
$custom_time .= "> to <input type=\"TEXT\" title=\"$examples\" name=\"ce\" ID=\"datepicker-ce\" SIZE=\"17\"";
if ($ce)
$custom_time .= " value=\"$ce\"";
$custom_time .= "> <input type=\"submit\" value=\"Go\">\n";
$custom_time .= "<input type=\"button\" value=\"Clear\" onclick=\"ganglia_submit(1)\"></span>\n";
# $custom_time .= $calendar;
$data->assign("custom_time", $custom_time);

# $tpl->assign("custom_time_head", $calendar_head);
$data->assign("custom_time_head", "");
$custom_time = make_custom_time_selector($cs, $ce);
$timezone_picker = make_timezone_picker();

#$tpl->assign("custom_time_head", $calendar_head);
$data->assign("custom_time_head", "");
} else {
$data->assign("custom_time_head", "");
$data->assign("custom_time_head", "");
}

$data->assign("custom_time", $custom_time);
$data->assign("timezone_picker", $timezone_picker);

if (isset($_SESSION['tz']) && ($_SESSION['tz'] != '')) {
$data->assign("timezone_option", "browser");
$data->assign("timezone_value", $_SESSION['tz']);
} else {
$data->assign("timezone_option", "server");
$data->assign("timezone_value", "");
}

if($conf['auth_system'] == 'enabled') {
$data->assign('auth_system_enabled', true);
Expand Down
20 changes: 0 additions & 20 deletions js/ganglia.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ $(function(){
search_field_q.val(search_value);
}

var datepicker_cs = $( "#datepicker-cs" );
if (datepicker_cs[0])
datepicker_cs.datetimepicker({
showOn: "button",
constrainInput: false,
buttonImage: "img/calendar.gif",
buttonImageOnly: true,
hideNowButton: true
});

$( "#datepicker-cs").datetimepicker();
var datepicker_ce = $( "#datepicker-ce" );
if (datepicker_ce[0])
datepicker_ce.datetimepicker({
showOn: "button",
constrainInput: false,
buttonImage: "img/calendar.gif",
buttonImageOnly: true,
hideNowButton: true
});
});

function selectTab(tab_index) {
Expand Down
Loading