Convert Seconds to Time Format and Epoch to Readable date

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
wsaeed
Posts: 1
Joined: Tue May 13, 2014 4:24 am

Convert Seconds to Time Format and Epoch to Readable date

Post by wsaeed »

Greeting,

I have two integers in Cacti graph, and I would like to convert them as following:

1- Number of seconds to time format (days, hours and minutes):
e.g: 500000 -> 5 days, 18 hours, 53 minutes and 20 seconds.

2- Epoch to human readable date:
e.g: 1402971071 -> Tue, 17 Jun 2014 02:11:11

I believe that this can be done using CDEFs and GPRINT presets, but I couldn't figure it out. Can you please help me to resolved this issue.

In addition, please find below the output from rrdtool:

Code: Select all

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=1399896798 \
--end=1399983198 \
--title='URL Database' \
--base=1000 \
--height=120 \
--width=600 \
--alt-autoscale-max \
--lower-limit=0 \
--units-exponent='0' \
COMMENT:"From 2014/05/12 15\:13\:18 To 2014/05/13 15\:13\:18\c" \
COMMENT:"  \n" \
--vertical-label='' \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:10: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti2/rra/database_age_106.rrd":url_database_age:AVERAGE \
DEF:b="/var/www/html/cacti2/rra/database_ver_108.rrd":url_database_ver:AVERAGE \
DEF:c="/var/www/html/cacti2/rra/database_exp_107.rrd":url_database_exp:AVERAGE \
CDEF:cdefa=a,3600,/ \
AREA:cdefa#ED7600FF:"Database Age\n"  \
LINE1:cdefa#000000FF:""  \
GPRINT:cdefa:LAST:"Database Age\:\t\t%8.2lf %s\n"  \
GPRINT:b:LAST:"Database Version\:\t\t%8.0lf\n"  \
GPRINT:c:LAST:"Database Expiry Date\:\t%8.0lf %S" 
Thank you in advance
Waleed
FredZwarts
Posts: 20
Joined: Wed Feb 01, 2023 5:27 am

Re: Convert Seconds to Time Format and Epoch to Readable date

Post by FredZwarts »

I have the same wish to convert integer values to time/date. I see no replies. Did you find a solution? It seems to me that more people would like to do this, but I cannot find a solution.
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Convert Seconds to Time Format and Epoch to Readable date

Post by TheWitness »

You have to create a GPRINT Prefix to do the date formating, and then use that GPRINT Prefix when adding the GPRINT. In the example, you look to be using Normal.
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?
FredZwarts
Posts: 20
Joined: Wed Feb 01, 2023 5:27 am

Re: Convert Seconds to Time Format and Epoch to Readable date

Post by FredZwarts »

I succeeded to create a GPRINT prefix '%c:valstrftime' which produces a date/time. However, it fails again if the GPRINT in which it is used also needs a newline. But I can make a work-around for that.
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Convert Seconds to Time Format and Epoch to Readable date

Post by TheWitness »

There is a HR option for every GPRINT or comment. Use that.
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?
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests