Writing metrics to database.