checking connection inside loop

I'm not @kamuslhv :)
What's the problem with adding this to `percona-agent/mysql`?