Search in sources :

Example 1 with TypedValue

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;
}
Also used : TimeSeries(com.google.api.services.monitoring.v3.model.TimeSeries) TimeInterval(com.google.api.services.monitoring.v3.model.TimeInterval) Metric(com.google.api.services.monitoring.v3.model.Metric) Point(com.google.api.services.monitoring.v3.model.Point) Date(java.util.Date) TypedValue(com.google.api.services.monitoring.v3.model.TypedValue)

Aggregations

Metric (com.google.api.services.monitoring.v3.model.Metric)1 Point (com.google.api.services.monitoring.v3.model.Point)1 TimeInterval (com.google.api.services.monitoring.v3.model.TimeInterval)1 TimeSeries (com.google.api.services.monitoring.v3.model.TimeSeries)1 TypedValue (com.google.api.services.monitoring.v3.model.TypedValue)1 Date (java.util.Date)1