use of com.google.api.services.monitoring.v3.model.TypedValue in project kork by spinnaker.
the class StackdriverWriter method measurementToTimeSeries.
/**
* Convert a Spectator metric Meter into a Stackdriver TimeSeries entry.
*
* @param descriptorType
* The Stackdriver MetricDescriptorType name for the measurement.
*
* @param measurement
* The Spectator Measurement to encode.
*
* @return
* The Stackdriver TimeSeries equivalent for the measurement.
*/
public TimeSeries measurementToTimeSeries(String descriptorType, Registry registry, Meter meter, Measurement measurement) {
Map<String, String> labels = cache.tagsToTimeSeriesLabels(descriptorType, measurement.id().tags());
long millis = measurement.timestamp();
double value = measurement.value();
TimeInterval timeInterval = new TimeInterval();
Date date = new Date(millis);
timeInterval.setEndTime(rfc3339.format(date));
String descriptorKind = cache.descriptorTypeToKind(descriptorType, registry, meter);
if (descriptorKind == "CUMULATIVE") {
timeInterval.setStartTime(counterStartTimeRfc3339);
}
TypedValue typedValue = new TypedValue();
typedValue.setDoubleValue(value);
Point point = new Point();
point.setValue(typedValue);
point.setInterval(timeInterval);
Metric metric = new Metric();
metric.setType(descriptorType);
metric.setLabels(labels);
TimeSeries ts = new TimeSeries();
ts.setResource(monitoredResource);
ts.setMetric(metric);
ts.setMetricKind(descriptorKind);
ts.setValueType("DOUBLE");
ts.setPoints(Lists.<Point>newArrayList(point));
return ts;
}
Aggregations