Skip to main content

15.1.5.2 Metrics API

MetricResourceApi provides read and write operations on time-series data. It is one of the most frequently used modules in the SDK.

Method List

MethodHTTPDescription
apiV1MetricsGetGET /api/v1/metricsQuery the metric list
apiV1MetricsIdHistoryGetGET /api/v1/metrics/{id}/historyQuery historical data for a metric
apiV1MetricsIdLatestGetGET /api/v1/metrics/{id}/latestQuery the latest value of a metric
apiV1MetricsIdDataPostPOST /api/v1/metrics/{id}/dataWrite data to a metric

Query Historical Data

Returns metric data within a specified time range, with optional aggregation.

Parameters

NameTypeRequiredDescription
idstringYesMetric ID
fromlongYesStart time, Unix millisecond timestamp
tolongYesEnd time, Unix millisecond timestamp
intervalstringNoAggregation time window, e.g. 1m, 1h. Omit to return raw data.
aggregatestringNoAggregation function: avg, max, min, sum

Returns: MetricDataDTO

Example

// Query the last 1 hour, 1-minute average
long now = System.currentTimeMillis();
long oneHourAgo = now - 3600_000L;

// See the OpenAPI spec or Swagger UI for the full method signature
// MetricResourceApi metricApi = apiClient.buildClient(MetricResourceApi.class);
// MetricDataDTO data = metricApi.apiV1MetricsIdHistoryGet(
// "metric-id-123", oneHourAgo, now, "1m", "avg");

Query Latest Value

Returns the most recent data point for a metric. Suitable for real-time monitoring scenarios.

Example

// See the OpenAPI spec or Swagger UI for the full method signature
// LatestValueDTO latest = metricApi.apiV1MetricsIdLatestGet("metric-id-123");
// System.out.println("Latest value: " + latest.getValue() + " @ " + latest.getTimestamp());
note

For the complete method signatures and parameters, refer to the OpenAPI spec file (idmp-v1.0.14.1.json) included in the SDK package, or browse the Swagger UI at /swagger-ui.html on your IDMP server.