@ Override public void start ( ) { try { url = new URL ( getStringSetting ( SETTING_URL , DEFAULT_STACKDRIVER_API_URL ) ) ; } catch ( MalformedURLException e ) { throw new EmbeddedJmxTransException ( e ) ; } apiKey = getStringSetting ( SETTING_TOKEN ) ; if ( getStringSetting ( SETTING_PROXY_HOST , null ) != null && ! getStringSetting ( SETTING_PROXY_HOST ) . isEmpty ( ) ) { proxy = new Proxy ( Proxy . Type . HTTP , new InetSocketAddress ( getStringSetting ( SETTING_PROXY_HOST ) , getIntSetting ( SETTING_PROXY_PORT ) ) ) ; } logger . info ( "Starting Stackdriver writer connected to '{}', proxy {} ..." , url , proxy ) ; stackdriverApiTimeoutInMillis = getIntSetting ( SETTING_STACKDRIVER_API_TIMEOUT_IN_MILLIS , DEFAULT_STACKDRIVER_API_TIMEOUT_IN_MILLIS ) ; // try to get and instance ID if ( getStringSetting ( SETTING_SOURCE_INSTANCE , null ) != null && ! getStringSetting ( SETTING_SOURCE_INSTANCE ) . isEmpty ( ) ) { // if one is set directly use that instanceId = getStringSetting ( SETTING_SOURCE_INSTANCE ) ; logger . info ( "Using instance ID {} from setting {}" , instanceId , SETTING_SOURCE_INSTANCE ) ; } else if ( getStringSetting ( SETTING_DETECT_INSTANCE , null ) != null && "AWS" . equalsIgnoreCase ( getStringSetting ( SETTING_DETECT_INSTANCE ) ) ) { // if setting is to detect, look on the local machine URL logger . info ( "Detect instance set to AWS, trying to determine AWS instance ID" ) ; instanceId = getLocalAwsInstanceId ( ) ; if ( instanceId != null ) { logger . info ( "Detected instance ID as {}" , instanceId ) ; } else { logger . info ( "Unable to detect AWS instance ID for this machine, sending metrics without an instance ID" ) ; } } else { // no instance ID, the metrics will be sent as "bare" custom metrics and not associated with an instance instanceId = null ; logger . info ( "No source instance ID passed, and not set to detect, sending metrics without and instance ID" ) ; } }
Initial setup for the writer class . Loads in settings and initializes one - time setup variables like instanceId .