[HOW TO] % of Bandwidth Used

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

[HOW TO] % of Bandwidth Used

Post by pshankland »

Can anyone tell me how I can simply get the % of the total bandwidth of the chosen line? Am getting info off my routers and switches and really want to know the percentage of the line that is being used but at the moment am only getting the bits through.

Any help / guidence would be appreciated.

Thanks.

Pete.
Attachments
CiscoRouter.png
CiscoRouter.png (15.09 KiB) Viewed 26732 times
benhanson
Posts: 43
Joined: Tue Feb 08, 2005 8:59 pm

Not sure if this is the easiest way . . .

Post by benhanson »

but I recently posted how to do this with drive space.

http://forums.cacti.net/about6577.html
User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

Post by pshankland »

Cheers for the post but am still not sure what I need to do to get this % utilisation - sorry.

Pete.
benhanson
Posts: 43
Joined: Tue Feb 08, 2005 8:59 pm

How to explain?

Post by benhanson »

First off, and I'm not saying this to be a snobbish PITA, some Cacti and RRD manual reading really helps to make sense of this. Specifically the RRD manual's section on CDEF's was crucial for me. Sort of a tribute to how well Cacti front-ends RRD, I didn't ever think about RRD until I had to set this up.

So the two XML files in the other post are templates, one graph, one host. If you want the easiest approach, for WinXX hosts, you should be able to just import these and not have to set anything up. The host template is the most inclusive. When I exported the templates, I had it include required elements, so the CDEF should be included in either one.

One thing that would be a great help in understanding Cacti is a flow chart. Graph templates are just that: Templates for creating graphs from Datasources. Data Templates are templates for creating RRD datasources. Host Templates are a combination of Data Queries and Graph templates, and Data Queries subsequently are assosiated to Graph Templates. I'm sure I've got this wrong, and you can see how confusing it might be for an initiate like myself. For me, once you get to level of Data Queries and Data Inputs, it's all magic.

The manual way: Create a CDEF called byPercentage or whatever you want. CDEFS are under the Graph Management menu. It will end up as 'cdef=b,a,/,100,*' which is 3 custom strings(a,b and 100) and two operators( / and *). The items must be in the right order to get the above cdef: 1. custom string b , 2. custom string a , 3. Operator / , 4. custom string 100 , 5. Operator *

This CDEF tells the graph generator, Take datasource b and divide it by data source a, and then multiply the output by 100. I believe this is standard RPN math ordering.

Now go to the graph in question. Item 1 of the graph needs to be the Total, item 2 needs to be the Used or current, since your percent value needs to be the current value divided by the Maximum or Total. Remove any other items for simplicity's sake, and add a 3rd item with no Data Source but a CDEF function of byPercentage, or whatever you named it. This should do it. If you just want the percentage to draw then change the color on items 1 and 2 to None.

Is it any clearer?
User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

Post by pshankland »

Unfortunatly, I have read the manual a load of times and for some reason still couldn't work out what to do.

By look through various other posts this evening I 'think' I have found a way to do this, but please correct me if I am wrong:

I have edited rrd.php to include the following:

1) Find:

Code: Select all

$cdef_string = str_replace("ALL_DATA_SOURCES_NODUPS", $cdef_total, $cdef_string);
2) Add the following after it:

Code: Select all

$cdef_string = str_replace("|query_ifSpeed|", $ifSpeed["field_value"], $cdef_string);
3) Find:

Code: Select all

/* lets make that sql query... */
4) Add the following before it:

Code: Select all

        $ifSpeed = db_fetch_row("select 
                host_snmp_cache.field_value 
                from graph_templates_graph,graph_local,host_snmp_cache 
                where graph_local.id=graph_templates_graph.local_graph_id 
                and graph_templates_graph.local_graph_id=$local_graph_id 
                and host_snmp_cache.host_id=graph_local.host_id 
                and host_snmp_cache.snmp_index=graph_local.snmp_index 
                and host_snmp_cache.field_value>1000");
I then created a new CDEF called 'Percentage Bandwidth Utilisation' and added the following fields:

Code: Select all

Item #1:  Special Data Source: CURRENT_DATA_SOURCE 
Item #2:  Custom String: |query_ifSpeed| 
Item #3:  Operator: / 
Item #4:  Custom String: 100 
Item #5:  Operator: *
Then, I modified the Graph Template I was using and added the following fields:

Code: Select all

Item # 11 COMMENT: ---INBOUND<HR> COMMENT AVERAGE       
Item # 12 (traffic_in): Current Util:<HR> GPRINT LAST       
Item # 13 (traffic_in): Average Util:<HR> GPRINT AVERAGE       
Item # 14 (traffic_in): Max Util:<HR> GPRINT MAX       
Item # 15 COMMENT: ---OUTBOUND<HR> COMMENT AVERAGE       
Item # 16 (traffic_out): Current Util:<HR> GPRINT LAST       
Item # 17 (traffic_out): Average Util:<HR> GPRINT AVERAGE       
Item # 18 (traffic_out): Max Util:<HR> GPRINT MAX       
Item # 19 (traffic_out): Line Speed: GPRINT LAST 
Am currently not getting any decent info out of the graphs but they have only polled a couple of times since I made this change and I know it can take a while to work.

Thanks.

PS - Most of this info was taken from the following post so thanks to the author: http://forums.cacti.net/viewtopic.php?t=3030
Attachments
Graph.png
Graph.png (19.75 KiB) Viewed 26533 times
User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

Post by pshankland »

Am getting somewhere now. After changing the GPRINT from NORMAL to EXACT proper numbers started coming back. Problem I now have is that it looks as though |query_ifSpeed| is not bring back the correct max speed of the line. The following is from a graph where the max speed should be 100Mbps but as you can see from the graph the speed is coming back as some stupid figure:

Code: Select all

D:\RRDTool\rrdtool.exe graph - \
--imgformat=PNG \
--start=1114376147 \
--end=1114462547 \
--title="3COM - DMZ Switch - Traffic - [Port 1] CheckPoint Firewall" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
COMMENT:"From 2005/04/24 21:55:47 To 2005/04/25 21:55:47\c" \
COMMENT:"\n" \
--vertical-label="bits per second" \
DEF:a="D\:\Cacti/rra/3com_dmz_switch_traffic_in_134.rrd":traffic_in:AVERAGE \
DEF:b="D\:\Cacti/rra/3com_dmz_switch_traffic_in_134.rrd":traffic_out:AVERAGE \
CDEF:cdefa=a,8,* \
CDEF:cdeff=b,8,* \
CDEF:cdefbb=a,100000000,/,100,* \
CDEF:cdefbf=b,100000000,/,100,* \
AREA:cdefa#00CF00:"Inbound"  \
GPRINT:cdefa:LAST:" Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s"  \
COMMENT:"Total In:  76.01 MB\n"  \
LINE1:cdeff#002A97:"Outbound"  \
GPRINT:cdeff:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdeff:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdeff:MAX:"Maximum\:%8.2lf %s"  \
COMMENT:"Total Out: 68.83 MB\n"  \
COMMENT:"---INBOUND"  \
GPRINT:cdefbb:LAST:" Current Util\:%8.0lf"  \
GPRINT:cdefbb:AVERAGE:"Average Util\:%8.0lf"  \
GPRINT:cdefbb:MAX:"Max Util\:%8.0lf\n"  \
COMMENT:"---OUTBOUND"  \
GPRINT:cdefbf:LAST:"Current Util\:%8.0lf"  \
GPRINT:cdefbf:AVERAGE:"Average Util\:%8.0lf"  \
GPRINT:cdefbf:MAX:"Max Util\:%8.0lf\n"  \
GPRINT:b:LAST:"Line Speed\:%8.0lf"
Any ideas?

Also, how did I manage to originally get the formatting of the graph so that the percentage value had brackets around it and a percentage sign - so long ago now I can't remember :) --> http://forums.cacti.net/viewtopic.php?p=23964#23964

Thanks.
Attachments
Graph.png
Graph.png (15.86 KiB) Viewed 26525 times
benhanson
Posts: 43
Joined: Tue Feb 08, 2005 8:59 pm

Post by benhanson »

I think I see what you are saying. Unlike the drive partition queries, there is no max value datasource to reference. It looks like the initial data query does this |query_ifSpeed| as rrd_maximum, but I can't find where this is stored or if there is a way to reference it in a CDEF(without modding the php)
User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

Post by pshankland »

Have now managed to get the Line Speed to display correctly (small Mexican wave) and also the percentages showing but they are not correct.

If you take a look at the graph the Line Speed is 448000bps and the Maximum Outbound Data was 138.87kbps / 138870bps. So...

138870 / 448000 x 100 = 30.99%

Unfortunatly, I am getting 3.87% as the reported Maximum Utilisation??

The CDEF looks ok but I really don't know what is happening. Below is the properties of the graph if that helps anyone.

Code: Select all

D:\RRDTool\rrdtool.exe graph - \
--imgformat=PNG \
--start=1114416561 \
--end=1114502961 \
--title="3COM - RPL to RWL Router - Traffic - WAN" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
COMMENT:"From 2005/04/25 09:09:21 To 2005/04/26 09:09:21\c" \
COMMENT:"\n" \
--vertical-label="bits per second" \
DEF:a="D\:\Cacti/rra/3com_rwl_router_traffic_in_9.rrd":traffic_in:AVERAGE \
DEF:b="D\:\Cacti/rra/3com_rwl_router_traffic_in_9.rrd":traffic_out:AVERAGE \
CDEF:cdefb=a,8,* \
CDEF:cdefg=b,8,* \
CDEF:cdefbd=a,448000,/,100,* \
CDEF:cdefbh=b,448000,/,100,* \
COMMENT:"*******************************************TRAFFIC*******************************************\n"  \
AREA:cdefb#00CF00:"Inbound"  \
GPRINT:cdefb:LAST:" Current\:%8.2lf %s"  \
GPRINT:cdefb:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefb:MAX:"Maximum\:%8.2lf %s"  \
COMMENT:"Total In:  29.3 MB\n"  \
LINE1:cdefg#002A97:"Outbound"  \
GPRINT:cdefg:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefg:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefg:MAX:"Maximum\:%8.2lf %s"  \
COMMENT:"Total Out: 101.03 MB\n"  \
COMMENT:"************************************BANDWIDTH UTILISATION************************************\n"  \
COMMENT:"INBOUND"  \
GPRINT:cdefbd:LAST:" Current Util\:(%6.2lf%%)"  \
GPRINT:cdefbd:AVERAGE:"Average Util\:(%6.2lf%%)"  \
GPRINT:cdefbd:MAX:"Max Util\:(%6.2lf%%)\n"  \
COMMENT:"OUTBOUND"  \
GPRINT:cdefbh:LAST:"Current Util\:(%6.2lf%%)"  \
GPRINT:cdefbh:AVERAGE:"Average Util\:(%6.2lf%%)"  \
GPRINT:cdefbh:MAX:"Max Util\:(%6.2lf%%)\n"  \
COMMENT:"*****************************************LINE DETAIL*****************************************\n"  \
COMMENT:"Line Speed: 448000bps" 
Any ideas?
Attachments
Screenshot.png
Screenshot.png (56.11 KiB) Viewed 26494 times
Graph.png
Graph.png (6.29 KiB) Viewed 26494 times
User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

Post by pshankland »

Please someone explain to me why this should be the case but by adding a multiply by 8 to the CDEF the percentage utilisations appear to have been corrected!

As you can see from the screen print of the CDEF all I have done is add this 'multiply by 8' and from the graph you can see that the percentages look correct - if I am wrong please tell me.

Can anyone explain this?

Thanks.
Attachments
Graph.png
Graph.png (53.64 KiB) Viewed 26456 times
screenshot.png
screenshot.png (155.27 KiB) Viewed 26456 times
User avatar
TheWitness
Developer
Posts: 17059
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

Cacti collects data in Octets (Bytes), which have to be multiplied by 8 to get Bits. IfSpeed is in Bits/Second I guess.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
User avatar
pshankland
Cacti User
Posts: 247
Joined: Fri Dec 31, 2004 7:07 am
Location: UK

Post by pshankland »

Cheers Larry, it had to be something to do with bits & bytes and things :)
georger_br
Cacti User
Posts: 63
Joined: Mon Jul 04, 2005 10:12 am
Location: Brazil

Isn't there a simpler way?

Post by georger_br »

Hi, I'm trying to implement the same feature: displaying the percentage utilized of the available bandwitdh.
The approach above looks like a hack to me, the kind of hack that breaks when upgrading Cacti. I'd like to do this in a more standard, reproducible way.
I have attached a screenshot of one of my Frame Relay links that helps explaining what I want to do.
I modified the Graph Template Interface - Traffic (bits/sec, Total Bandwidth) and added two HRULES: Banda Garantida (CIR, or Committed Information Rate) and Banda Total (Maximum Bandwidth). That way it is pretty clear when I have a)exceeded recommended usage and b)reached maximum usage. In this particular graph, Banda Total = 512000.
The legend displays Current: 56.03 k Average: 19.09 k Maximum:118.76 k. I would like it to display Current: 56.03 k (10.94%) Average: 19.09 k (3.73%) Maximum:118.76 k (23.2%).
Any helpful hints on how to do this? Thanks in advance. Regards,

Georger
pshankland wrote:Cheers Larry, it had to be something to do with bits & bytes and things :)
Attachments
Screenshot of one of my Frame Relay links.
Screenshot of one of my Frame Relay links.
hzt.png (34.94 KiB) Viewed 25528 times
georger_br
Cacti User
Posts: 63
Joined: Mon Jul 04, 2005 10:12 am
Location: Brazil

Re: Isn't there a simpler way?

Post by georger_br »

Well, I dug deeper and finally managed to implement my dream bandwidth graph. A screenshot goes below.
I created two CDEFs: the first converts the bandwidth from bytes to bits (yes, I discovered it is redundant - I could have used Turn Bytes into Bits, but it was good exercise), and the second divides the first (current bandwidth) by the upper limit of the graph (total link bandwidth).
I also created a GPRINT Preset to format the percentage.
Last I added the six GPRINTs (for inbound/outbound LAST, AVERAGE and MAX) to the graph and voila - it's working!
pshankland, your post was invaluable in helping me achive this. Thanks! Regards,

Georger
georger_br wrote:Hi, I'm trying to implement the same feature: displaying the percentage utilized of the available bandwitdh.
The approach above looks like a hack to me, the kind of hack that breaks when upgrading Cacti. I'd like to do this in a more standard, reproducible way.
I have attached a screenshot of one of my Frame Relay links that helps explaining what I want to do.
I modified the Graph Template Interface - Traffic (bits/sec, Total Bandwidth) and added two HRULES: Banda Garantida (CIR, or Committed Information Rate) and Banda Total (Maximum Bandwidth). That way it is pretty clear when I have a)exceeded recommended usage and b)reached maximum usage. In this particular graph, Banda Total = 512000.
The legend displays Current: 56.03 k Average: 19.09 k Maximum:118.76 k. I would like it to display Current: 56.03 k (10.94%) Average: 19.09 k (3.73%) Maximum:118.76 k (23.2%).
Any helpful hints on how to do this? Thanks in advance. Regards,

Georger
pshankland wrote:Cheers Larry, it had to be something to do with bits & bytes and things :)
Attachments
hzt.png
hzt.png (34.25 KiB) Viewed 25482 times
disorganizer
Cacti User
Posts: 68
Joined: Thu Aug 04, 2005 8:34 am

Post by disorganizer »

the thing with the upperlimit just didnt work for me.
also using rrd_maximum did not work, as that is not set somehow (bug in cacti? should be set to ifSpeed according to manual on a new rrd creation).

the best way would propably be to get the rrd_maximum=ifSpeed/8 thing working.
does anyone know how to fix that?
FPL_NMS
Posts: 37
Joined: Sun Aug 21, 2005 1:17 am

Post by FPL_NMS »

George, can you provide the string you used to create the GPRINT that prints the legend you have now. I cannot for some reason figure this one out.


thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests