lunes, 24 de enero de 2022

¿Cómo acelerar tu zabbix server?

El que ha configurado zabbix ha observado que zabbix consume espacio para el registro histórico, registro que puede eliminarse y en el siguiente ejemplo se dejan 60 dias equivalente a casi dos meses de registro histórico, esto acelera un poco el servicio del zabbix reduciendo la cantidad de información historica de logs almacenadas en la base de datos y dejando siempre información en la base de datos. El lector puede ajustar la cantidad de tiempo que le convenga almacenar o si desea no perder esta información puede hacer un dump a estas tablas y almacenarlas en un espacio de almacenamiento histórico. El usuario puede ejecutar este script cada cierto tiempo y mantener una base de datos reducida.
#!/bin/bash
fromdate=$(date --date="60 day ago" +"%Y-%m-%d")
time mysql -u root -proot zabbix -e "
RENAME TABLE history_uint TO history_uint_old;
CREATE TABLE history_uint LIKE history_uint_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO history_uint (
SELECT * FROM history_uint_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE history_uint_old;
"

time mysql -u root -proot zabbix -e "
RENAME TABLE history_str TO history_str_old;
CREATE TABLE history_str LIKE history_str_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO history_str (
SELECT * FROM history_str_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE history_str_old;
"

time mysql -u root -proot zabbix -e "
RENAME TABLE history_log TO history_log_old;
CREATE TABLE history_log LIKE history_log_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO history_log (
SELECT * FROM history_log_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE history_log_old;
"

time mysql -u root -proot zabbix -e "
RENAME TABLE history_text TO history_text_old;
CREATE TABLE history_text LIKE history_text_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO history_text (
SELECT * FROM history_text_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE history_text_old;
"

time mysql -u root -proot zabbix -e "
RENAME TABLE history TO history_old;
CREATE TABLE history LIKE history_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO history (
SELECT * FROM history_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE history_old;
"

time mysql -u root -proot zabbix -e "
RENAME TABLE trends_uint TO trends_uint_old;
CREATE TABLE trends_uint LIKE trends_uint_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO trends_uint (
SELECT * FROM trends_uint_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE trends_uint_old;
"

time mysql -u root -proot zabbix -e "
RENAME TABLE trends TO trends_old;
CREATE TABLE trends LIKE trends_old;
SET SESSION SQL_LOG_BIN=0;
INSERT INTO trends (
SELECT * FROM trends_old WHERE clock >= UNIX_TIMESTAMP(
\"$fromdate 00:00:00\"
)
);
DROP TABLE trends_old;
"

No hay comentarios: