You should use the Asterisk pre-stop event handler to run qloaderd (which uploads queue_log data into a MySQL database for further analysis).
Create a bash script called asterisk.stop.pre and place it in the HAAst event’s directory. In that script call qloaderd with any parameters you need.