Java 类com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder 实例源码

项目:swage    文件:CloudWatchRecorder.java   
/**
 * Convenience factory method to create a CloudWatchRecorder and register a JVM
 * shutdown hook to automatically shut it down on application exit.
 * The created recorder will use its own internal client to CloudWatch,
 * using the default jitter and publish settings.
 *
 * @param namespace CloudWatch namespace to publish under.
 * @param dimensionMapper Configuration specifying which dimensions to sent
 *                        to CloudWatch for each metric event.
 * @return A CloudWatchRecorder instance that will automatically shutdown on JVM exit.
 */
public static final CloudWatchRecorder withAutoShutdown(
        final String namespace,
        final DimensionMapper dimensionMapper)
{
    CloudWatchRecorder recorder = new CloudWatchRecorder(
            AmazonCloudWatchClientBuilder.defaultClient(),
            namespace,
            DEFAULT_JITTER,
            DEFAULT_PUBLISH_FREQ,
            dimensionMapper);

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        recorder.shutdown();
    }));

    return recorder;
}
项目:aem-orchestrator    文件:AwsConfig.java   
@Bean
public AmazonCloudWatch amazonCloudWatchClient(final AWSCredentialsProvider awsCredentialsProvider, 
    final ClientConfiguration awsClientConfig, final Region awsRegion) {
    return AmazonCloudWatchClientBuilder.standard()
        .withCredentials(awsCredentialsProvider)
        .withClientConfiguration(awsClientConfig)
        .withRegion(awsRegion.getName())
        .build();
}
项目:aws-doc-sdk-examples    文件:DisableAlarmActions.java   
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply an alarm name\n" +
            "Ex: DisableAlarmActions <alarm-name>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String alarmName = args[0];

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        DisableAlarmActionsRequest request = new DisableAlarmActionsRequest()
            .withAlarmNames(alarmName);

        DisableAlarmActionsResult response = cw.disableAlarmActions(request);

        System.out.printf(
            "Successfully disabled actions on alarm %s", alarmName);
    }
项目:aws-doc-sdk-examples    文件:DeleteAlarm.java   
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply an alarm name\n" +
            "Ex: DeleteAlarm <alarm-name>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String alarm_name = args[0];

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        DeleteAlarmsRequest request = new DeleteAlarmsRequest()
            .withAlarmNames(alarm_name);

        DeleteAlarmsResult response = cw.deleteAlarms(request);

        System.out.printf("Successfully deleted alarm %s", alarm_name);
    }
项目:aws-doc-sdk-examples    文件:EnableAlarmActions.java   
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply an alarm name\n" +
            "Ex: EnableAlarmActions <alarm-name>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String alarm = args[0];

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        EnableAlarmActionsRequest request = new EnableAlarmActionsRequest()
            .withAlarmNames(alarm);

        EnableAlarmActionsResult response = cw.enableAlarmActions(request);

        System.out.printf(
            "Successfully enabled actions on alarm %s", alarm);
    }
项目:aws-doc-sdk-examples    文件:DescribeAlarms.java   
public static void main(String[] args) {

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        boolean done = false;
        DescribeAlarmsRequest request = new DescribeAlarmsRequest();

        while(!done) {

            DescribeAlarmsResult response = cw.describeAlarms(request);

            for(MetricAlarm alarm : response.getMetricAlarms()) {
                System.out.printf("Retrieved alarm %s", alarm.getAlarmName());
            }

            request.setNextToken(response.getNextToken());

            if(response.getNextToken() == null) {
                done = true;
            }
        }
    }
项目:aws-doc-sdk-examples    文件:ListMetrics.java   
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a metric name and metric namespace\n" +
            "Ex: ListMetrics <metric-name> <metric-namespace>\n";

        if (args.length != 2) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String name = args[0];
        String namespace = args[1];

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        ListMetricsRequest request = new ListMetricsRequest()
                .withMetricName(name)
                .withNamespace(namespace);

        boolean done = false;

        while(!done) {
            ListMetricsResult response = cw.listMetrics(request);

            for(Metric metric : response.getMetrics()) {
                System.out.printf(
                    "Retrieved metric %s", metric.getMetricName());
            }

            request.setNextToken(response.getNextToken());

            if(response.getNextToken() == null) {
                done = true;
            }
        }
    }
项目:aws-doc-sdk-examples    文件:PutMetricData.java   
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a data point:\n" +
            "Ex: PutMetricData <data_point>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        Double data_point = Double.parseDouble(args[0]);

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        Dimension dimension = new Dimension()
            .withName("UNIQUE_PAGES")
            .withValue("URLS");

        MetricDatum datum = new MetricDatum()
            .withMetricName("PAGES_VISITED")
            .withUnit(StandardUnit.None)
            .withValue(data_point)
            .withDimensions(dimension);

        PutMetricDataRequest request = new PutMetricDataRequest()
            .withNamespace("SITE/TRAFFIC")
            .withMetricData(datum);

        PutMetricDataResult response = cw.putMetricData(request);

        System.out.printf("Successfully put data point %f", data_point);
    }
项目:beam    文件:KinesisIO.java   
@Override
public AmazonCloudWatch getCloudWatchClient() {
  AmazonCloudWatchClientBuilder clientBuilder =
      AmazonCloudWatchClientBuilder.standard().withCredentials(getCredentialsProvider());
  if (serviceEndpoint == null) {
    clientBuilder.withRegion(region);
  } else {
    clientBuilder.withEndpointConfiguration(
        new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region.getName()));
  }
  return clientBuilder.build();
}
项目:wildfly-camel    文件:CloudWatchUtils.java   
public static AmazonCloudWatchClient createCloudWatchClient() {
    BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
    AmazonCloudWatchClient client = !credentials.isValid() ? null : (AmazonCloudWatchClient)
            AmazonCloudWatchClientBuilder.standard()
            .withCredentials(credentials)
            .withRegion("eu-west-1")
            .build();
    return client;
}
项目:panopticon    文件:CloudwatchClient.java   
public CloudwatchClient(HasCloudwatchConfig cloudwatchConfig) {
    amazonCloudWatch = AmazonCloudWatchClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(cloudwatchConfig))
            .withRegion(cloudwatchConfig.getRegion())
            .build();
}
项目:aws-doc-sdk-examples    文件:PutMetricAlarm.java   
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply an alarm name and instance id\n" +
            "Ex: DeleteAlarm <alarm-name> <instance-id>\n";

        if (args.length != 2) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String alarmName = args[0];
        String instanceId = args[1];

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        Dimension dimension = new Dimension()
            .withName("InstanceId")
            .withValue(instanceId);

        PutMetricAlarmRequest request = new PutMetricAlarmRequest()
            .withAlarmName(alarmName)
            .withComparisonOperator(
                ComparisonOperator.GreaterThanThreshold)
            .withEvaluationPeriods(1)
            .withMetricName("CPUUtilization")
            .withNamespace("AWS/EC2")
            .withPeriod(60)
            .withStatistic(Statistic.Average)
            .withThreshold(70.0)
            .withActionsEnabled(false)
            .withAlarmDescription(
                "Alarm when server CPU utilization exceeds 70%")
            .withUnit(StandardUnit.Seconds)
            .withDimensions(dimension);

        PutMetricAlarmResult response = cw.putMetricAlarm(request);

        System.out.printf(
            "Successfully created alarm with name %s", alarmName);

    }
项目:cmn-project    文件:CloudWatch.java   
public CloudWatch(AWSCredentialsProvider credentials, Regions region) {
    cloudWatch = AmazonCloudWatchClientBuilder.standard().withRegion(region).withCredentials(credentials).build();
}
项目:candlestack    文件:CloudWatchAccessor.java   
private CloudWatchAccessor() throws CandlestackException {

        metricsReaderWriter = MetricsReaderWriter.getInstance();

        detailedMonitoringEnabled = GlobalAWSProperties.isCloudWatchDetailedMonitoringEnabled();

        requestPeriod = detailedMonitoringEnabled ? DETAILED_REQUEST_PERIOD : NON_DETAILED_REQUEST_PERIOD;

        maxTimeDifference = 1000 * requestPeriod * MAX_DATA_POINTS;

        cloudWatchClient = AmazonCloudWatchClientBuilder.standard().withRegion( GlobalAWSProperties.getRegion() ).build();

        lastDatapointDateMap = new HashMap<>();

    }