Monitoring Availability Groups can be tricky. The DMVs don’t update the log_send_rate and redo_rate all the time especially if nothing is happening so if you try to use those for calculations when monitoring you could false results worse yet pages in the middle of the night. In order to calculate the log_send_rate
Update: From time to time I get questions on this blog post and since I have wrote it dbatools has come out with method do this and if you have not checked out dbatools you should. Click here to get started with dbatools and here (Invoke-DbaQuery) to see the function
Last year I had a project that involved using database mirroring between two servers that had 20+ user databases on them and setting those up one a time takes way too long. I wrote this script to generate a script that could be run in SQLCMD mode and setup mirroring