Android Library for Collecting Metrics with StatsD
Step 1: Configure Android Manifest
Add the following to AndroidManifest.xml
AND
inside the tags.
Step 2: Initialize StatsD Client within onCreate()
NonBlockingStatsDClient statsD;
@Override protected void onCreate (Bundle savedInstanceState) {
StatsDClientKey key = new StatsDClientKey ("example.prefix", "www.exampledomain.com", portNumber);
statsD = StatsDClientContainer.INSTANCE.getClient(key);
...
...
}
Step 3: Override onResume()
@Override public void onResume() { super.onResume(); NetworkStateManager.testNetworkConnectionChange(getApplicationContext());
...
...
}
Step 4: Send Metrics
-Send counter:
statsD.count("metric.name", metricValue);
-Send timer: statsD.recordExecutionTime("metric.name", metricValue);
-Send set
statsD.recordSetEvent("metric.name", "eventName");
-Send gauge
statsD.recordGaugeValue("metric.name", metricValue);
Step 5: Close StatsD Client within onDestroy()
@Override protected void onDestroy() { statsDClientContainer.closeClient(client);
OR
statsDClientContainer.closeClient("prefix", "domain", port);
...
...
}
All NonBlockingStatsDClient objects are shared across the project. If two calls to create client are made from different activites with the same prefix, domain, and port a reference to the same object will be returned in both cases.
https://w.amazon.com/index.php/Amazon_Music/Componentization/Europa
@kestingj