2

I'm using RRDtool through a Perl script (RRDs) to visualize temperature readings. As I want everything in the graph to be shown in Swedish (weekdays etc), I set the locale to sv_SE.UTF-8 in my Perl script with:

use POSIX qw(locale_h);
setlocale(LC_ALL, "sv_SE.UTF-8");

RRDtool gets this, and prints weekday names in Swedish. However, numerical values that are written under the RRDtool graph with GPRINT use dots instead of commas as decimal separators (XX.xx), and I'm not sure why. In Swedish, commas should be used (XX,xx). I use GPRINT like this:

GPRINT:temp_out:MIN: Min\\: %6.1lf

I've tried setting LC_NUMERIC and LC_CTYPE to sv_SE.UTF-8 as well, but without result. I've tried using sv_SE.iso8859-1, but no go. I've also read various printf documentation, but have yet to come up with a solution.

Has anyone managed to make RRDtool use commas instead of dots as decimal separators? Thanks!

Edit:

If I create the graph using rrdtool graph at the command line and have set LC_NUMERIC=sv_SE, I get commas as decimal separators. This leads me to believe that my Perl script doesn't pick up on my setlocale. Still investigating...

John V.
  • 45
  • 5
  • Which RRD Perl module are you using? RRD::Editor? RRDTool::Creator? – Zaid Nov 19 '11 at 17:26
  • I'm using the RRDs module that is bundled with RRDtool and use RRDs::create and RRDs::graph to create the database and build my graph. – John V. Nov 21 '11 at 10:55

1 Answers1

1

rrdtool is actually forcing LC_NUMERIC in multiple places to 'C' in order to prevent stray commas from showing up in odd places ...

to see commas in generated charts, one would have to enhance this logic a bit further in rrd_graph.c to explicitly re-enable the users original LC_NUMERIC setting prior to rendering GPRINT statements.

Tobi Oetiker
  • 5,167
  • 2
  • 17
  • 23
  • Thanks for chiming in Tobi. The weird thing is that I get commas in my graph when using rrdtool from the command line, so rrdtool seems to be following orders. However, when creating the graph using the Perl module RRDs, I get dots. A bit of googling would suggest that there might be something amuck with Perl's handling of LC_NUMERIC. The quest continues. – John V. Nov 22 '11 at 20:58
  • are you sure you are using the same version of rrdtool all the way ? the LC_NUMERIC enforcement is rather new. – Tobi Oetiker Nov 22 '11 at 22:58
  • Yes, I am using RRDtool 1.4.5 in both cases. In the end I went the quick and dirty route and edited rrd_graph.c to set `LC_NUMERIC` to `sv_SE` instead of `C`, and recompiled. Now I get commas as decimal separators when using the RRDs module as well. Not an elegant solution, but it works. Thanks so much for taking the time to answer! – John V. Nov 23 '11 at 08:18
  • note, that now the output of PRINT may be contain , too which might be not so optimal when it comes to parsing that if you are also extracting data using graphv for example. – Tobi Oetiker Nov 24 '11 at 07:33