Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Tue Mar 26, 2019 7:33 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Cacti timezone issues
PostPosted: Wed Jul 25, 2012 5:50 am 
Offline

Joined: Wed Jul 25, 2012 5:38 am
Posts: 2
I recently updated to 0.8.8a with rrdtool 1.4.7, as I tough my old version (0.8.7g/1.2.9) where the cause of my issue.

Indeed, this didn't solve my problem, which is that graphs do not update.

Actually, I found out that the issue was caused by the php.ini value date.timezone = "UTC".

This should have an impact on unix timestamps provided to rrdtool, but apparently it does !

From the logs :
07/25/2012 09:45:20 AM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/www/cacti/rra/magento_stg_db_traffic_in_321.rrd --template traffic_in:traffic_out 1343227517:1119063717:3360557635

The human-readable time is OK (logging actually occurred at 09:45 UTC), but the unix timestamp supplied to rrdtool is wrong (1343227517 is actually 14:45 UTC).

Needless to say, my rrd files are now all messed up.

Does anyone know the correct way to change the time zone in Cacti (in my case to have everything relate to UTC) ?


Top
 Profile  
 
 Post subject: Re: Cacti timezone issues
PostPosted: Wed Jul 25, 2012 7:50 am 
Offline

Joined: Wed Jul 25, 2012 5:38 am
Posts: 2
After a lot of investigation, I figured out that cacti was translating back and forth between human-readable times (in specific timezones) and unix timestamps, causing all kinds of issues.

I found out that three elements must have their timezone aligned to make that kind of setup work :
[*] cacti
[*] rrdtool
[*] mysql

Cacti time can be set by adding a "date.timezone" value in /etc/php.ini.

Cacti must be instructed to reflect this timezone settings to MySQL database. I got the idea by reading http://bugs.cacti.net/view.php?id=2144.
My diff against 0.8.8a :
Code:
*** include/global.php.orig     2012-07-25 12:01:48.000000000 +0000
--- include/global.php  2012-07-25 12:04:36.000000000 +0000
***************
*** 223,228 ****
--- 223,230 ----
  include_once($config["library_path"] . "/variables.php");
  include_once($config["library_path"] . "/auth.php");

+ db_execute(sprintf("SET time_zone = '%s'", date_default_timezone_get()));
+
  api_plugin_hook("config_insert");

  /* current cacti version */


Cacti must also be instructed to reflect this timezone to rrdtool. This came clearly by reading http://nicolas.vanwambeke.net/wp/2010/04/06/changing-the-timezone-of-cacti-graphs-using-rrdtool/.
Patch against 0.8.8a :
Code:
*** ./lib/rrd.php.orig  2012-07-25 12:06:30.000000000 +0000
--- ./lib/rrd.php       2012-07-25 12:12:08.000000000 +0000
***************
*** 39,44 ****
--- 39,47 ----
                putenv("RRD_DEFAULT_FONT=" . read_config_option("path_rrdtool_default_font"));
        }

+       /* Set the time zone */
+       putenv(sprintf("TZ=%s", date_default_timezone_get()));
+
        if ($output_to_term) {
                $command = read_config_option("path_rrdtool") . " - ";
        }else{
***************
*** 92,97 ****
--- 95,103 ----
                $pipe_mode = "rb";
        }

+       /* Set the time zone */
+       putenv(sprintf("TZ=%s", date_default_timezone_get()));
+
        /* an empty $rrdtool_pipe array means no fp is available */
        if (!is_resource($rrdtool_pipe)) {
                session_write_close();
***************
*** 405,410 ****
--- 411,419 ----
                $rrd_tune .= " --data-source-rename $data_source_name:" . $rrd_tune_array["data-source-rename"];
        }

+       /* Set the time zone */
+       putenv(sprintf("TZ=%s", date_default_timezone_get()));
+
        if ($rrd_tune != "") {
                if (file_exists($data_source_path) == true) {
                        $fp = popen(read_config_option("path_rrdtool") . " tune $data_source_path $rrd_tune", "r");


Now, the tricky part is : both your rrd and you MySQL databases still refer to the previous timezone, so you need to update both !

In the database, you need to reset all poller status (before doing the following, you may want to ensure that no poller is running and no poller is scheduled to run) :
truncate poller;
truncate poller_command;
truncate poller_output;
truncate poller_time;

To support symbolic timezone names in MySQL, you should populate the mysql.timezone table using this command :
/usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

Then, you need to fix all the rrds ! Maybe the trickiest part. I found no other way than writing a small bit of perl code :
Code:
#!/usr/bin/perl

my ($fn)[email protected];

my $tmpfn="/tmp/rrdfix.$$.xml";

die "Cannot find $fn : $!" unless (-f $fn);

open(IN,"rrdtool dump $fn|") or die "Cannot spawn rrdtool : ".$!;
open(OUT,">$tmpfn");
while(<IN>) {
  if (/(.*?<lastupdate>)(\d+)(<\/lastupdate>.*)/) {
    my ($pre,$lastu,$post)=($1,$2,$3);
    print OUT $pre.($lastu-18000).$post;
  } else {
    print OUT $_;
  }
}
close(OUT);
close(IN);

system("rrdtool restore $tmpfn $fn -f");
unlink $tmpfn;


Top
 Profile  
 
 Post subject: Re: Cacti timezone issues
PostPosted: Thu Aug 23, 2012 1:32 pm 
Offline

Joined: Mon Nov 15, 2010 7:57 am
Posts: 7
This is brilliant. Thanks. I was having the same problem with a new install on openSuSE 12.1. I had tried to import some data from a previous install and assumed that was the issue. After I started again from scratch and had the same problem. .

I followed your directions and they worked perfectly. (I had to manually make the changes to rrd.php for some reason as patch didn't like any of the hunks, but still worked great. )

THANKS!!


Top
 Profile  
 
 Post subject: Re: Cacti timezone issues
PostPosted: Thu May 30, 2013 5:46 pm 
Offline

Joined: Wed May 29, 2013 7:39 pm
Posts: 2
Very awesome.... 8)


Top
 Profile  
 
 Post subject: Re: Cacti timezone issues
PostPosted: Wed Jan 22, 2014 4:13 pm 
Offline

Joined: Wed Jan 22, 2014 4:08 pm
Posts: 1
http://n00blab.com/correcting-cacti-timezone/#comment-3854

Correcting Cacti Timezone

Battled a super annoying issue with what appeared to be Cacti not displaying graphs, which after half a day of messing around ended up being a timezone setting…..grrrrrrrrrrrr

After discovering Cacti was indeed graphing my expected values, just 4 hours ahead of my local time (EDT, America/Toronto) I realized cacti.log was showing UTC timestamps.

After confirming my Linux system time:

[email protected] ~ $ date
Fri Aug 17 04:39:13 EDT 2012

I dug around on cacti.net and found instructions on updating php.ini with timezone values:

http://docs.cacti.net/faq#time_zone_warning


I had seen this warning while checking the apache2 error log earlier and corrected the php.ini file accordingly:

sudo vi /etc/php5/apache2/php.ini

/timezone

date.timezone = America/Toronto

:wq

The list of supported php timezones can be found here

No luck. Cacti’s log still tracked in UTC and graph timezones were still off. I read about mysql and rrdtool timezone altering etc…but both tools were fine, showing the correct system time.

finally i decided to search for any other php.ini file that might exist on my system:

sudo find / -name php.ini

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

what do you know…..

updated the alternate php.ini file accordingly….and we’re live!

wow…i need a beer.


Top
 Profile  
 
 Post subject: Re: Cacti timezone issues
PostPosted: Wed Jun 17, 2015 8:28 am 
Offline

Joined: Fri Jun 11, 2010 7:47 am
Posts: 6
Location: Hamburg
simply add this line into the file graph_image.php with your time zone
add it on the second line just under the <?php

<?php
putenv('TZ=Europe/Berlin');


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group