Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[rrd-users] legend: getting everything aligned and perky

150 views
Skip to first unread message

Daniele Sluijters

unread,
Jul 19, 2011, 4:37:16 AM7/19/11
to
Hi guys,

Probably a semi-dreaded topic here but does anyone have a good idea as to how to make the legend align?
Tools like munin seem to have a pretty good grasp of it but whatever I try I always end up with one value or another out of place.

Currently I'm looking to create a structure like this

| Heading 1 | Heading 2
line1 Value1.1 Value1.2
line2 Value2.1 Value2.2
area1 Value3.1 Value3.2
area2 Value4.1 Value4.2

Now whichever way I try to swing this I always end up with uneven spacings between value1.1 and value 1.2 compared to value2.1 to 2.2 because the value outputted for 2.1 has an extra zero or something like that screwing up the spacing. Or if the name of area2 has more characters everything else gets bumped.

To give you an idea:
"COMMENT: Average",
"COMMENT: Max\\n",
"AREA:tierin#014194:Incoming:STACK",
"GPRINT:inbits:AVERAGE:%6.2lf %Sbps ",
"GPRINT:inbits:MAX:%6.2lf %Sbps\\l",
"AREA:tierout#014194:Outgoing:STACK",
"GPRINT:outbits:AVERAGE:%6.2lf %Sbps ",
"GPRINT:outbits:MAX:%6.2lf %Sbps\\l",

That works, ish, for interface-related graphs but screws up because of the usage of spaces and other stuff to align everything. The fact that Incoming and Outgoing use, character-wise, the same amount of space is the only thing that saves me.

I've tried a few things with the GPRINT statement and COMMENT and though I can get it to work for a few specific graphs I haven't found a universal way of achieving this. Is there an "easy" way to do this, did someone happen to write a tool for it or can I use something like the html <table>-tag?

Kind regards,

--
Daniele Sluijters
e: d.slu...@betterbe.com
w: http://www.betterbe.com

_______________________________________________
rrd-users mailing list
rrd-...@lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

Simon Hobson

unread,
Jul 19, 2011, 6:46:37 AM7/19/11
to
Daniele Sluijters wrote:

>Probably a semi-dreaded topic here but does anyone have a good idea
>as to how to make the legend align?

If you find out, can you let me know as well ;-)

At some point, (IIRC) I observed that an upgrade degraded this
particular part - and graphs that used to have aligned legends no
longer did.

What I've found is :
It helps to make all value fields the same width by means of the
formatting string.
Tabs are supposed to help, but these are relative to the end of the
previous element - so IMO not helpful.
Spaces seem to match other characters in strings, but NOT between
strings and other elements (legend colour blobs, value fields).

So, for example, I've found that this generally works :

* "label " ^^^^val ^^value
* "other label" ^^value ^^value

While these will all be misaligned :
* "label" ^^value
* "label " ^^val

* "label" ^^value ^^value
* "label " ^^value

* "label" ^^value
" text" ^^value

Where * is the "colour blob", and ^ represents an implied space from
the value format.
--
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.

Brandon Phelps

unread,
Jul 19, 2011, 8:55:21 AM7/19/11
to
I use the following, which seems to be the same as your output, minus
the header line:

AREA:rhigh#FF6666AA:"High " \
LINE1:rhigh#FF0000 \
GPRINT:rhigh:AVERAGE:"Avg\\: %7.2lf" \
GPRINT:rhigh:MAX:"Max\\: %4.0lf\\n" \
AREA:rmedium#6666FFAA:"Medium" \
LINE1:rmedium#0000FF \
GPRINT:rmedium:AVERAGE:"Avg\\: %7.2lf" \
GPRINT:rmedium:MAX:"Max\\: %4.0lf\\n" \

The environment I'm using requires me to escape colons, so you might not
need those extra \\'s before the colons. The important thing to
remember is to include your format string in quotes, so that you can
manually add extra space where necessary. For example if you wanted to
spell out the word "Average" instead of "Avg", you would need to change
the "Max:" to be "Max :" instead, etc.

Good luck!

On 07/19/2011 04:37 AM, Daniele Sluijters wrote:
> Hi guys,


>
> Probably a semi-dreaded topic here but does anyone have a good idea as to how to make the legend align?

> Tools like munin seem to have a pretty good grasp of it but whatever I try I always end up with one value or another out of place.
>
> Currently I'm looking to create a structure like this
>
> | Heading 1 | Heading 2
> line1 Value1.1 Value1.2
> line2 Value2.1 Value2.2
> area1 Value3.1 Value3.2
> area2 Value4.1 Value4.2
>
> Now whichever way I try to swing this I always end up with uneven spacings between value1.1 and value 1.2 compared to value2.1 to 2.2 because the value outputted for 2.1 has an extra zero or something like that screwing up the spacing. Or if the name of area2 has more characters everything else gets bumped.
>
> To give you an idea:
> "COMMENT: Average",
> "COMMENT: Max\\n",
> "AREA:tierin#014194:Incoming:STACK",
> "GPRINT:inbits:AVERAGE:%6.2lf %Sbps ",
> "GPRINT:inbits:MAX:%6.2lf %Sbps\\l",
> "AREA:tierout#014194:Outgoing:STACK",
> "GPRINT:outbits:AVERAGE:%6.2lf %Sbps ",
> "GPRINT:outbits:MAX:%6.2lf %Sbps\\l",
>
> That works, ish, for interface-related graphs but screws up because of the usage of spaces and other stuff to align everything. The fact that Incoming and Outgoing use, character-wise, the same amount of space is the only thing that saves me.
>
> I've tried a few things with the GPRINT statement and COMMENT and though I can get it to work for a few specific graphs I haven't found a universal way of achieving this. Is there an "easy" way to do this, did someone happen to write a tool for it or can I use something like the html<table>-tag?
>
> Kind regards,
>

_______________________________________________

Ulf Zimmermann

unread,
Jul 19, 2011, 3:39:46 PM7/19/11
to
You can use \t in the GPRINT to align.


________________________________________
From: rrd-users-bounces+ulf=atc-onl...@lists.oetiker.ch [rrd-users-bounces+ulf=atc-onl...@lists.oetiker.ch] On Behalf Of Brandon Phelps [bph...@gls.com]
Sent: Tuesday, July 19, 2011 5:55 AM
To: rrd-...@lists.oetiker.ch
Subject: Re: [rrd-users] legend: getting everything aligned and perky

Simon Hobson

unread,
Jul 20, 2011, 2:57:42 AM7/20/11
to
Ulf Zimmermann wrote:
>You can use \t in the GPRINT to align.

It's been a while now, but from memory it didn't work for me because
... it tabs from the end of the previous element on the line, not to
an absolute position. I think I was trying to align some values where
one line had the colour blob from the legend, and another didn't.
Since the tab runs from the end of the space occupied by the colour
blob, there is no way to align the other line with it at all.
Similarly where some lines don't include all the values that others
do - the tab runs from the end of the previous element, and so you
still end up trying to match the length of a printed field with
spaces.

It also spread stuff out terribly so that my tables just didn't fit
into the box.

Now if someone has a working example that can do something like this :

* Some label xxx.xx xxx.xx xxx.xx
Another label yyy.yy yyy.yy

and have it all line up then I'd love to see it !

--
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.

_______________________________________________

Daniele Sluijters

unread,
Jul 20, 2011, 4:13:05 AM7/20/11
to
Hi,

I figured out a few things:

1) RRDtool just can't/won't align stuff decently like you want it because it doesn't have the options to do so. I'm really missing something like a table-keyword similar to HTML's in order to create tabular legends.

2) \t, \l, \n, \j are useful but it's a thing about getting stuff right and getting stuff wrong. Basically, shuffle through the options until you get the result you need.

3) The only way to really align stuff is with spaces. If a string is always of an equal length, thanks to for example additionally appended spaces at the end of a label, stuff will line out.

In the end I'm left with the following code:
args_ext.append("--pango-markup")
args_ext.append("COMMENT: <b>Average</b>")
args_ext.append("COMMENT: <b>Max</b>\\n")
args_ext.append("--font")
args_ext.append("LEGEND:7:monospace")
args_ext.append("LINE1:sc%i%s:%s" % (2*i+1000, COLORS_MULTI[2*i], pair.descr.split("/")[0].lower().ljust(8)+"|"))
args_ext.append("TEXTALIGN:left")
args_ext.append("GPRINT:sc%i:AVERAGE:%%8.2lf %%S |" % (2*i+1000,))
args_ext.append("GPRINT:sc%i:MAX:%%8.2lf %%S |\\l" % (2*i+1000,))
args_ext.append("LINE2:sc%i%s:%s" % (2*i+1+1000, COLORS_MULTI[2*i+1], pair.descr.split("/")[1].lower().strip().ljust(8)+"|"))
args_ext.append("GPRINT:sc%i:AVERAGE:%%8.2lf %%S |" % (2*i+1+1000,))
args_ext.append("GPRINT:sc%i:MAX:%%8.2lf %%S |\\l" % (2*i+1+1000,))

Now because I'm using python's string formatting I need to escape the % by doubling it so it isn't seen by python as something meaningful, same goes for the backslashes (\). I'm also generating the sc-numbers on the fly, don't bother with it, I know what's happening and that doesn't affect anything.

The crux lies in ljustify(8). It basically makes sure the label is 8 chars long with spaces appended to the right of it. Because we also tell RRDtool that the font for the legend is a monospace-font everything now is exactly the same size so we can start using spaces to align. Coupled with the %8.2lf I also always know that the output will be 8 numbers followed by the decimal separator followed by another two numbers. If the first part doesn't happen to have 8 numbers spaces will be prepended to it so xxxx.xx and yyy.yy align equally to the right. The additional pipe at the end is just for clarity in our case, it creates a column-feel.

By bolding the first two comments and spacing them correctly you can then create the look and feel of table headings but that only works for RRDtool 1.3+ which can use pango.

This in effect results in the following code being passed to RRDtool:
COMMENT: <b>Average</b>
COMMENT: <b>Max</b>\n
--font
LEGEND:7:monospace
CDEF:sc1000=sc0,1024.000000,*
CDEF:sc1001=sc1,1024.000000,*
LINE1:sc1000#014194:used |
TEXTALIGN:left
GPRINT:sc1000:AVERAGE:%8.2lf %S |
GPRINT:sc1000:MAX:%8.2lf %S |\l
LINE2:sc1001#f49800:total |
GPRINT:sc1001:AVERAGE:%8.2lf %S |
GPRINT:sc1001:MAX:%8.2lf %S |\l
CDEF:sc1002=sc2,1024.000000,*
CDEF:sc1003=sc3,1024.000000,*
LINE1:sc1002#C93A5E:free |
GPRINT:sc1002:AVERAGE:%8.2lf %S |
GPRINT:sc1002:MAX:%8.2lf %S |\l
LINE2:sc1003#2C8C29:max |
GPRINT:sc1003:AVERAGE:%8.2lf %S |
GPRINT:sc1003:MAX:%8.2lf %S |\l

As you can see, the amount of spaces between 'max' and the pipe at the end is just a bit more than for example 'free' until the pipe.

In the end I get a graph looking like this:
https://dump.daenney.net/rrdtool-example.png

That's reasonably decent and good enough for now. I really wish there was a less intricate way of doing this. Now I still need to find a color-scheme / bunch of settings that give the output a bit more of a post-millenium look and feel.

Steve Shipway

unread,
Jul 20, 2011, 5:31:29 AM7/20/11
to
You might like to try enabling the Pango markup option to RRDTool, and see if you can achieve more using Pango. The documentation for this is available online. It lets you do more HTML-like things, change fonts, and so on.

Steve

Steve Shipway
University of Auckland ITS
UNIX Systems Design Lead
s.sh...@auckland.ac.nz
Ph: +64 9 373 7599 ext 86487

Daniele Sluijters

unread,
Jul 20, 2011, 5:53:25 AM7/20/11
to
Hi,

I already have, that's why the <b>'s are in there to bold the headers :-). Unfortunately pango is rather limited. Though it allows a lot of style changes indeed layout-wise it is proving to be of almost no use.

The ability to change fonts is useful, same as changing the colors. However, since for aligning I'm bound to a monospace font my choice gets rather limited again. It's a bit of a trade-off between getting something that looks decent and is also decent layout-

0 new messages