[SOLVED] How do I change the x-graph to show AM/PM?

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

[SOLVED] How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

Hello:

Well, I conquered the Timezone issue, but now the client wants AM/PM designations on his graphs.

This page talks about how to do it, but I'd thought I'd ask here for knowledgeable opinions.
http://www.vandenbogaerdt.nl/rrdtool/tu ... x-grid.php --> "RRDtool graph --x-grid tutorial and examples" re: LFM

Code: Select all

"%H	Hour as two digits, with leading zero, e.g. 00 01 ... 22 23
Now we get 1400 for 2pm.

Another page says "RRDtool allows you to generate reports in numerical and graphical form based on the data stored in one or several RRDs. The graphing feature is fully configurable. Size, color and contents of the graph can be defined freely. Check rrdgraph for more information on this." from this page http://oss.oetiker.ch/rrdtool/doc/rrdtool.en.html

I am sure there's a lot I didn't include but I am using Version 0.8.7g pretty much out of the box install.

Thank you for your time.

How can I implement AM/PM designation on my x-graphs | timelines?

Thank you for your time.
Last edited by cirrhus9 on Tue May 17, 2011 8:27 pm, edited 1 time in total.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How do I change the x-graph to show AM/PM?

Post by noname »

Cacti does not fully support RRDtool options (yet, probably).

I tried implementing that..
(for Cacti 0.8.7g, but not tested completely. At your own risk.)

1) Add new field to rra table
% mysql -uUSER -pPASS cacti -e 'ALTER TABLE rra ADD x_grid VARCHAR(80) NULL;'
Result in database:
Image

2) Modify source

include/global_form.php:

Code: Select all

--- include/global_form.php.org Thu Mar 31 15:47:00 2011
+++ include/global_form.php     Mon May 16 16:26:00 2011
@@ -923,6 +923,13 @@
                "value" => "|arg1:timespan|",
                "max_length" => "12",
                ),
+       "x_grid" => array(
+               "method" => "textbox",
+               "friendly_name" => "X-Grid Definitions",
+               "description" => "Custom definitions of 'x-grid' option for this RRA.",
+               "value" => "|arg1:x_grid|",
+               "max_length" => "80",
+               ),
        "id" => array(
                "method" => "hidden_zero",
                "value" => "|arg1:id|"
lib/rrd.php:

Code: Select all

--- lib/rrd.php.org     Thu Mar 31 15:47:00 2011
+++ lib/rrd.php Mon May 16 16:30:22 2011
@@ -590,7 +590,7 @@
                        }
                }
        }else{
-               $rra = db_fetch_row("select timespan,rows,steps from rra where id=$rra_id");
+               $rra = db_fetch_row("select timespan,rows,steps,x_grid from rra where id=$rra_id");
        }

        $seconds_between_graph_updates = ($ds_step * $rra["steps"]);
@@ -861,6 +861,11 @@
                $graph_opts .= rrdtool_set_font("unit");
        }

+       /* x-grid definitions */
+       if (!empty($rra["x_grid"])) {
+               $graph_opts .= "--x-grid " . $rra["x_grid"] . RRD_NL;
+       }
+
        $i = 0; $j = 0;
        $last_graph_cf = array();
        if (sizeof($graph_items) > 0) {
rra.php:

Code: Select all

--- rra.php.org Sat Jul 10 07:33:46 2010
+++ rra.php     Mon May 16 16:25:44 2011
@@ -66,6 +66,7 @@
                $save["steps"] = form_input_validate($_POST["steps"], "steps", "^[0-9]*$", false, 3);
                $save["rows"] = form_input_validate($_POST["rows"], "rows", "^[0-9]*$", false, 3);
                $save["timespan"] = form_input_validate($_POST["timespan"], "timespan", "^[0-9]*$", false, 3);
+               $save["x_grid"] = form_input_validate($_POST["x_grid"], "x_grid", "", true, 3);

                if (!is_error_message()) {
                        $rra_id = sql_save($save, "rra");
@@ -168,7 +169,8 @@
                "name" => array("Name", "ASC"),
                "steps" => array("Steps", "ASC"),
                "rows" => array("Rows", "ASC"),
-               "timespan" => array("Timespan", "ASC"));
+               "timespan" => array("Timespan", "ASC"),
+               "x_grid" => array("X-Grid Definitions", "ASC"));

        html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"], 4);

@@ -177,7 +179,8 @@
                name,
                rows,
                steps,
-               timespan
+               timespan,
+               x_grid
                FROM rra
                ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']);

@@ -198,6 +201,9 @@
                        <td>
                                <?php print $rra["timespan"];?>
                        </td>
+                       <td>
+                               <?php print $rra["x_grid"];?>
+                       </td>
                        <td align="right">
                                <a href="<?php print htmlspecialchars("rra.php?action=remove&id=" . $rra["id"]);?>"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
                        </td>
Result:
Image

3) Define x-grid as you like

(For example, I edited Daily RRA)
Image
* I use "%p" (AM/PM) instead of "%P" (am/pm), because my rrdtool was linked with old C library when compiled.

Result:
Image
NOTICE: This string should be sanitized (but this time I didn't)

4) View graphs

Image

When I clicked "Graph Source/Properties" icon:
/usr/local/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title='Localhost - Disk Space - /var' \
--rigid \
--base=1024 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label='bytes' \
--slope-mode \
--font TITLE:10: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
--x-grid MINUTE:30:HOUR:2:HOUR:2:0:"%I%p" \
DEF:a="/var/www/cacti/rra/localhost_hdd_free_48.rrd":hdd_used:AVERAGE \
DEF:b="/var/www/cacti/rra/localhost_hdd_free_48.rrd":hdd_free:AVERAGE \
CDEF:cdefa=a,1024,* \
CDEF:cdefe=b,1024,* \
...
// Sorry my English
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

Re: How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

noname:

an Excellent solution. Thank you.

AM/PM vs. am/pm... It will have to do. :)

"NOTICE: This string should be sanitized (but this time I didn't)"

Who, or what does the sanitizing?

Thank you for your time.

P.S. Your English is excellent too. :)
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How do I change the x-graph to show AM/PM?

Post by noname »

cirrhus9 wrote:"NOTICE: This string should be sanitized (but this time I didn't)"

Who, or what does the sanitizing?
This option which you (or other administrator) defined will be passed to rrdtool command line,
so some "tainted" characters (e.g. pipe(|), backquote(`), etc.) should be omitted/disabled to avoid executing unwanted command.

Well.. perhaps.. like this?
$graph_opts .= "--x-grid " . escapeshellcmd($rra["x_grid"]) . RRD_NL;
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

Re: How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

Thank you.

I implemented the changes you suggested but had to roll back those changes when all I got was a blank page.

I will try again and let you know.

Thank you very much.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: How do I change the x-graph to show AM/PM?

Post by gandalf »

noname wrote:Cacti does not fully support RRDtool options (yet, probably).
This is correct for 087g. It has been implemented in a most flexible way in 088 SVN code (not yet published).
R.
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

Re: How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

noname:

I get a blank page when viewing RRAs

Here's the diff from them, maybe you can spot my "error"?

diff /usr/share/cacti/site/rra.php /usr/share/cacti/site/rra.php.org

Code: Select all

69d68
<               $save["x_grid"] = form_input_validate($_POST["x_grid"], "x_grid", "", true, 3);
173,174c172
<               "timespan" => array("Timespan", "ASC"),
<                 "x_grid" => array("X-Grid Definitions", "ASC"));
---
> 
182,184c180
<               timespan,
<               timespan,
<               x_grid
---
>               timespan
204,206d199
<                       </td>
<                       <td>
<                               <?php print $rra["x_grid"];?>
Thank you for your time.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How do I change the x-graph to show AM/PM?

Post by noname »

It seemed that something failed to modify. (e.g. You're duplicating "timespan,")

Then, please use this patch at Cacti install directory (after rolling back changes).

To patch:
% patch -p1 < xgrid.patch

To revert:
% patch --reverse -p1 < xgrid.patch
Attachments
xgrid.patch
(2.56 KiB) Downloaded 161 times
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

Re: How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

noname:

Yes, that stuck out like a 3rd eyeball and I questioned it.

I will attempt the patch tomorrow and let you know.

Thank you, I really appreciate your time.
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

Re: How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

That did it.

Very much appreciated.

Can you explain this logic to me?
MINUTE:30:HOUR:2:HOUR:2:0

Also, will that same string (+"%I%p" work for the "Hourly (1 Minute Average)" rra?
Which I hope will also change the x_grid at /cacti/graph_view.php?action=tree&tree_id=x ?
(The default "view" on Graphs tab. Or will I have to recreate my graphs?)

Without having peered into too much, it may have to be something different.
I check this http://repo.opennms.org/sites/jrobin/1. ... eAxis.html
but didn't study it. (Not that I could understand it)

Thanks!
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How do I change the x-graph to show AM/PM?

Post by noname »

cirrhus9 wrote:Can you explain this logic to me?
MINUTE:30:HOUR:2:HOUR:2:0
Gray line is drawn at every 30 minutes
Red line is drawn at every 2 hours
Label is placed at every 2 hours
Label position is adjusted +/- 0 sec

See also: http://www.vandenbogaerdt.nl/rrdtool/tutorial/x-grid.php
cirrhus9 wrote:Also, will that same string (+"%I%p" work for the "Hourly (1 Minute Average)" rra?
For example:

Code: Select all

MINUTE:5:MINUTE:30:HOUR:1:0:"%l%p"
Image
(I'm not using 1-minute polling)
cirrhus9 wrote:Which I hope will also change the x_grid at /cacti/graph_view.php?action=tree&tree_id=x ?
(The default "view" on Graphs tab. Or will I have to recreate my graphs?)
Default graph view when clicked "graphs" tab is depend on user's 'Graph Settings'.
Image

Unfortunately, this default timespan is independent from existing RRAs.
(P.S. If you changed this graph settings, please re-login to see its effect)
cirrhus9 wrote:Without having peered into too much, it may have to be something different.
I check this http://repo.opennms.org/sites/jrobin/1. ... eAxis.html
See RRDtool source code.
src/rrd_graph.c:

Code: Select all

xlab_t xlab[] = {
    {0,                 0,   TMT_SECOND,30, TMT_MINUTE,5,  TMT_MINUTE,5,         0,"%H:%M"},
    {2,                 0,   TMT_MINUTE,1,  TMT_MINUTE,5,  TMT_MINUTE,5,         0,"%H:%M"},
    {5,                 0,   TMT_MINUTE,2,  TMT_MINUTE,10, TMT_MINUTE,10,        0,"%H:%M"},
...
cirrhus9
Posts: 30
Joined: Thu Apr 28, 2011 7:23 am

Re: How do I change the x-graph to show AM/PM?

Post by cirrhus9 »

Thank you.
Newuser2015
Posts: 1
Joined: Wed Oct 07, 2015 1:17 pm

Re: [SOLVED] How do I change the x-graph to show AM/PM?

Post by Newuser2015 »

I know this is a very old post but I am struggling a bit with am/pm. Hopefully someone figured this out and can point me in the right direction.

I have graphs working for the daily 5 minute average but only when I click on the graph. (Please see below)

I am not sure how to modify the default view so I can see am/pm when I click on a server/system.
The link in this post gives a 404. http://repo.opennms.org/sites/jrobin/1. ... eAxis.html


Thank you.
Attachments
Default view (does not show am/pm and when I view properties I do not see <br />--x-grid MINUTE:30:HOUR:2:HOUR:2:0:&quot;%I%p&quot; \) Not sure where to modify this.
Default view (does not show am/pm and when I view properties I do not see
--x-grid MINUTE:30:HOUR:2:HOUR:2:0:"%I%p" \) Not sure where to modify this.
Cacti_default_page.png (24.62 KiB) Viewed 3001 times
5 Minute view (displays am/pm)
5 Minute view (displays am/pm)
Cacti_5 minute.png (16.02 KiB) Viewed 3001 times
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests