Number of databases in a server ?
select count(*) from master.sys.databases
if you want to exclude system databases:
where database_id > 4
If you are running accross multiple servers, make sure that you have connections from a centralized server to remote servers and create a cursor to loop through each server with above query.