This project contains a library for use in Java applications to post custom metrics to Stackdriver using our https gateway.
Stackdriver Custom Metrics Guide
Releases of this project are available via Maven Central. Here's how to import the 0.3 release
<dependency>
<groupId>com.stackdriver</groupId>
<artifactId>stackdriver-custommetrics</artifactId>
<version>0.3</version>
</dependency>
Here are some examples for how to use this code in your projects. The package import is com.stackdriver.api.custommetrics
and the main
class is CustomMetricsPoster
. Items in ALL CAPS below are meant to be placeholders for your values and will need to be substituted.
YOUR_API_KEY - insert the API key you generated in Stackdriver
YOUR_METRIC_NAME - custom metric name. Related ones should have similar names so they can be wildcarded
POINT_VALUE - observation of the metric value
COLLECTED_AT_DATE - Java Date object that indicates when the observation took place
CURRENT_INSTANCE_ID - AWS or Rackspace Cloud instance ID for the instance that the metric applies to, when applicable
import com.stackdriver.api.custommetrics.CustomMetricsPoster
new CustomMetricsPoster(YOUR_API_KEY).sendMetricDataPoint(YOUR_METRIC_NAME, POINT_VALUE);
new CustomMetricsPoster(YOUR_API_KEY).sendMetricDataPoint(YOUR_METRIC_NAME, POINT_VALUE).sendMetricDataPoint(SECOND_METRIC_NAME, SECOND POINT VALUE);
new CustomMetricsPoster(YOUR_API_KEY).sendInstanceMetricDataPoint(YOUR_METRIC_NAME, POINT_VALUE, CURRENT_INSTANCE_ID);
new CustomMetricsPoster(YOUR_API_KEY).sendMetricDataPoint(YOUR_METRIC_NAME, POINT_VALUE, COLLECTED_AT_DATE);
new CustomMetricsPoster(YOUR_API_KEY).sendInstanceMetricDataPoint(YOUR_METRIC_NAME, POINT_VALUE, COLLECTED_AT_DATE, CURRENT_INSTANCE_ID);