Getting metrics out of AWS Cloudwatch using Java API: - amazon-cloudwatch

I am trying to get metrics out of Amazon CloudWatch using the Java SDK.
I can find examples of listing out metrics. But just can't find any full example showing how to retrieve values for a metric for a given period.
Any pointers will be highly appreciated.
Thanks

Have you seen the GetMetricDataRequest documentation?
Should be straight forward. Something along these lines. (Note, I haven't tested the code).
final GetMetricDataRequest getMetricDataRequest = new GetMetricDataRequest();
final MetricDataQuery metricDataQuery = new MetricDataQuery();
metricDataQuery.setId("METRIC_ID");
final MetricStat metricStat = new MetricStat();
final Metric metric = new Metric();
final Dimension dimension = new Dimension();
nodeCountMetric.setNamespace(namespace);
dimension.setName("DIMENSION_KEY");
dimension.setValue("value");
metric.setDimensions(Collections.singletonList(dimension));
metric.setMetricName(metricName);
metricStat.setMetric(metric);
metricStat.setPeriod(SECONDS_60);
metricStat.setStat(SAMPLE_COUNT_STATISTIC);
metricDataQuery.setMetricStat(metricStat);
getMetricDataRequest.setMetricDataQueries(Collections.singletonList(metricDataQuery));
final Date endTime = new Date();
getMetricDataRequest.setEndTime(endTime);
getMetricDataRequest.setStartTime(new Date(endTime.getTime() - HOURS_3));
final AmazonCloudWatch cw =
AmazonCloudWatchClientBuilder.defaultClient();
GetMetricDataResult metricData = cw.getMetricData(metricDataRequest);

Related

How to convert of Stream of Mono to Flux or reduce a stream of Mono to a Mono using sum operation

My code is as below. I need to get a fare from mongo db for each trip, and then sum all the fares for each trip to get the total fare. I am stuck with a stream of Mono that I do not know how to read from. I tried converting this to a Flux, but I am getting a Flux<Mono>, which is not what I want. Please help!! Or how can we reduce a Stream of Mono to a Mono?
private int calculateDailyRate(final Entry<LocalDate, List<Trip>> entry) {
int dailyFare = 0;
List<Trip> trips = entry.getValue();
// Get the fare for each trip, and then sum up the list of fares to get the daily total fare
trips.stream().map(trip->fareLookupRepo.getFareRules(trip.getSecondOfDay(), trip.getTripDate().getDayOfWeek().getValue(),
trip.getFromZone(), trip.getToZone()).sort(Comparator.comparing(FareRule::getRate)).next().map(FareRule::getRate));
return dailyFare;
}
'''
I am not sure if your logic is correct, because your can be dates with entires.
But here is hint how to do what you try to achive.
return Flux.fromIterable(trips)
.flatMap(trip-> fareLookupRepo.getFareRules(trip.getSecondOfDay(), trip.getTripDate().getDayOfWeek().getValue(),
trip.getFromZone(), trip.getToZone())
.flatMap(trip-> Mono.just(trip.getRate())))
.reduce(0, (x1, x2)-> x1 + x2)
Note: fareLookupRepo.getFareRules it should return mono

NASA API into table in excel

I'm trying to download weather related data using the Nasa API into excel using powerquery.
I'm trying to query wind speed at 50 metres, the string for which is
https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?&request=execute&tempAverage=DAILY&identifier=SinglePoint&parameters=WS50M&userCommunity=SB&lon=142&lat=-38&startDate=20170101&endDate=20201231&outputList=JSON&user=DOCUMENTATION
I know this is the correct string because when I paste this as a url into my chrome browser, I get the desired output in JSON. However, when I try to get the output into a table in excel, I get a mere 2 records. Something is clearly amiss.
Any help on this will be appreciated.
Olá, utilize o power Query do excel.
let
Fonte = Json.Document(Web.Contents("https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?&request=execute&tempAverage=DAILY&identifier=SinglePoint&parameters=WS50M&userCommunity=SB&lon=142&lat=-38&startDate=20170101&endDate=20201231&outputList=JSON&user=DOCUMENTATION")),
features = Fonte[features],
features1 = features{0},
properties = features1[properties],
parameter = properties[parameter],
WS50M = parameter[WS50M]
in
WS50M

New to Python and Pandas, Looking for help aggregating observations

I am relatively new to using Python and Pandas, and was looking for help with this line of code:
`Football.ydstogo[Football.ydstogo>='11']&[Football.ydstogo<='19']= '10-plus`'
I am working with data from the NFL, and trying to build a model to predict when a team will pass, or when a team will run the ball. One of my variables (ydstogo) measures the distance for the team, with the ball, to get a first down. I am trying to group together the observations after 10 yards for ease of visualization.
When I tried running the code above, the error in my output is "can't assign to operator". I've used this code before to change gender observations to dummy variables, so I'm confused why it is not working here.
As I understand, you want to find elements with (string)
value between '11' and '19' and set a new string there.
So probably your should change your code to:
Football.ydstogo[(Football.ydstogo >= '11') & (Football.ydstogo <= '19')] = '10-plus'
Alternative:
Football.ydstogo[Football.ydstogo.between('11', '19')] = '10-plus'

How to use org.openimaj.ml.gmm to construct speaker models.

I would like to know how I can get GMM speaker model using OpenIMaj library.
org.openimaj.ml.gmm.GaussianMixtureModelEM. I have tried following
GaussianMixtureModelEM gmm = new GaussianMixtureModelEM
(DEFAULT_NUMBER_COMPONENTS,GaussianMixtureModelEM.CovarianceType.Diagonal);
MixtureOfGaussians mixture = gmm.estimate(data);
boolean convergerd = gmm.hasConverged();
I get true that GaussianMixtureModelEM has converged, I am lost where to go from here. Any help guidance would be appreciated.
Given your comment, then mixture.estimateLogProbability(point) should do what you want (see http://www.openimaj.org/apidocs/org/openimaj/math/statistics/distribution/MixtureOfGaussians.html#estimateLogProbability(double[])).

Apache Spark to add numbers from an ArrayList

I was looking for a Spark program that adds the elements of an existing Integer ArrayList.I went through all transformations and actions in apache spark but couldn't find a suitable one to just add the elements.
If someone could tell me how to write the code for the above ie add elements of an arraylist in spark , then it'll be great.
Thanks.
If you have a RDD[Int] as shown below:
val myRdd = sc.parallelize(Seq(1,2,3,4,5,6))
you could do the following to add the elements of the List:
myRdd.reduce(_+_)
res1: Int = 21
Or you could do the following as well:
myRdd.fold(0)(_+_)
res6: Int = 21
Hope it helps.