Example usage for com.amazonaws.util EC2MetadataUtils getInstanceType

List of usage examples for com.amazonaws.util EC2MetadataUtils getInstanceType

Introduction

In this page you can find the example usage for com.amazonaws.util EC2MetadataUtils getInstanceType.

Prototype

public static String getInstanceType() 

Source Link

Document

Get the type of the instance.

Usage

From source file:com.boundlessgeo.suite.geoserver.cloudwatch.aws.MetricDatumEncoder.java

License:Open Source License

private void setUp() {
    try {//  w ww .java  2 s  . c om
        if (enablePerInstanceMetrics) {
            amiId = EC2MetadataUtils.getAmiId();
            logger.info("Detected AMI ID of {}", amiId);
            instanceType = EC2MetadataUtils.getInstanceType();
            logger.info("Detected Instance Type = {}", instanceType);
            if (StringUtils.isBlank(instanceId)) {
                instanceId = EC2MetadataUtils.getInstanceId();
                logger.info("Detected Instance Id of {}", instanceId);
            } else
                logger.info("Instance Id overridden with {}", instanceId);
        }
        setup = true;
    } catch (Exception ex) {
        logger.error("Unable to determine AMI ID or Instance type...are we on AWS?");
        logger.error(ex.getMessage());
        //only try this once....the strings can just be empty if it fails.
        //the sender will catch it anyways
        setup = true;
    }
}