Extra space in my GPRINT

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
bodgit
Posts: 8
Joined: Wed Aug 31, 2005 6:39 am

Extra space in my GPRINT

Post by bodgit »

I've created a new graph template for MySQL, and there seems to be a extra space appearing in the GPRINT fields. I've attached a graph with this behaviour.

I've gone through the graph template and I can't find an extra space on any of the labels. Here's the debug output from rrdtool:

Code: Select all

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="hugh - MySQL - Commands" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="commands per second" \
--slope-mode \
DEF:a="/var/www/cacti/rra/hugh_com_select_54.rrd":com_select:AVERAGE \
DEF:b="/var/www/cacti/rra/hugh_qcache_hits_57.rrd":qcache_hits:AVERAGE \
DEF:c="/var/www/cacti/rra/hugh_com_select_54.rrd":com_insert:AVERAGE \
DEF:d="/var/www/cacti/rra/hugh_com_select_54.rrd":com_insert_select:AVERAGE \
DEF:e="/var/www/cacti/rra/hugh_com_select_54.rrd":com_update:AVERAGE \
DEF:f="/var/www/cacti/rra/hugh_com_select_54.rrd":com_update_multi:AVERAGE \
DEF:g="/var/www/cacti/rra/hugh_com_select_54.rrd":com_replace:AVERAGE \
DEF:h="/var/www/cacti/rra/hugh_com_select_54.rrd":com_replace_select:AVERAGE \
DEF:i="/var/www/cacti/rra/hugh_com_select_54.rrd":com_delete:AVERAGE \
DEF:j="/var/www/cacti/rra/hugh_com_select_54.rrd":com_delete_multi:AVERAGE \
DEF:ba="/var/www/cacti/rra/hugh_com_select_54.rrd":com_truncate:AVERAGE \
CDEF:cdefa=a,UNKN,UNKN,IF \
CDEF:cdefb=b,UNKN,UNKN,IF \
CDEF:cdefc=c,UNKN,UNKN,IF \
CDEF:cdefd=d,UNKN,UNKN,IF \
CDEF:cdefe=e,UNKN,UNKN,IF \
CDEF:cdeff=f,UNKN,UNKN,IF \
CDEF:cdefg=g,UNKN,UNKN,IF \
CDEF:cdefh=h,UNKN,UNKN,IF \
CDEF:cdefi=i,UNKN,UNKN,IF \
CDEF:cdefj=j,UNKN,UNKN,IF \
CDEF:cdefba=a,b,+ \
CDEF:cdefbe=c,d,+ \
CDEF:cdefbi=e,f,+ \
CDEF:cdefcc=g,h,+ \
CDEF:cdefcg=i,j,+ \
LINE1:cdefa:""  \
LINE1:cdefb:""  \
LINE1:cdefc:""  \
LINE1:cdefd:""  \
LINE1:cdefe:""  \
LINE1:cdeff:""  \
LINE1:cdefg:""  \
LINE1:cdefh:""  \
LINE1:cdefi:""  \
LINE1:cdefj:""  \
LINE1:cdefba#005D57:"SELECT"  \
GPRINT:cdefba:LAST:"  Current\:%8.2lf %s"  \
GPRINT:cdefba:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefba:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:cdefbe#FF4105:"INSERT"  \
GPRINT:cdefbe:LAST:"  Current\:%8.2lf %s"  \
GPRINT:cdefbe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefbe:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:cdefbi#D8ACE0:"UPDATE"  \
GPRINT:cdefbi:LAST:"  Current\:%8.2lf %s"  \
GPRINT:cdefbi:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefbi:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:cdefcc#005199:"REPLACE"  \
GPRINT:cdefcc:LAST:"  Current\:%8.2lf %s"  \
GPRINT:cdefcc:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefcc:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:cdefcg#EACC00:"DELETE"  \
GPRINT:cdefcg:LAST:"  Current\:%8.2lf %s"  \
GPRINT:cdefcg:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefcg:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:ba#55D6D3:"TRUNCATE"  \
GPRINT:ba:LAST:"Current\:%8.2lf %s"  \
GPRINT:ba:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:ba:MAX:"Maximum\:%8.2lf %s"
The "Current:" label for the REPLACE GPRINT should only have one space before it to make it line up with the TRUNCATE line, it has two somehow.
Attachments
graph.png
graph.png (54.91 KiB) Viewed 11431 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

There's an option in the Graph Template definitions reading Auto Padding. You may want to switch it off
Reinhard
bodgit
Posts: 8
Joined: Wed Aug 31, 2005 6:39 am

Post by bodgit »

Tried flipping auto padding off, now it looks even worse :(

Most of the labels now only line up by virtue of them all being the same length strings.

I'm guessing the auto pad option is implemented by Cacti rather than RRD itself. If you can point me to the code, I can try and have a look and see if I can work out what is going on.
Attachments
graph.png
graph.png (55.78 KiB) Viewed 11394 times
bodgit
Posts: 8
Joined: Wed Aug 31, 2005 6:39 am

Post by bodgit »

Okay, found the problem I think, I'll try and explain as best as I can.

In lib/rrd.php(rrdtool_function_graph), in the auto padding code, the $text_format_lengths array containing the length of the legend text of each AREA/STACK/LINE[123] graph element is keyed on the 'data_template_rrd_id'.

The problem is, for any of these graph elements that are graphing a CDEF, there is an empty 'data_template_rrd_id' value, so what happens is each graphed CDEF element will overwrite the length of the previous graphed CDEF element in the array.

So in my graph if you trace the elements graphed, it will store a length of '6' 3 times, then a '7', then overwrite it again with '6', all under the same array key, as well as a length of '8' for the final element which is a regular data source in it's own array key as that has a valid 'data_template_rrd_id' value.

When the graph is actually drawn, cacti will look up the length of each legend string again by the value of 'data_template_rrd_id', and it will return the length '6' for each of the CDEF graph elements. So in my case it thinks the length of the 'REPLACE' field is 6 instead of 7 because that's the length of the 'DELETE' field, the last CDEF in the list, and because the longest field is 8 characters (TRUNCATE), it tacks on 2 extra spaces.

The workaround/fix is to key $text_format_lengths on some unique key other than 'data_template_rrd_id' that is unique and non-NULL for all elements.

Clear as mud? :D
User avatar
Cylindric
Cacti User
Posts: 54
Joined: Mon Jul 16, 2007 9:32 am

Post by Cylindric »

I had this, and just kind of cheated by putting a space at the end of the titles for those rows where column 2 isn't indented enough. It pushed the alignment to the next tab-stop.
Server: Windows Server 2008 R2 x64 (running on a VM, 4Gb RAM)
Cacti: 0.8.8a (using cmd, 270 datasources in 145s)
MySQL: 5.5.16, Apache: 2.2.21, PHP: 5.3.16
bodgit
Posts: 8
Joined: Wed Aug 31, 2005 6:39 am

Post by bodgit »

The attached patch fixes it for me. Basically instead of trying to store the lengths of the strings, I just recalculate them later on.

The alignment issue is gone and I haven't noticed any bugs introduced into the other graphs.
Attachments
lib-rrd.php.patch
(2.82 KiB) Downloaded 732 times
fatus
Posts: 1
Joined: Fri Oct 12, 2007 6:18 pm

Great job!

Post by fatus »

bodgit wrote:The attached patch fixes it for me. Basically instead of trying to store the lengths of the strings, I just recalculate them later on.

The alignment issue is gone and I haven't noticed any bugs introduced into the other graphs.
Great job! This patch fixed all whitespace issues for me and probably should appear on the Official fixes page.
SyS_ErroR
Posts: 1
Joined: Wed Oct 24, 2007 6:03 pm

Post by SyS_ErroR »

bodgit wrote:The attached patch fixes it for me. Basically instead of trying to store the lengths of the strings, I just recalculate them later on.

The alignment issue is gone and I haven't noticed any bugs introduced into the other graphs.
I'm having the same problem with the default templates.
Can you tell me how to implement your patch?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Great job!

Post by gandalf »

fatus wrote:
bodgit wrote:The attached patch fixes it for me. Basically instead of trying to store the lengths of the strings, I just recalculate them later on.

The alignment issue is gone and I haven't noticed any bugs introduced into the other graphs.
Great job! This patch fixed all whitespace issues for me and probably should appear on the Official fixes page.
I've put it onto my ToDo List for 0.8.8. If time permits, we may post an official patch.
Reinhard
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Fixed in SVN. Thanks for the contribution
Reinhard
br2t
Posts: 1
Joined: Thu Nov 29, 2012 3:06 am

Re: Extra space in my GPRINT

Post by br2t »

Hello!
Can you replace in future releases function strlen on mb_strlen?
I'm from Russia and I use Russian language in GPRINT and i have some trouble with extra space.
strlen is counts bits but no the letters, when i replace in patch

Code: Select all

strlen($graph_variables["text_format"][$graph_item_id]) 
on

Code: Select all

mb_strlen($graph_variables["text_format"][$graph_item_id], "UTF-8")

it works, and i has no extra space in GPRINT.

Thank you.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests