From abed86ca4e43ab72d3c9c11ffbd8ab7973f7424d Mon Sep 17 00:00:00 2001 From: Gavin Towey Date: Thu, 15 May 2014 17:17:27 -0700 Subject: [PATCH] fixed timezone issue when no php default is present also fixed some permissions issues with the vagrant boostrap.sh setup process. I moved the cron job from root to vagrant user, but forgot about file permissions on the slow log file. Moved it back to root. --- conf/sample.config.inc.php | 1 + lib/Anemometer.php | 12 ++++++++++-- vagrant/bootstrap.sh | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/conf/sample.config.inc.php b/conf/sample.config.inc.php index f2c502f9..1312d987 100644 --- a/conf/sample.config.inc.php +++ b/conf/sample.config.inc.php @@ -284,6 +284,7 @@ $conn['port'] = $parts[1]; } + $conn['db'] = 'mysql'; if ($sample['db_max'] != '') { $conn['db'] = $sample['db_max']; diff --git a/lib/Anemometer.php b/lib/Anemometer.php index 555c3300..709d4035 100644 --- a/lib/Anemometer.php +++ b/lib/Anemometer.php @@ -25,6 +25,7 @@ class Anemometer { private $report_obj; private $header_printed = false; private $exception_select_fields = array('checksum','sample','DIGEST'); // column names which appear in both fact and dimension tables + private $timezone_offset; /** * Constructor. Pass in the global configuration object @@ -39,6 +40,13 @@ function __construct($conf) return; } + $timezone = ini_get('date.timezone'); + if (!$timezone) + { + date_default_timezone_set('America/Los_Angeles'); + $timezone = date_default_timezone_get(); + } + $this->timezone_offset = timezone_offset_get( new DateTimeZone( $timezone ), new DateTime()); $this->conf = $conf; $this->data_model = new AnemometerModel($conf); @@ -199,7 +207,7 @@ private function setup_data_for_graph_search($data=null) $data['ajax_table_request_url_base'] = site_url() . '?action=api&output=table&noheader=1&datasource=' . $data['datasource']. '&' . $this->report_obj->get_search_uri(array( 'dimension-'.$data['time_field_name'], 'dimension-ts_min')); $data['table_url_time_start_param'] = 'dimension-'.$data['time_field_name'].'_start'; $data['table_url_time_end_param'] = 'dimension-'.$data['time_field_name'].'_end'; - $data['timezone_offset'] = timezone_offset_get( new DateTimeZone( ini_get('date.timezone' )), new DateTime()); + $data['timezone_offset'] = $this->timezone_offset; return $data; } @@ -437,7 +445,7 @@ public function show_query() { $data['hostname_field_name'] = $this->data_model->get_field_name('hostname'); $data['checksum_field_name'] = $this->data_model->get_field_name('checksum'); - $data['timezone_offset'] = timezone_offset_get( new DateTimeZone( ini_get('date.timezone' )), new DateTime()); + $data['timezone_offset'] = $this->timezone_offset; $data['tables'] = $this->report_obj->get_tables(); if ($source_type == 'slow_query_log') diff --git a/vagrant/bootstrap.sh b/vagrant/bootstrap.sh index e1bdb61e..cca4c976 100644 --- a/vagrant/bootstrap.sh +++ b/vagrant/bootstrap.sh @@ -29,6 +29,6 @@ EOF # add cron for collection script cat << EOF > /home/vagrant/crontab -*/5 * * * * /vagrant/anemometer/scripts/anemometer_collect.sh --interval 15 --history-db-host localhost +*/5 * * * * /vagrant/anemometer/scripts/anemometer_collect.sh --interval 15 --history-db-host localhost --defaults-file /home/vagrant/.my.cnf --history-defaults-file /home/vagrant/.my.cnf EOF -crontab -u vagrant /home/vagrant/crontab +crontab -u root /home/vagrant/crontab