feature: Added ability to output graphs as svg (#5959)

* feature: Added ability to output graphs as svg

* Update graph.inc.php

* added ability to gzip various files for web servers
This commit is contained in:
Neil Lathwood
2017-02-22 12:08:18 +00:00
committed by Tony Murray
parent 1c9cbc42f5
commit a8691680ab
10 changed files with 48 additions and 12 deletions

View File

@ -99,6 +99,8 @@ server {
index index.php;
access_log /opt/librenms/logs/access_log;
error_log /opt/librenms/logs/error_log;
gzip on;
gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files $uri $uri/ @librenms;
}

View File

@ -123,6 +123,8 @@ server {
index index.php;
access_log /opt/librenms/logs/access_log;
error_log /opt/librenms/logs/error_log;
gzip on;
gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files $uri $uri/ @librenms;
}

View File

@ -79,6 +79,8 @@ server {
index index.php;
access_log /opt/librenms/logs/access_log;
error_log /opt/librenms/logs/error_log;
gzip on;
gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files $uri $uri/ @librenms;
}

View File

@ -3,6 +3,9 @@
Options FollowSymlinks Multiviews
AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f

View File

@ -72,7 +72,7 @@ function get_graph_by_port_hostname()
$vars['height'] = $_GET['height'] ?: 300;
$auth = '1';
$vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`$port`=? AND `deleted` = 0 LIMIT 1", array($hostname, $vars['port']));
$app->response->headers->set('Content-Type', 'image/png');
$app->response->headers->set(set_image_type());
rrdtool_initialize(false);
include 'includes/graphs/graph.inc.php';
rrdtool_close();
@ -149,7 +149,7 @@ function get_graph_generic_by_hostname()
$vars['height'] = $_GET['height'] ?: 300;
$auth = '1';
$vars['device'] = dbFetchCell('SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?', array($hostname));
$app->response->headers->set('Content-Type', 'image/png');
$app->response->headers->set(set_image_type());
rrdtool_initialize(false);
include 'includes/graphs/graph.inc.php';
rrdtool_close();
@ -514,7 +514,7 @@ function get_graph_by_portgroup()
unset($seperator);
$vars['type'] = 'multiport_bits_separate';
$vars['id'] = $if_list;
$app->response->headers->set('Content-Type', 'image/png');
$app->response->headers->set(set_image_type());
rrdtool_initialize(false);
include 'includes/graphs/graph.inc.php';
rrdtool_close();

View File

@ -1419,3 +1419,17 @@ function eventlog_severity($eventlog_severity)
break;
}
} // end eventlog_severity
/**
*
*/
function set_image_type()
{
global $config;
if ($config['webui']['graph_type'] === 'svg') {
return header('Content-type: image/svg+xml');
} else {
return header('Content-type: image/png');
}
}

View File

@ -9,7 +9,7 @@ if ($_GET['to']) {
}
if ($_GET['width']) {
$width = mres($_GET['width']);
$width = mres($vars['width']);
}
if ($config['trim_tobias']) {
@ -17,7 +17,7 @@ if ($config['trim_tobias']) {
}
if ($_GET['height']) {
$height = mres($_GET['height']);
$height = mres($vars['height']);
}
if ($_GET['inverse']) {

View File

@ -31,7 +31,7 @@ $period = ($to - $from);
$prev_from = ($from - $period);
$graphfile = $config['temp_dir'].'/'.strgen().'.png';
$graphfile = $config['temp_dir'].'/'.strgen();
$type = $graphtype['type'];
$subtype = $graphtype['subtype'];
@ -102,6 +102,10 @@ if ($error_msg) {
}
} else {
// $rrd_options .= " HRULE:0#999999";
if ($config['webui']['graph_type'] === 'svg') {
$rrd_options .= " --imgformat=SVG -m 0.75";
}
if ($no_file) {
if ($width < 200) {
graph_error('No RRD');
@ -125,8 +129,8 @@ if ($error_msg) {
if (is_file($graphfile)) {
if (!$debug) {
header('Content-type: image/png');
if ($config['trim_tobias']) {
set_image_type();
if ($config['trim_tobias'] && $config['webui']['graph_type'] !== 'svg') {
list($w, $h, $type, $attr) = getimagesize($graphfile);
$src_im = imagecreatefrompng($graphfile);
$src_x = '0';
@ -156,7 +160,7 @@ if ($error_msg) {
}
} else {
echo `ls -l $graphfile`;
echo '<img src="'.data_uri($graphfile, 'image/png').'" alt="graph" />';
echo '<img src="'.data_uri($graphfile, 'image/svg+xml').'" alt="graph" />';
}
unlink($graphfile);
} else {

View File

@ -16,6 +16,14 @@ $graph_conf = array(
'descr' => 'Set the minimum graph height',
'type' => 'text',
),
array('name' => 'webui.graph_type',
'descr' => 'Set the graph type',
'type' => 'select',
'options' => array(
'png' => 'png',
'svg' => 'svg',
),
),
);
$availability_map_conf = array(

1
sql-schema/166.sql Normal file
View File

@ -0,0 +1 @@
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('webui.graph_type','png','png','Set the default graph type','webui',0,'graph',0,'0','0');