Page 1 of 2

Bulk service deletion using api very slow ?

Posted: Wed Oct 24, 2018 8:48 am
by vishfx
Hi,

NagiosXI 5.5.5 ( installed from nagiosxi repo)
OS: RHEL 7.5

Am doing bulk deletion of 2000+ services using parallel excecution nagiosxi api ( http://localhost/nagiosxi/api/v1/config/service )
It works, but the process seems to be extremely slow ( 20+ mins approx )

I do see sequential execution of the below script in the back-end :

Code: Select all

nagios   15937  0.0  0.0 113172  1200 ?        S    09:29   0:00 sh -c cd /usr/local/nagiosxi/scripts && ./ccm_delete_object.php -t service -i 8066
nagios   15938 31.0  0.4 438072 32260 ?        S    09:29   0:00 /usr/bin/php -q ./ccm_delete_object.php -t service -i 8066
Is there a way to speed this up ?

Please advise.

Regards,
Vish.

Re: Bulk service deletion using api very slow ?

Posted: Wed Oct 24, 2018 2:03 pm
by cdienger
Can you share the commands you're running against the API? Do they have the &applyconfig=1 option? This could be causing it to be slow if it is set for each command. It would be best to run most of the DELETE commands without this option and then run the final command with this option. Doing it this way removes the object and then applies the config once afterwards.

Re: Bulk service deletion using api very slow ?

Posted: Wed Oct 24, 2018 10:25 pm
by vishfx
Hi,

Below is logic used:

Code: Select all


# loop run thru deletion of 2000  services

loop for i = 1 to 2000
      curl -XDELETE  http://localhost/nagiosxi/api/v1/config/service?apikey=NAGIOSXI_APIKEY&host_name=service[i]&service_description=host[i]&force=1&pretty=1
loop ends

# runs applyconfig after services deletion
curl -XPOST   http://localhost/nagiosxi/api/v1/system/applyconfig?apikey=NAGIOSXI_APIKEY&pretty=1

Also, while performing this bulk removal noticed the below in the NagiosXI UI :

Code: Select all

Warning: mysqli_real_connect(): (HY000/1040): Too many connections in /usr/local/nagiosxi/html/db/adodb/drivers/adodb-mysqli.inc.php on line 125

Warning: mysqli_real_connect(): (HY000/1040): Too many connections in /usr/local/nagiosxi/html/db/adodb/drivers/adodb-mysqli.inc.php on line 125

Warning: mysqli_real_connect(): (08004/1040): Too many connections in /usr/local/nagiosxi/html/db/adodb/drivers/adodb-mysqli.inc.php on line 125
Databse Error
A database connection error has been detected, please follow the repair prompt below. If the issue persists, please contact Nagios support.
Run the following from the CLI as root to attempt to repair the DB:

/usr/local/nagiosxi/scripts/repair_databases.sh
Regards,
Vish.

Re: Bulk service deletion using api very slow ?

Posted: Thu Oct 25, 2018 9:47 am
by lmiltchev
Warning: mysqli_real_connect(): (HY000/1040): Too many connections in /usr/local/nagiosxi/html/db/adodb/drivers/adodb-mysqli.inc.php on line 125
I would recommend that you increase the max_connections value in the /etc/my.cnf file to a higher number. This should speed up your Nagios XI server (and the REST API commands). For more information, see our KB article on the topic:

https://support.nagios.com/kb/article/n ... s-513.html

Re: Bulk service deletion using api very slow ?

Posted: Thu Oct 25, 2018 10:09 am
by vishfx
I followed the document.

But am getting the below error:

Code: Select all

mysql -uroot -pnagiosxi -e "show variables like 'max_connections';"
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Re: Bulk service deletion using api very slow ?

Posted: Thu Oct 25, 2018 10:15 am
by lmiltchev
Did you change the root mysql password from the "default" (nagiosxi)? If you did, you would need to use the new password in the command.

Re: Bulk service deletion using api very slow ?

Posted: Mon Oct 29, 2018 10:44 pm
by vishfx
yes I managed to reset the mysql root password.

Have done the steps as per documents.

Still testing , will update shortly.

Re: Bulk service deletion using api very slow ?

Posted: Tue Oct 30, 2018 9:13 am
by lmiltchev
Sure, we will keep the thread open for the time being.

Re: Bulk service deletion using api very slow ?

Posted: Tue Oct 30, 2018 11:28 pm
by vishfx
Post changes from https://support.nagios.com/kb/article/n ... s-513.html

I no longer see the "Too many connections" error.

However, deletion of 2000+ services still takes a very long time.

Now I see the below:

Code: Select all

+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 818   |
+-----------------+-------+
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 819   |
+----------------------+-------+
Regards,
Vish.

Re: Bulk service deletion using api very slow ?

Posted: Wed Oct 31, 2018 8:53 am
by lmiltchev
How many users log in the Nagios XI server at the same time? This value (819) is quite high... You may need to increase the max_connections value in the /etc/my.cnf even more if you are reaching this number.