How to find aborted connection day wise
How to find aborted connection day wise
One important metric to monitor is the aborted connection ration,which indicated number of faild connectionsattempts relative to the total number of connection attempts.
Step.1.Now we are going to create table.
CREATE TABLE `daily_aborted_connections` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`log_date` DATE NULL DEFAULT NULL,
`aborted_connection_total` INT(11) NULL DEFAULT NULL,
`aborted_connection_yesterday` INT(11) NULL DEFAULT NULL,
`aborted_connection_today` INT(11) NULL DEFAULT NULL,
`connection_total` INT(11) NULL DEFAULT NULL,
`connection_yesterday` INT(11) NULL DEFAULT NULL,
`connection_today` INT(11) NULL DEFAULT NULL,
`aborted_connections_ration_daywise` DECIMAL(10,2) NULL DEFAULT NULL,
`log_inserted_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`log_time_ist` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=9
;
Step.2.Now we are going to create store procedure .
CREATE DEFINER=`db_user`@`%` PROCEDURE `log_aborted_connection`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE current_aborted_connections INT;
DECLARE previous_aborted_connections INT DEFAULT 0;
DECLARE daily_aborted_connectionss INT;
DECLARE aboted_connection_yesterday INT DEFAULT 0;
DECLARE current_connection INT;
DECLARE previous_connections INT DEFAULT 0;
DECLARE daily_connections INT;
DECLARE connection_yesterday INT DEFAULT 0;
DECLARE connection_today INT;
####GET the CURRENT aborrted connections.
SELECT variable_value INTO current_aborted_connections FROM performance_schema.global_status WHERE variable_name='aborted_connects';
##get the total aborted connection from the privioud day.
SELECT SUM(aborted_connection_today) INTO previous_aborted_connections FROM daily_aborted_connections;
##calculate the daily aborted connections.
SET daily_aborted_connectionss=current_aborted_connections-IFNULL(previous_aborted_connections,0);
SET previous_aborted_connections=(SELECT aborted_connection_today FROM daily_aborted_connections ORDER BY id DESC LIMIT 1);
##get the current total connection
SELECT variable_value INTO current_connection FROM performance_schema.global_status WHERE variable_name='connections';
###get the total connection from the previous day.
SELECT SUM(connection_today) INTO previous_connections FROM daily_aborted_connections;
##calculate the daily connection
SET daily_connections=current_connection-IFNULL(previous_connections,0);
SET connection_yesterday=(SELECT connection_today FROM daily_aborted_connections ORDER BY id DESC LIMIT 1);
##insert the daily aborted connections and connected into the table.
##INSERT INTO daily_aborted_connections(log_date)
INSERT INTO `daily_aborted_connections` (log_date, aborted_connection_total, aborted_connection_yesterday,aborted_connection_today,connection_total,connection_yesterday,connection_today, aborted_connections_ration_daywise)
VALUES(NOW(),current_aborted_connections,IFNULL(aboted_connection_yesterday,0),daily_aborted_connectionss,current_connection,IFNULL(connection_yesterday,0),daily_connections,
((daily_aborted_connectionss/daily_connections)*100));
END
Step.3.show sample output
Comments
Post a Comment