collect event data and write to database