protected static void registerStatsdMetricObserver ( List < MetricObserver > observers , String prefix , String host , String port ) { // verify at least hostname is set, else cannot configure this observer if ( null == host || host . trim ( ) . isEmpty ( ) ) { LOGGER . info ( "StatdsMetricObserver not configured, missing environment variable: {}" , ENV_STATSD_HOSTNAME ) ; return ; } LOGGER . debug ( "{} environment variable is: {}" , ENV_STATSD_PREFIX , prefix ) ; LOGGER . debug ( "{} environment variable is: {}" , ENV_STATSD_HOSTNAME , host ) ; LOGGER . debug ( "{} environment variable is: {}" , ENV_STATSD_PORT , port ) ; int iport = - 1 ; if ( port != null && ! port . isEmpty ( ) ) { try { iport = Integer . valueOf ( port ) ; } catch ( NumberFormatException e ) { iport = - 1 ; LOGGER . warn ( "Configured port is not an integer. Falling back to default" ) ; } } if ( iport < 0 ) { iport = 8125 ; //default statsd port LOGGER . debug ( "Using default port: " + port ) ; } LOGGER . debug ( "StatsdMetricObserver prefix: " + prefix ) ; LOGGER . debug ( "StatsdMetricObserver host: " + host ) ; LOGGER . debug ( "StatsdMetricObserver port: " + iport ) ; observers . add ( new StatsdMetricObserver ( prefix , host , iport ) ) ; }
If there is sufficient configuration register a StatsD metric observer to publish metrics . Requires at a minimum a host . Optionally can set prefix as well as port . The prefix defaults to an empty string and port defaults to 8125 .