port wmstats script to WMCore codebase

Fixes #5150