Search in sources :

Example 1 with MetricDataStream

use of org.platformlayer.metrics.model.MetricDataStream in project platformlayer by platformlayer.

the class GetMetric method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    MetricDataStream dataStream = (MetricDataStream) o;
    try {
        MetricToJsonVisitor visitor = new MetricToJsonVisitor(writer);
        dataStream.accept(visitor);
        visitor.close();
    } catch (IOException e) {
        throw new IllegalArgumentException("Error formatting results", e);
    }
}
Also used : IOException(java.io.IOException) MetricToJsonVisitor(org.platformlayer.client.cli.output.MetricToJsonVisitor) MetricDataStream(org.platformlayer.metrics.model.MetricDataStream)

Example 2 with MetricDataStream

use of org.platformlayer.metrics.model.MetricDataStream in project platformlayer by platformlayer.

the class GetMetric method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    MetricQuery query = new MetricQuery();
    query.item = getContext().pathToItem(getProject(), path);
    if (filters != null) {
        query.filters.addAll(filters);
    }
    if (projections != null) {
        query.projections.addAll(projections);
    }
    query.setFlatten(flatten);
    MetricDataStream dataStream = client.getMetric(query);
    return dataStream;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) MetricQuery(org.platformlayer.metrics.model.MetricQuery) MetricDataStream(org.platformlayer.metrics.model.MetricDataStream)

Example 3 with MetricDataStream

use of org.platformlayer.metrics.model.MetricDataStream in project platformlayer by platformlayer.

the class HttpPlatformLayerClient method getMetric.

@Override
public MetricDataStream getMetric(MetricQuery query) throws PlatformLayerClientException {
    String relativePath = buildRelativePath(query.item) + "/metrics";
    StreamingResponse response = doRequest(HttpMethod.POST, relativePath, StreamingResponse.class, Format.JSON, query, Format.XML);
    MetricDataStream dataStream;
    try {
        dataStream = JsonMetricDataStream.build(response.getResponseStream());
        // Don't close yet
        response = null;
    } catch (IOException e) {
        throw new PlatformLayerClientException("Error parsing returned data", e);
    } finally {
        Closeables.closeQuietly(response);
    }
    return dataStream;
}
Also used : IOException(java.io.IOException) JsonMetricDataStream(org.platformlayer.metrics.model.JsonMetricDataStream) MetricDataStream(org.platformlayer.metrics.model.MetricDataStream)

Aggregations

MetricDataStream (org.platformlayer.metrics.model.MetricDataStream)3 IOException (java.io.IOException)2 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 MetricToJsonVisitor (org.platformlayer.client.cli.output.MetricToJsonVisitor)1 JsonMetricDataStream (org.platformlayer.metrics.model.JsonMetricDataStream)1 MetricQuery (org.platformlayer.metrics.model.MetricQuery)1