What is the best way to check that a login is possible to a database in PostgreSQL

You could do something like a classical active check which does these sort of connectivity tests (Check postgres) or perform a simple query against your database which will also confirm that connectivity is there and the basic select works.
Regarding the formatting of the performance data this would be a good help Unable to get performance metrics from check_sql - #3 by lravelo