Added NPE protection when gathering metrics