コード例 #1
0
   function displayGraph($rrdtool_template, $itemtype, $items_id, $timezone, $time='1d', $part='', $width='900') {
      global $CFG_GLPI;

      $pmComponent = new PluginMonitoringComponent();
//      if (isset($_GET['itemtype'])) {
//         $itemtype = $_GET['itemtype'];
//         $items_id = $_GET['items_id'];
//      }
      $item = new $itemtype();
      if ($item->getFromDB($items_id)) {
         $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
         $ident = $items_id.$time;

         if ($part == ''
                 OR $part == 'div') {
            echo '<div id="chart'.$ident.'">'.
                '<svg style="width: '.$width.'px;display: block;"></svg>'.
              '</div>';

            echo "<div id=\"updategraph".$items_id.$time."\"></div>";
         }
         if ($part == ''
                 OR $part == 'js') {
            if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
               PluginMonitoringToolbox::loadPreferences($pmComponent->fields['id']);
            }
            if (! isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
               $format = '%H:%M';
            } else {
               if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']][''])) {
                  unset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]['']);
               }
               $pmServicegraph = new PluginMonitoringServicegraph();
               $a_ret = $pmServicegraph->generateData($rrdtool_template,
                                            $itemtype,
                                            $items_id,
                                            $timezone,
                                            $time,
                                            '',
                                            $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]);
               $format = $a_ret[2];
            }
            echo "<script>";
            $formaty = ".0f";
            echo '

            var data'.$ident.' = [];
            var chart'.$ident.';
            redraw'.$ident.' = function () {
               nv.addGraph(function() {
                  chart'.$ident.' = nv.models.lineChart();

                  chart'.$ident.'.useInteractiveGuideline(true);

                  chart'.$ident.'.xAxis
                     .tickFormat(function(d) { return d3.time.format("'.$format.'")(new Date(d)); });

                  chart'.$ident.'.yAxis
                     .axisLabel("test")
                     .tickFormat(d3.format(\''.$formaty.'\'));

                  chart'.$ident.'.forceY([0]);

                  d3.select("#chart'.$ident.' svg")
                    .attr("height", 300)
                    .datum(data'.$ident.')
                    .transition().duration(50)
                    .call(chart'.$ident.');



                 return chart'.$ident.';
               });
            };';

            echo "
            (function worker".$items_id.$time."() {
              startDate = new Date($('#custom_date').val());
              startTime = Date.parse('04/03/1980 ' + ($('#custom_time').val()) + ':00');
              $.getJSON('".$CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/updateChart.php"
                    ."?rrdtool_template=".$rrdtool_template."&itemtype=".$itemtype.
                          "&items_id=".$items_id.
                          "&timezone=".$timezone.
                          "&time=".$time."&customdate=' + (startDate.getTime()/1000.0) + '".
                          "&customtime=' + (startTime/1000.0) + '".
                          "&components_id=".$pmComponent->fields['id']."', function(data) {
                data".$ident." = data;

                redraw".$ident."();
                setTimeout(worker".$items_id.$time.", 30000);
              });
            })();";
            echo "
            </script>";
         }

                 }
      return;
   }
コード例 #2
0
            $enddate = mktime(date('H', $_GET['customtime']), date('i', $_GET['customtime']), date('s', $_GET['customtime']), date('n', $_GET['customdate']), date('d', $_GET['customdate']), date('Y', $_GET['customdate']));
        }
    }
}
if (isset($_GET['components_id']) && !isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']])) {
    PluginMonitoringToolbox::loadPreferences($_GET['components_id']);
}
if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']])) {
    echo json_encode(array());
    //   echo __('No data ...', 'monitoring');
    exit;
}
if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']][''])) {
    unset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']]['']);
}
$a_ret = $pmServicegraph->generateData($_GET['rrdtool_template'], $_GET['itemtype'], $_GET['items_id'], $_GET['timezone'], $_GET['time'], $enddate, $_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']]);
$mydatat = $a_ret[0];
$a_labels = $a_ret[1];
$pmComponent = new PluginMonitoringComponent();
$pmCommand = new PluginMonitoringCommand();
$pmComponent->getFromDB($_GET['components_id']);
$pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']);
$a_data = array();
$a_values = array();
$lab = '';
$num = 1;
$a_names = array();
$formaty = ".0f";
$max = 0;
foreach ($mydatat as $name => $data) {
    if (!isset($a_names[$name])) {
コード例 #3
0
    function displayGraph($rrdtool_template, $itemtype, $items_id, $timezone, $time = '1d', $part = '', $width = '900')
    {
        global $CFG_GLPI;
        $pmComponent = new PluginMonitoringComponent();
        //      if (isset($_GET['itemtype'])) {
        //         $itemtype = $_GET['itemtype'];
        //         $items_id = $_GET['items_id'];
        //      }
        $item = new $itemtype();
        if ($item->getFromDB($items_id)) {
            $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
            $ident = $items_id . $time;
            if ($part == '' or $part == 'div') {
                echo '<div id="chart' . $ident . '">' . '<svg style="width: ' . $width . 'px;display: block;height: 300px;"></svg>' . '</div>';
                echo "<div id=\"updategraph" . $items_id . $time . "\"></div>";
            }
            if ($part == '' or $part == 'js') {
                if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
                    PluginMonitoringToolbox::loadPreferences($pmComponent->fields['id']);
                }
                if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
                    $format = '%H:%M';
                } else {
                    if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']][''])) {
                        unset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]['']);
                    }
                    $pmServicegraph = new PluginMonitoringServicegraph();
                    $a_ret = $pmServicegraph->generateData($rrdtool_template, $itemtype, $items_id, $timezone, $time, '', $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]);
                    $format = $a_ret[2];
                }
                echo "<script>";
                echo '

            var formaty = ".0f";
            var data' . $ident . ' = [];
            var chart' . $ident . ';
            redraw' . $ident . ' = function () {
               nv.addGraph(function() {
                  if (typeof data' . $ident . '[0] != "undefined") {
                     formaty = data' . $ident . '[0]["formaty"];
                  }
                  chart' . $ident . ' = nv.models.lineChart();

                  chart' . $ident . '.useInteractiveGuideline(true);

                  chart' . $ident . '.xAxis
                     .tickFormat(function(d) { return d3.time.format("' . $format . '")(new Date(d)); });

                  chart' . $ident . '.yAxis
                     .axisLabel("test")
                     .tickFormat(d3.format(formaty));

                  chart' . $ident . '.forceY([0]);

                  d3.select("#chart' . $ident . ' svg")
                    .attr("height", 300)
                    .datum(data' . $ident . ')
                    .transition().duration(50)
                    .call(chart' . $ident . ');

                 return chart' . $ident . ';
               });
            };';
                echo "\n            (function worker" . $items_id . $time . "() {\n              startDate = new Date(\$('#custom_date').val());\n              startTime = Date.parse('04/03/1980 ' + (\$('#custom_time').val()) + ':00');\n              \$.getJSON('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/updateChart.php" . "?rrdtool_template=" . $rrdtool_template . "&itemtype=" . $itemtype . "&items_id=" . $items_id . "&timezone=" . $timezone . "&time=" . $time . "&customdate=' + (startDate.getTime()/1000.0) + '" . "&customtime=' + (startTime/1000.0) + '" . "&components_id=" . $pmComponent->fields['id'] . "', function(data) {\n                data" . $ident . " = data;\n\n                var newDate = \$('#custom_date').val() + ' ' + \$('#custom_time').val();\n                var timestamp = new Date(newDate).getTime();\n                if (timestamp > (new Date().getTime() - 3600000)) {\n                    var datenow = new Date();\n                    \$('#custom_time').val(datenow.getHours() + ':' + datenow.getMinutes());\n                    \$('#custom_date').val((datenow.getMonth() + 1) + '/' + datenow.getDate() + '/' + datenow.getFullYear());\n                }\n\n                redraw" . $ident . "();\n                ";
                $refresh = 30;
                // 30 seconds
                if ($time == '12h') {
                    $refresh = 240;
                    // 4 minutes
                } else {
                    if ($time == '1d') {
                        $refresh = 600;
                        // 10 minutes
                    } else {
                        if ($time == '1w') {
                            $refresh = 1800;
                            // 30 minutes
                        }
                    }
                }
                echo "\n                setTimeout(worker" . $items_id . $time . ", " . $refresh . "000);\n              });\n            })();";
                echo "\n            </script>";
            }
        }
        return;
    }
コード例 #4
0
ファイル: updateChart.php プロジェクト: geldarr/hack-space
$enddate = '';
if ($_POST['customdate'] == '' && $_POST['customtime'] == '') {
    $enddate = '';
} else {
    if ($_POST['customdate'] == '') {
        $enddate = mktime(date('H', $_POST['customtime']), date('i', $_POST['customtime']), date('s', $_POST['customtime']));
    } else {
        if ($_POST['customtime'] == '') {
            $enddate = $_POST['customdate'];
        } else {
            // have the 2 defined
            $enddate = mktime(date('H', $_POST['customtime']), date('i', $_POST['customtime']), date('s', $_POST['customtime']), date('n', $_POST['customdate']), date('d', $_POST['customdate']), date('Y', $_POST['customdate']));
        }
    }
}
$a_ret = $pmServicegraph->generateData($_POST['rrdtool_template'], $_POST['itemtype'], $_POST['items_id'], $_POST['timezone'], $_POST['time'], $enddate);
$mydatat = $a_ret[0];
$a_labels = $a_ret[1];
$format = $a_ret[2];
$suffix = '';
if (isset($_POST['suffix'])) {
    $suffix = $_POST['suffix'];
}
if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_POST['components_id']])) {
    PluginMonitoringServicegraph::loadPreferences($_POST['components_id']);
}
//$format = "%H:%M";
//if ($_POST['time'] != "2h"
//   AND $_POST['time'] != "12h"
//   AND $_POST['time'] != "1d") {
//   if (isset($_SESSION['glpi_plugin_monitoring']['dateformat'])) {