Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Sun May 28, 2017 1:27 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Gradient Graphs for Cacti
PostPosted: Thu Jun 18, 2015 8:16 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2580
Location: Kressbronn, Germany
Hi folks,

I've played around a bit with the RRD graphing and implemented a quick gradient support for them. It's based on several other scripts and if someone is cabable of re-writing the "colourBrightness" function to be GPLv2 I would greatly appreciate it. The code changes ALL AREA related graphs dynamically.

Nothing fency and a quick&dirty hack, but maybe someone still likes it :-)

Look here for additional information: http://blog.network-outsourcing.de/2015 ... ti-graphs/

Here are some samples graphs:
Attachment:
graph_image_localhost_gradient_1.png
graph_image_localhost_gradient_1.png [ 37.22 KiB | Viewed 9122 times ]

Attachment:
graph_image_localhost_gradient_3.png
graph_image_localhost_gradient_3.png [ 41.5 KiB | Viewed 9118 times ]

Attachment:
graph_image_localhost_gradient_2.png
graph_image_localhost_gradient_2.png [ 35.83 KiB | Viewed 9111 times ]

Attachment:
graph_image_localhost_gradient_4.png
graph_image_localhost_gradient_4.png [ 23.67 KiB | Viewed 9111 times ]

Attachment:
graph_image_localhost_gradient_5.png
graph_image_localhost_gradient_5.png [ 74.32 KiB | Viewed 9110 times ]


Here's the code.
You can change the effect of the gradient by changing the following line accoringly:
$end_color = colourBrightness("#" . $graph_item["hex"],-0.4); // End color is a 40% (0.4) darkened (negative number) version of the original color


File: lib/rrd.php, Line: 1375
Code:
                        if (preg_match("/^AREA$/", $graph_item_types{$graph_item["graph_type_id"]})) {
                                $graph_item_stack_type = $graph_item_types{$graph_item["graph_type_id"]};
                                $graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
//                              $txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . $graph_item_color_code . ":" . cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id]) . " ";
                                $end_color =  colourBrightness("#" . $graph_item["hex"],-0.4); // End color is a 40% (0.4) darkened (negative number) version of the original color
                                $txt_graph_items .= gradient($data_source_name,$graph_item_color_code,$end_color.$graph_item["alpha"],cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id]),20,false,$graph_item["alpha"]);
                                $need_rrd_nl = FALSE;
                        }elseif (preg_match("/^LINE[123]$/", $graph_item_types{$graph_item["graph_type_id"]})) {
                                $graph_item_stack_type = $graph_item_types{$graph_item["graph_type_id"]};
                                $graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
                                $txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . $graph_item_color_code . ":" . cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id]) . " ";

                        }elseif ($graph_item_types{$graph_item["graph_type_id"]} == "STACK") {


at the end of rrd.php
Code:
// from: http://lab.clearpixel.com.au/2008/06/darken-or-lighten-colours-dynamically-using-php/  License: unknown
// The code is based on the CSSColor project of the same person from here: http://www.barelyfitz.com/projects/csscolor/ License: GPLv2
   function colourBrightness($hex, $percent) {
        // Work out if hash given
        $hash = '';
        if (stristr($hex,'#')) {
                $hex = str_replace('#','',$hex);
                $hash = '#';
        }
        /// HEX TO RGB
        $rgb = array(hexdec(substr($hex,0,2)), hexdec(substr($hex,2,2)), hexdec(substr($hex,4,2)));
        //// CALCULATE
        for ($i=0; $i<3; $i++) {
                // See if brighter or darker
                if ($percent > 0) {
                        // Lighter
                        $rgb[$i] = round($rgb[$i] * $percent) + round(255 * (1-$percent));
                } else {
                        // Darker
                        $positivePercent = $percent - ($percent*2);
                        $rgb[$i] = round($rgb[$i] * (1-$positivePercent)); // round($rgb[$i] * (1-$positivePercent));
                }
                // In case rounding up causes us to go to 256
                if ($rgb[$i] > 255) {
                        $rgb[$i] = 255;
                }
        }
        //// RBG to Hex
        $hex = '';
        for($i=0; $i < 3; $i++) {
                // Convert the decimal digit to hex
                $hexDigit = dechex($rgb[$i]);
                // Add a leading zero if necessary
                if(strlen($hexDigit) == 1) {
                $hexDigit = "0" . $hexDigit;
                }
                // Append to the hex string
                $hex .= $hexDigit;
        }
        return $hash.$hex;
}

// from https://github.com/lingej/pnp4nagios/blob/master/share/pnp/application/helpers/rrd.php / License: GPLv2
function gradient($vname=FALSE, $start_color='#0000a0', $end_color='#f0f0f0', $label=FALSE, $steps=20, $lower=FALSE, $alpha='FF'){
        $label = preg_replace("/'/","",$label);
        if($vname === FALSE){
//            throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
        }
        if(preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i',$start_color,$matches)){
            $r1=hexdec($matches[1]);
            $g1=hexdec($matches[2]);
            $b1=hexdec($matches[3]);
        }else{
  //          throw new Kohana_exception("rrd::". __FUNCTION__ . "() Wrong Color Format: '".$start_color."'");
        }
        if(preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i',$end_color,$matches)){
            $r2=hexdec($matches[1]);
            $g2=hexdec($matches[2]);
            $b2=hexdec($matches[3]);
        }else{
//            throw new Kohana_exception("rrd::". __FUNCTION__ . "() Wrong Color Format: '".$end_color."'");
        }
        $diff_r=$r2-$r1;
        $diff_g=$g2-$g1;
        $diff_b=$b2-$b1;
        $spline =  "";
        $spline_vname = "var".substr(sha1(rand()),1,4);
        $vnamet = $vname.substr(sha1(rand()),1,4);
        if(preg_match('/^([0-9]{1,3})%$/', $lower, $matches)){
  //          if($matches[1] > 100)
  //              throw new Kohana_exception("rrd::". __FUNCTION__ . "() Lower gradient start > 100% is not allowed: '".$lower."'");

            $lower   = $matches[1];
            $spline .= sprintf("CDEF:%sminimum=%s,100,/,%d,* ".RRD_NL, $vnamet, $vname, $lower);
        }elseif(preg_match('/^([0-9]+)$/', $lower, $matches)){
            $lower   = $matches[1];
            $spline .= sprintf("CDEF:%sminimum=%s,%d,- ".RRD_NL, $vnamet, $vname, $lower);
        }else{
            $lower   = 0;
            $spline .= sprintf("CDEF:%sminimum=%s,%s,- ".RRD_NL, $vnamet, $vname, $vname);
        }
        for ($i=$steps; $i>0; $i--){
            $spline .=  sprintf("CDEF:%s%d=%s,%sminimum,-,%d,/,%d,*,%sminimum,+ ".RRD_NL,$spline_vname,$i,$vname,$vnamet,$steps,$i,$vnamet);
        }
        // We don't use alpha blending for the area right now
        $alpha = 'ff';
        for ($i=$steps; $i>0; $i--){
            $factor=$i / $steps;
            $r=round($r1 + $diff_r * $factor);
            $g=round($g1 + $diff_g * $factor);
            $b=round($b1 + $diff_b * $factor);
            if (($i==$steps) and ($label!=FALSE) and (strlen($label)>2) ){
                $spline .=  sprintf("AREA:%s%d#%02X%02X%02X%s:\"%s\" ".RRD_NL, $spline_vname,$i,$r,$g,$b,$alpha,$label);
            }else{
                $spline .=  sprintf("AREA:%s%d#%02X%02X%02X%s ".RRD_NL, $spline_vname,$i,$r,$g,$b,$alpha);
            }
        }
        $spline .=  sprintf("AREA:%s%d#%02X%02X%02X%s ".RRD_NL, $spline_vname,$steps,$r2,$g2,$b2,'00',$label);
        return $spline;
    }

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Last edited by phalek on Wed Sep 23, 2015 9:02 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Fri Jun 19, 2015 1:31 am 
Offline
Cacti User

Joined: Mon May 03, 2010 11:48 am
Posts: 71
thanks! this is cool :-)

_________________
_________________
Cacti - 0.8.8c
Poller Type - SPINE 0.8.7i
Server Info - Linux 2.6.31.14 - Opensuse 11
Web Server - Apache/2.2.13 PHP 5.3.3
MySQL - 5.1.49 ;RRDTool - 1.3.7 ;SNMP - 5.4.2.1


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Fri Jun 19, 2015 1:32 am 
Offline
Cacti User

Joined: Mon May 03, 2010 11:48 am
Posts: 71
P.S.:
can you please tell which colours you have set for your WAN interface traffic statistics (upload & download)...

_________________
_________________
Cacti - 0.8.8c
Poller Type - SPINE 0.8.7i
Server Info - Linux 2.6.31.14 - Opensuse 11
Web Server - Apache/2.2.13 PHP 5.3.3
MySQL - 5.1.49 ;RRDTool - 1.3.7 ;SNMP - 5.4.2.1


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Fri Jun 19, 2015 1:34 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2580
Location: Kressbronn, Germany
Thanks.

Look at the attached screenshot for the GraphTemplate Definition:
Attachment:
GraphTemplate_Interfaces.png
GraphTemplate_Interfaces.png [ 40.11 KiB | Viewed 9089 times ]

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Tue Sep 15, 2015 8:56 am 
Offline

Joined: Thu Sep 27, 2012 5:24 am
Posts: 17
sooo pretty :)

cheers, Phalek!


edit:
Now, if only I could remove the " ' " apostrophes from all my graphs, that´d be even better!


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Wed Sep 23, 2015 8:38 am 
Offline

Joined: Tue Jul 09, 2013 5:32 pm
Posts: 16
Hanseat wrote:
sooo pretty :)
edit:
Now, if only I could remove the " ' " apostrophes from all my graphs, that´d be even better!


Yes, where is this coming from? I don't recall it being there prior.

Edit: Reverting the changes removes the apostrophes.


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Wed Sep 23, 2015 8:56 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2580
Location: Kressbronn, Germany
Is that for the title only or for the comments ?

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Wed Sep 23, 2015 9:03 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2580
Location: Kressbronn, Germany
Just fixed it. Right at the first line of the "gradient" function there's a new line removing these chars:

Code:
        $label = preg_replace("/'/","",$label);


I've updated the blog posting and the first post in this thread.

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Wed Sep 23, 2015 1:14 pm 
Offline

Joined: Thu Sep 27, 2012 5:24 am
Posts: 17
Many thanks, will give it a try tomorrow!

edit: and I´ll keep the changes now, thanks a lot!


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Sun Oct 18, 2015 4:56 pm 
Offline

Joined: Fri Dec 07, 2012 11:11 am
Posts: 48
As usual, love your work!

First, is this for 0.8.8b (Which is what still comes out of apt for us Ubuntu lovers)?

Second, is there a chance you could simply upload an entire rrd.php file that has all the proper edits? I'm unclear on what it is I'm supposed to edit at line 1375 myself. Either a full copy of the rrd.php, or maybe just highlight exactly what needs to be actually changed.

Third, keep up the awesome work! Love what you've done with Cereus and Smokeping!

Thanks!

_________________
-------------------------------------

VERSION: Cacti 0.8.8b
POLLER: Spine
DATA SOURCES: 100,000K and Growing (Multiple Servers)
PLUGINS: AUTOM8, THOLD, DISCOVER, WEATHERMAP, BOOST, CLOG, NECTAR, MACTRACK, FLOWVIEW, SPIKEKILL, INTROPAGE, MONITOR


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Sun Oct 18, 2015 4:56 pm 
Offline

Joined: Fri Dec 07, 2012 11:11 am
Posts: 48
As usual, love your work!

First, is this for 0.8.8b (Which is what still comes out of apt for us Ubuntu lovers)?

Second, is there a chance you could simply upload an entire rrd.php file that has all the proper edits? I'm unclear on what it is I'm supposed to edit at line 1375 myself. Either a full copy of the rrd.php, or maybe just highlight exactly what needs to be actually changed.

Third, keep up the awesome work! Love what you've done with Cereus and Smokeping!

Thanks!

_________________
-------------------------------------

VERSION: Cacti 0.8.8b
POLLER: Spine
DATA SOURCES: 100,000K and Growing (Multiple Servers)
PLUGINS: AUTOM8, THOLD, DISCOVER, WEATHERMAP, BOOST, CLOG, NECTAR, MACTRACK, FLOWVIEW, SPIKEKILL, INTROPAGE, MONITOR


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Mon Oct 19, 2015 12:36 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2580
Location: Kressbronn, Germany
Hi Jim,

0.8.8b is what this was built for. Here's a download link for the file: http://blog.network-outsourcing.de/wp-c ... t_088b.zip

I've added the link to the post as well.

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Mon Oct 19, 2015 8:43 am 
Offline

Joined: Fri Dec 07, 2012 11:11 am
Posts: 48
Outstanding! Thank you sir!

_________________
-------------------------------------

VERSION: Cacti 0.8.8b
POLLER: Spine
DATA SOURCES: 100,000K and Growing (Multiple Servers)
PLUGINS: AUTOM8, THOLD, DISCOVER, WEATHERMAP, BOOST, CLOG, NECTAR, MACTRACK, FLOWVIEW, SPIKEKILL, INTROPAGE, MONITOR


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Tue Oct 27, 2015 11:30 am 
Offline

Joined: Fri Dec 07, 2012 11:11 am
Posts: 48
Just have to say, this looks simply amazing. Loving this.

_________________
-------------------------------------

VERSION: Cacti 0.8.8b
POLLER: Spine
DATA SOURCES: 100,000K and Growing (Multiple Servers)
PLUGINS: AUTOM8, THOLD, DISCOVER, WEATHERMAP, BOOST, CLOG, NECTAR, MACTRACK, FLOWVIEW, SPIKEKILL, INTROPAGE, MONITOR


Top
 Profile  
 
 Post subject: Re: Gradient Graphs for Cacti
PostPosted: Sun Dec 06, 2015 5:36 pm 
Offline

Joined: Sun Nov 29, 2015 1:13 pm
Posts: 1
I love gradient, it's a nice contribution. However, it doesn't work well on graphics with transparency effects (when graphs have opacity)
Can you avoid using it on graphics with a preset opacity?

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group