Metrics SDK
HexDroid Metrics SDK allows you to proactive monitor any device.
Setup
Add dependencies
To add core
metrics integration, add the following artifact to your build.gradle.kts
(Kotlin DSL) or
build.gradle
(Groovy):
implementation("com.hexdroid.client.metrics:core:0.0.1")
Latest version can be found on Maven Central
Install
Entry point to the metrics lib is: createReportingClient
, you can create client with the following:
import com.hexdroid.client.metrics.core.createReportingClient
val apiKey = "hexdv_xxxxxx"
val reportingClient = createReportingClient(apiKey)
After this point, you are ready to send metrics to HexDroid.
Basic usage
Metric Types
To report data, you will need to create a MetricKey
which describes what type of data that we will be reporting.
There are multiple types of MetricKey
available:
Type | Purpose |
---|---|
MetricKey.value | Best suited to report numeric (whole/decimal) numbers, for example: 'battery temperature' |
MetricKey.state | Best suited to report state values (string,bool,enums), for example 'Wifi Connected' |
MetricKey.counter | Best suited to report numeric counter values, for example 'Wifi connection error occurred' |
Report numeric data
Let's create MetricKey.value
to report battery temperature:
val batteryTemperatureMetricKey = MetricKey.value(id = "battery.temperature")
Now, we can report data:
val batteryTemperature = 25.3f
batteryTemperatureMetricKey.report(reportingClient, batteryTemperature)
Report state data
Let's create MetricKey.state
to report battery state:
val batteryStateMetricKey = MetricKey.state(id = "battery.status")
Now, we can report data:
val batteryState = "connected"
batteryStateMetricKey.report(reportingClient, batteryState)
Advanced usage
Configure
If default configuration of Metrics is not suitable, we provide a flexible builder where you can customize defaults
val reportingClient = createReportingClient(apiKey) {
delivery = testDelivery
}