[revisitied] Time Shifter V0.2

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

[revisitied] Time Shifter V0.2

Post by gandalf »

Some days ago I introduced a new feature, the Time Shifter. Due to some discussions on the forum and work with the current Time Shifter, I decided to implement some improved version based on current 0.8.6h svn branch. Unfortunately, this patch changes five files and generates two new files for the images (images/move_left.gif and images/move_right.gif, they already were provided by the last patch) and a new ./lib/time.php module.

Installing by patch
Save your files!
./include/html/inc_timespan_settings.php
./include/html/inc_timespan_selector.php
./include/config_constants.php
./include/config_arrays.php
./include/config_settings.php
will be changed. You may need them as a backup!
This approach only works with unpatched cacti. If you already installed the fist Time Shifter version, please use the tar.gz approach.
Copy attached patch file to your current cacti directory.

Code: Select all

patch -p1 < cacti_patch_time_shifter2.patch
will patch existing files and create the new ones (the parameter is -pONE, it is a number, not the lowercase "L"). It would produce

Code: Select all

patching file images/move_left.gif
patching file images/move_right.gif
patching file include/config_arrays.php
patching file include/config_constants.php
patching file include/config_settings.php
patching file include/html/inc_timespan_selector.php
patching file include/html/inc_timespan_settings.php
patching file lib/time.php
That's all.

Installing by overwriting
Save your files!
./include/html/inc_timespan_settings.php
./include/html/inc_timespan_selector.php
./include/config_constants.php
./include/config_arrays.php
./include/config_settings.php
will be changed. You may need them as a backup!
This approach works with already patched cacti. But be careful. It OVERWRITES some existing files. Perhaps it would be better to extract the changes from the tar.gz files
- include/config_settings.php
- include/config_constants.php
- include/config_arrays.php
- include/html/inc_timespan_selector.php
- include/html/inc_timespan_settings.php
manually and apply them to your files.

Code: Select all

tar -zxvf cacti_patch_time_shifter2.tar.gz
will expand all files to their correct directories. It should produce:

Code: Select all

./
./images/
./images/move_right.gif
./images/move_left.gif
./include/
./include/html/
./include/html/inc_timespan_settings.php
./include/html/inc_timespan_selector.php
./include/config_constants.php
./include/config_arrays.php
./include/config_settings.php
./lib/
./lib/time.php
Using: new Defaults
User Management settings for each user are extended by this patch. Select the Graph Settings Tab to find three new entries that control Graph Generation. The following picture shows the default settings:

Image


Default Graph View Timeshift
Select the amount of time for shifting actions. This defaults to 1 Day. Special attention must be given to monthly shifting. But this will be explained later.

Allow Graph to extend to Future
Due to some extension of Preset, it is possible to preselect a timespan, that extends to the future (e.g. to end of current month). This checkbox allows for suppression of that, so that no graph may show times in the future. Excuse my lack of english knowledge, I can't explain this better.
For displaying graphs representing special timespans (weekly, monthly, yearly) and shifting them it is useful to have this checked.

First Day of the Week
For weekly timespans, this dropdown allows specifying the first weekday of a week. I know there are lots of people out there that use other calendars (different year definitions and the like); but I don't know much about that. So I did not implement these specialties.

Please change these values first if there is any need for this. They are stored on a "per user" basis in cacti's MySQL tables without need for table schema change.


Using: General
This patch extends the time selection bar as shown below. I had fun to provide a tooltip help using html title tags for each item on the bar.

Image


Using: new Presets
Some requests were made on the forum to allow for calendaric display, e.g. not only last week but current week (from e.g. monday to sunday) or month (from first day to last day of month). So I extended the Preset dropdown by:
  • This Day
  • This Week
  • This Month
  • This Year
  • Previous Day
  • Previous Week
  • Previous Month
  • Previous Year
Some funny date calculations were needed for this. If interested, see ./lib/time.php. Pay attention to the date fields and the Graph Legend; see this in action for This Week:

Image


And now for Previous Month:

Image



Using: new Shift Amounts
The first solution published tried to deduce the shift amount by guessing this from the timespan between current graph begin and end time. This could turn out be be way too complicated for quickly work. So I introduced a new dropdown to define the shift amount seperately. This amount is initialized to 1 Day and may be changed for each user individually (see above). So please select the appropriate Shift Amount before using the "Shift Left" or "Shift Right" arrows.

Image


The calendar magic is pure php builtin functions (strtotime, date) and confirmed to work at least with php 4.3.9. As to the PHP Site, there may be some change for php version 5; but I did not have the opportunity to check this out.

Using: true Monthly Shifting
I'm very proud to present this feature. And yes, it took me quite some time. Of course, this is not hard to understand, but let me show you some examples:
Shifting 1 Month using arbitrary begin/end times
Lets assume, Graph start at Feb, 24 at 15:00 and end at Feb, 25, 15:00. Shifting "1 Month" left will of course result in the new Graph spanning the time from Jan, 24 at 15:00 to Jan, 25 at 15:00. No magic, so far.
Shifting 1 Month using "This Month" Preset
Now lets start the Graph at Feb, 01 at 00:00 and end it at Feb, 28 at 23:59. If current time is somewhere within February, this is easily done using "This Month" Preset.

Image


What would you assume shifting "1 Month" left would result in? Wrong!
Shifting Feb, 01 at 00:00 "1 Month" left results in: Jan, 01 at 00:00.
Shifting Feb, 28 at 23:59 "1 Month" left results in: Jan, 31 at 23:59!

Image


So Monthly Shifting takes different numbers of days for the months into account. The code was made such, that begin time is checked for "begin of any month" and end time is checked for "end of any month". Begin and end need not to be related to the same month. So you may span e.g. two months manually.

Image


Shifting "1 Month" left will result in a 2 Months spanning Graph as expected.

Image


Time Shifter will not only work in Tree Mode but also in Preview Mode
As always Use this at your own risk

happy cactiing
Reinhard
Attachments
cacti_patch_time_shifter2.tar.gz
Whole files for overwriting as gzipped tar
(15.5 KiB) Downloaded 916 times
cacti_patch_time_shifter2.patch
Patch
(30.35 KiB) Downloaded 804 times
User avatar
fmangeant
Cacti Guru User
Posts: 2345
Joined: Fri Sep 19, 2003 8:36 am
Location: Sophia-Antipolis, France
Contact:

Post by fmangeant »

Many many thanks, my users will be delighted to use the "true" presets...

IMHO it would be a good idea to incorporate this addon in a 0.8.6x release.
[size=84]
[color=green]HOWTOs[/color] :
[list][*][url=http://forums.cacti.net/viewtopic.php?t=15353]Install and configure the Net-SNMP agent for Unix[/url]
[*][url=http://forums.cacti.net/viewtopic.php?t=26151]Install and configure the Net-SNMP agent for Windows[/url]
[*][url=http://forums.cacti.net/viewtopic.php?t=28175]Graph multiple servers using an SNMP proxy[/url][/list]
[color=green]Templates[/color] :
[list][*][url=http://forums.cacti.net/viewtopic.php?t=15412]Multiple CPU usage for Linux[/url]
[*][url=http://forums.cacti.net/viewtopic.php?p=125152]Memory & swap usage for Unix[/url][/list][/size]
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

fmangeant wrote:IMHO it would be a good idea to incorporate this addon in a 0.8.6x release.
I suppose, this is not possible. The devs are working on 0.9.0 code and releasing another 0.8.6 version would cause unwanted delay, I suppose
Reinhard
User avatar
TheWitness
Developer
Posts: 17059
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

Make your case with Ian.

Larry
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
davs
Posts: 28
Joined: Fri Mar 31, 2006 9:47 am
Location: paris

Post by davs »

Hi Reinhard,

I've install your patch by overwriting the files... The time shifter works but all my plugins do not work anymore :cry:

Do you have any ideas to resolved that?

Thanks a lot...
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Sorry for that.
Please use patches only when plugin arch is installed (full files are based on pure cacti, not on plugin-modified-cacti). And please see the current version at http://forums.cacti.net/viewtopic.php?t=12429
Reinhard
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests