Database not updated in realtime !

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Developers, Moderators

Post Reply
Rno
Cacti Pro User
Posts: 704
Joined: Wed Dec 07, 2011 9:19 am

Database not updated in realtime !

Post by Rno »

Hello,
Me again, and my plugin.
I have a poller_bottom function, and when called I read a last_poll on the DB, add an offset, and check if it's time to run, if it is I update the Db then proceed.
But it's look like calling a sql_execute with an insert or update function even if I get a return of 1 (true), the DB is not update all the time !

Here is my function:
$poller_interval = read_config_option('ciscotools_check_backup');

if ($poller_interval == "0")// for the test it setup to 3600, so one hour
return;

$lp = read_config_option('ciscotools_last_poll');

if ((time() - $lp) < $poller_interval){
ciscotools_log('time: '.time().' lp: '. $lp .' poller: '. $poller_interval);
return;
}

$sql = "INSERT INTO settings VALUES ('ciscotools_last_poll','" . time() . "') ON DUPLICATE KEY UPDATE value='".time()."'";
$result = db_execute($sql);
ciscotools_log('Go time: '.time().' lp: '. $lp .' poller: '. $poller_interval.' diff: '.(time() - $lp));
ciscotools_log('sql: '.$sql.' result:'.$result);

ciscotools_checkbackup();

// the check backup for know just display this line: CISCOTOOLS need to backup :6 hosts

then my log
14/04/2020 11:46:02 - CISCOTOOLS time: 1586857562 lp: 1586857443 poller: 3600
14/04/2020 11:45:03 - CISCOTOOLS time: 1586857503 lp: 1586857443 poller: 3600
14/04/2020 11:44:03 - CISCOTOOLS need to backup :6 hosts
14/04/2020 11:44:03 - CISCOTOOLS sql: INSERT INTO settings VALUES ('ciscotools_last_poll','1586857443') ON DUPLICATE KEY UPDATE value='1586857443' result:1
14/04/2020 11:44:03 - CISCOTOOLS Go time: 1586857443 lp: 1586853543 poller: 3600 diff: 3900
14/04/2020 11:43:03 - CISCOTOOLS need to backup :6 hosts
14/04/2020 11:43:03 - CISCOTOOLS sql: INSERT INTO settings VALUES ('ciscotools_last_poll','1586857383') ON DUPLICATE KEY UPDATE value='1586857383' result:1
14/04/2020 11:43:03 - CISCOTOOLS Go time: 1586857383 lp: 1586853543 poller: 3600 diff: 3840
14/04/2020 11:42:03 - CISCOTOOLS need to backup :6 hosts
14/04/2020 11:42:03 - CISCOTOOLS sql: INSERT INTO settings VALUES ('ciscotools_last_poll','1586857323') ON DUPLICATE KEY UPDATE value='1586857323' result:1
14/04/2020 11:42:03 - CISCOTOOLS Go time: 1586857323 lp: 1586853543 poller: 3600 diff: 3780
14/04/2020 11:41:03 - CISCOTOOLS need to backup :6 hosts
14/04/2020 11:41:03 - CISCOTOOLS sql: INSERT INTO settings VALUES ('ciscotools_last_poll','1586857263') ON DUPLICATE KEY UPDATE value='1586857263' result:1
14/04/2020 11:41:03 - CISCOTOOLS Go time: 1586857263 lp: 1586853543 poller: 3600 diff: 3720
14/04/2020 11:40:03 - CISCOTOOLS need to backup :6 hosts
14/04/2020 11:40:03 - CISCOTOOLS sql: INSERT INTO settings VALUES ('ciscotools_last_poll','1586857203') ON DUPLICATE KEY UPDATE value='1586857203' result:1
14/04/2020 11:40:03 - CISCOTOOLS Go time: 1586857203 lp: 1586853543 poller: 3600 diff: 3660
14/04/2020 11:39:02 - CISCOTOOLS time: 1586857142 lp: 1586853543 poller: 3600

If you understand my log, at time (11:40:03 it's time to proceed, then the db is updated as displayed by the SQL function, and return TRUE, then the backup is executed.
But again 1 minutes later (the cacti pooler interval) everytghing is done again, and should not, since the cisco_last_pool whas supose to be updated, but it's look like it's not.
Or the first call to the DB is taken from a cache instead of the DB value.

So How can I fix this ?
force the re-cache of the DB of push to the DB to be sure ?
Or should Iupdate and read until I can read the right value ?

thanks for your help
Test
Almalinux
php 8.2.14
mariadb 10.6.16
Cacti 1.2.27
Spine 1.2.27
RRD 1.7.2
thold 1.8
monitor 2.5
syslog 3.2
flowview: 3.3
weathermap 1.0 Beta
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Database not updated in realtime !

Post by TheWitness »

Instead of all that SQL, just use the Cacti API:

set_config_option('ciscotools_last_poll', time());

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?
Rno
Cacti Pro User
Posts: 704
Joined: Wed Dec 07, 2011 9:19 am

Re: Database not updated in realtime !

Post by Rno »

Oh great, didn't saw this one,
thanks
Test
Almalinux
php 8.2.14
mariadb 10.6.16
Cacti 1.2.27
Spine 1.2.27
RRD 1.7.2
thold 1.8
monitor 2.5
syslog 3.2
flowview: 3.3
weathermap 1.0 Beta
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests