本文整理汇总了Java中com.amazonaws.services.cloudwatch.AmazonCloudWatch类的典型用法代码示例。如果您正苦于以下问题:Java AmazonCloudWatch类的具体用法?Java AmazonCloudWatch怎么用?Java AmazonCloudWatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonCloudWatch类属于com.amazonaws.services.cloudwatch包,在下文中一共展示了AmazonCloudWatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
public void start() {
int mb = 1024 * 1024;
LOG.info("Max memory: {} mb", Runtime.getRuntime().maxMemory() / mb);
LOG.info("Starting up Kinesis Consumer... (may take a few seconds)");
AmazonKinesisClient kinesisClient = new AmazonKinesisClient(kinesisCfg.getKinesisCredentialsProvider(),
kinesisCfg.getKinesisClientConfiguration());
AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient(kinesisCfg.getDynamoDBCredentialsProvider(),
kinesisCfg.getDynamoDBClientConfiguration());
AmazonCloudWatch cloudWatchClient = new AmazonCloudWatchClient(kinesisCfg.getCloudWatchCredentialsProvider(),
kinesisCfg.getCloudWatchClientConfiguration());
Worker worker = new Worker.Builder()
.recordProcessorFactory(() -> new RecordProcessor(unitOfWorkListener, exceptionStrategy, metricsCallback, dry))
.config(kinesisCfg)
.kinesisClient(kinesisClient)
.dynamoDBClient(dynamoDBClient)
.cloudWatchClient(cloudWatchClient)
.build();
worker.run();
}
示例2: amazonCloudWatchClient
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
@Bean
public AmazonCloudWatch amazonCloudWatchClient(final AWSCredentialsProvider awsCredentialsProvider,
final ClientConfiguration awsClientConfig, final Region awsRegion) {
return AmazonCloudWatchClientBuilder.standard()
.withCredentials(awsCredentialsProvider)
.withClientConfiguration(awsClientConfig)
.withRegion(awsRegion.getName())
.build();
}
示例3: main
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
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);
}
示例4: main
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
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);
}
示例5: main
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
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);
}
示例6: main
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
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;
}
}
}
示例7: CloudWatch
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
CloudWatch(AmazonCloudWatch cloudWatch, String cloudWatchNamespace, String prefix,
String application, String hostName) {
super();
assert cloudWatch != null;
assert cloudWatchNamespace != null && !cloudWatchNamespace.startsWith("AWS/")
&& cloudWatchNamespace.length() > 0 && cloudWatchNamespace.length() <= 255;
assert prefix != null;
assert application.length() >= 1 && application.length() <= 255;
assert hostName.length() >= 1 && hostName.length() <= 255;
this.awsCloudWatch = cloudWatch;
this.cloudWatchNamespace = cloudWatchNamespace;
this.prefix = prefix;
// A dimension is like a tag which can be used to filter metrics in the CloudWatch UI.
// Name and value of dimensions have min length 1 and max length 255.
dimensions.add(new Dimension().withName("application").withValue(application));
dimensions.add(new Dimension().withName("hostname").withValue(hostName));
// note: to add other dimensions (max 10), we could call
// new URL("http://instance-data/latest/meta-data/instance-id").openStream(),
// or /ami-id, /placement/availability-zone, /instance-type, /local-hostname, /local-ipv4, /public-hostname, /public-ipv4
// see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
// except that it would not work from the collector server
}
示例8: ElapsedTimeAggregatorTest
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
/**
* Default constructor
*/
public ElapsedTimeAggregatorTest() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmazonCloudWatch cloudWatchClient = mock(AmazonCloudWatch.class);
Region region = Region.getRegion(Regions.US_WEST_1);
when(ec2Client.describeTags(any(DescribeTagsRequest.class))).
thenReturn(new DescribeTagsResult());
instanceOnlyAggregator = new ElapsedTimeAggregator("TEST", region, "i-500f6ca6", null, ec2Client, cloudWatchClient);
when(ec2Client.describeTags(any(DescribeTagsRequest.class))).
thenReturn(new DescribeTagsResult().withTags(
new TagDescription().
withKey("aws:autoscaling:groupName").
withValue("TEST")
));
asgAggregator = new ElapsedTimeAggregator("TEST", region, "i-500f6ca6", null, ec2Client, cloudWatchClient);
}
示例9: CloudWatchRecorder
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
/**
* Create a new recorder instance.
* This recorder will periodically send aggregated metric events to CloudWatch
* via the provided client. Requests will be queued and sent using a
* single-threaded ScheduledExecutorService every publishFrequency (in seconds).
* The initial submission to CloudWatch will be delayed by a random amount
* on top of the publish frequency, bounded by maxJitter.
*
* The {@link #shutdown} method must be called when the application is done
* with the recorder in order to flush and stop the reporting thread.
*
* @param client Client to use for connecting to CloudWatch
* @param namespace CloudWatch namespace to publish under
* @param maxJitter Maximum delay before counting publish frequency for
* initial request, in seconds.
* A value of 0 will provide no jitter.
* @param publishFrequency Batch up and publish at this interval, in seconds.
* Suggested value of 60, for one minute aggregation.
* @param dimensionMapper Configuration specifying which dimensions to sent
* to CloudWatch for each metric event.
*/
public CloudWatchRecorder(
final AmazonCloudWatch client,
final String namespace,
final int maxJitter,
final int publishFrequency,
final DimensionMapper dimensionMapper)
{
if (client == null) {
throw new IllegalArgumentException("AmazonCloudWatch must be provided");
}
if (namespace == null || namespace.isEmpty()) {
throw new IllegalArgumentException("namespace must be provided");
}
if (dimensionMapper == null) {
throw new IllegalArgumentException("DimensionMapper must be provided");
}
this.metricsClient = client;
this.namespace = namespace;
//TODO: is there value in injecting this? Yes, but then how to handle lifecycle?
this.publishExecutor = Executors.newSingleThreadScheduledExecutor();
this.aggregator = new MetricDataAggregator(dimensionMapper);
start(maxJitter, publishFrequency);
}
示例10: record_and_shutdown
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
@Test
public void record_and_shutdown() throws Exception {
final DimensionMapper mapper = new DimensionMapper.Builder()
.addGlobalDimension(ContextData.ID)
.build();
final String namespace = "spacename";
final String id = UUID.randomUUID().toString();
final TypedMap data = ContextData.withId(id).build();
final double time = 123.45;
final AmazonCloudWatch client = mock(AmazonCloudWatch.class);
final CloudWatchRecorder recorder = new CloudWatchRecorder(client, namespace, 60, 120, mapper);
final MetricRecorder.Context context = recorder.context(data);
context.record(M_TIME, time, Unit.MILLISECOND, Instant.now());
context.close();
// shutdown right away, before first scheduled publish
recorder.shutdown();
final List<MetricDatum> expected = new ArrayList<>(1);
expected.add(makeDatum(id, M_TIME.toString(), time, time, time, 1, StandardUnit.Milliseconds));
verify(client).putMetricData(argThat(new RequestMatcher(namespace, expected)));
}
示例11: provideAmazonCloudWatch
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
@Provides
@Singleton
protected AmazonCloudWatch provideAmazonCloudWatch(Region region, AWSCredentialsProvider credentialsProvider) {
AmazonCloudWatch cloudWatch = new AmazonCloudWatchClient(credentialsProvider);
cloudWatch.setRegion(region);
return cloudWatch;
}
示例12: main
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
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;
}
}
}
示例13: main
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
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);
}
示例14: getCloudWatchClient
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
@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();
}
示例15: testPublishFilteredMetrics_metricStatFiltered
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; //导入依赖的package包/类
/**
* A metric is not fully filtered, but some stats within the metric are
*/
@Test
public void testPublishFilteredMetrics_metricStatFiltered() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
metricRegistry.meter("UnitTestMeter1").mark();
metricRegistry.meter("UnitTestMeter2").mark();
final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);
reporter =
new MetricsCloudWatchReporter(
APP_NAME,
APP_VERSION,
APP_ENVIRONMENT,
"utm1=UnitTestMeter1,utm2=UnitTestMeter2:1m:5m:15m",
2,
TimeUnit.SECONDS,
metricRegistry,
createCloudWatchFactory(amazonCloudWatch));
reporter.start();
//give the reporter a chance to publish
Thread.sleep(3000);
PutMetricDataRequestMatcher matcher = new PutMetricDataRequestMatcher(
new MetricDatumValidator("utm1.1m", APP_ENVIRONMENT, 0d),
new MetricDatumValidator("utm1.5m", APP_ENVIRONMENT, 0d),
new MetricDatumValidator("utm1.15m", APP_ENVIRONMENT, 0d),
new MetricDatumValidator("utm1.mean", APP_ENVIRONMENT, null),
new MetricDatumValidator("utm2.1m", APP_ENVIRONMENT, 0d),
new MetricDatumValidator("utm2.5m", APP_ENVIRONMENT, 0d),
new MetricDatumValidator("utm2.15m", APP_ENVIRONMENT, 0d));
Mockito.verify(amazonCloudWatch, Mockito.times(1)).putMetricData(Mockito.argThat(matcher));
}