diff --git a/README.md b/README.md
index b2c4889..d324617 100644
--- a/README.md
+++ b/README.md
@@ -74,4 +74,9 @@ $ ansible-playbook ansible_playbook.yaml --tags config
## List of exported metrics:
-TODO: add grafana dashboard json here
\ No newline at end of file
+`android_battery_charge_ratio` - Current battery charge
+`android_system_info{manufacturer, model, os_release, cpu_core_count}` - Information about Android system
+`android_uptime_seconds` - Phone uptime in seconds
+`android_cpu_active_seconds{core}` - Active CPU time in seconds since last time system booted
+`android_cpu_total_seconds{core}` - Total CPU time in seconds since last time system booted
+`android_system_temperature_celsius{where}` - Temperature on the device
diff --git a/client/.idea/gradle.xml b/client/.idea/gradle.xml
index a2d7c21..ae388c2 100644
--- a/client/.idea/gradle.xml
+++ b/client/.idea/gradle.xml
@@ -7,6 +7,7 @@
+
diff --git a/client/app/src/main/AndroidManifest.xml b/client/app/src/main/AndroidManifest.xml
index f0c3aba..f5cdd77 100644
--- a/client/app/src/main/AndroidManifest.xml
+++ b/client/app/src/main/AndroidManifest.xml
@@ -8,6 +8,8 @@
+
+
= ArrayList()
//TODO scrape_duration gauge
+ val startTime = System.currentTimeMillis()
// metrics definitions
-// collectBatteryStatus(mfs)
-// collectGps(mfs)
- collectSteps(mfs)
+ collectBatteryChargeRatio(mfs)
+ collectUptimeInSeconds(mfs)
+// collectCpuUsage(mfs)
+ collectHasWiFiConnection(mfs)
+ collectHasCellularConnection(mfs)
+// collectDeviceTemperatures(mfs)
+ collectAndroidInfo(mfs)
+
+ collectScrapeDuration(mfs, startTime)
Log.d(TAG, "Metrics collected")
return mfs
}
-// private fun collectBatteryStatus(mfs: MutableList) {
-// //TODO
-// val batteryPercentageGauge = GaugeMetricFamily(
-// "battery_percentage", //TODO convert to ratio
-// "Current battery percentage", listOf(),
-// )
-//
-// val batteryPercentage: Double = metricsEngineRef.batteryChargeRatio().toDouble()
-// batteryPercentageGauge.addMetric(listOf(), batteryPercentage)
-// mfs.add(batteryPercentageGauge)
-// }
-
-// private fun collectGps(mfs: MutableList){
-// //TODO
-// }
-
private fun collectSteps(mfs: MutableList){
val gauge = GaugeMetricFamily(
"steps",
@@ -50,4 +43,110 @@ class AndroidCustomExporter(private val metricEngine: MetricsEngine) : Collector
gauge.addMetric(listOf(), 1.0)
mfs.add(gauge)
}
+
+ private fun collectBatteryChargeRatio(mfs : MutableList){
+ val gauge = GaugeMetricFamily(
+ "android_battery_charge_ratio",
+ "Current battery charge",
+ listOf(),
+ )
+ gauge.addMetric(listOf(), metricEngine.getBatteryChargeRatio())
+ mfs.add(gauge)
+ }
+
+ private fun collectUptimeInSeconds(mfs : MutableList){
+ val gauge = GaugeMetricFamily(
+ "android_uptime_seconds",
+ "Android uptime in seconds",
+ listOf(),
+ )
+ gauge.addMetric(listOf(), metricEngine.getUptimeInSeconds())
+ mfs.add(gauge)
+ }
+
+ //TODO this does not work
+ private fun collectCpuUsage(mfs : MutableList){
+ var coreIndex= 0
+ val cpuUsage : Array = metricEngine.getCpuUsage()
+ val gaugeActive = GaugeMetricFamily(
+ "android_cpu_active_seconds",
+ "Active CPU time in seconds since last system booted",
+ listOf("core"),
+ )
+ val gaugeTotal = GaugeMetricFamily(
+ "android_cpu_total_seconds",
+ "Total CPU time in seconds since last system booted",
+ listOf("core")
+ )
+
+ cpuUsage.forEach {
+ gaugeActive.addMetric(listOf((coreIndex++).toString()), it.active / 1000.0)
+ gaugeActive.addMetric(listOf((coreIndex++).toString()), it.total / 1000.0)
+ }
+
+ mfs.addAll(listOf(gaugeTotal, gaugeActive))
+ }
+
+ //TODO does not work
+ private fun collectDeviceTemperatures(mfs : MutableList){
+ val deviceTemperatures = metricEngine.getDeviceTemperatures()
+ val gauge = GaugeMetricFamily(
+ "android_system_temperature_celsius{where}` - ",
+ "Temperature on the device",
+ listOf("where")
+ )
+ deviceTemperatures.entries.forEach{
+ gauge.addMetric(listOf(it.key), it.value)
+ }
+ mfs.add(gauge)
+ }
+
+ private fun collectHasWiFiConnection(mfs : MutableList){
+
+ }
+
+ private fun collectHasCellularConnection(mfs : MutableList){
+
+ }
+
+ private fun collectAndroidInfo(mfs : MutableList){
+ val gauge = GaugeMetricFamily(
+ "android_system_info",
+ "Static information about the android phone",
+ listOf("manufacturer", "model", "os_release","cpu_core_count")
+ )
+ gauge.addMetric(listOf(
+ metricEngine.getAndroidManufacturer(),
+ metricEngine.getAndroidModel(),
+ metricEngine.getAndroidOsVersion(),
+ metricEngine.getNumberOfCpuCores().toString(),
+ ), 1.0)
+ mfs.add(gauge)
+ }
+
+ private fun collectNumberOfCpuCores(mfs : MutableList){
+ val gauge = GaugeMetricFamily(
+ "android_system_info",
+ "Static information about the android phone",
+ listOf("manufacturer", "model", "os_release",)
+ )
+ gauge.addMetric(listOf(
+ metricEngine.getAndroidManufacturer(),
+ metricEngine.getAndroidModel(),
+ metricEngine.getAndroidOsVersion(),
+ ), 1.0)
+ mfs.add(gauge)
+ }
+
+ private fun collectScrapeDuration(mfs : MutableList, startTime : Long){
+ val gauge = GaugeMetricFamily(
+ "android_scrape_duration_seconds",
+ "Duration of the metric scrape",
+ listOf()
+ )
+
+ val differenceMilis = System.currentTimeMillis() - startTime
+ gauge.addMetric(listOf(), differenceMilis / 1000.0)
+ mfs.add(gauge)
+ }
}
diff --git a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/exporter/worker/MetricsEngine.kt b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/exporter/worker/MetricsEngine.kt
index 6b65abf..c1398d4 100644
--- a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/exporter/worker/MetricsEngine.kt
+++ b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/exporter/worker/MetricsEngine.kt
@@ -27,10 +27,6 @@ data class AxisSpecificGauge(
)
class HwSensorsCache(
- var batteryChargeRatio : Double? = null,
- var numberOfSteps : Int? = null,
-
-
var headingDegrees : Double? = null,
var headingAccuracyDegrees : Double? = null,
var hingeAngleDegrees : Double? = null,
@@ -83,11 +79,10 @@ val temperatureTypes : Map = mapOf(
class MetricsEngine(private val context: Context) : SensorEventListener {
private val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
private val hwSensorsCache = HwSensorsCache()
- val hwPropertiesManager = context.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE) as HardwarePropertiesManager
+ private val hwPropertiesManager = context.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE) as HardwarePropertiesManager
init {
- //TODO
- //registerAllHwEventHandlers()
+ registerAllHwEventHandlers()
}
fun hwSensorsValues(): HwSensorsCache {
@@ -108,7 +103,7 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
}
fun dispose() {
- //sensorManager.unregisterListener(this)
+ sensorManager.unregisterListener(this)
}
override fun onSensorChanged(event: SensorEvent?) {
@@ -193,15 +188,7 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
// Do nothing
}
-
-// - network availability
-// - 4G, 5G
-// - ram
-// - scrape duration
-// - bluetooth - mac bluetooth
-// - storage information
-
- fun batteryChargeRatio(): Float {
+ fun getBatteryChargeRatio(): Double {
val batteryStatus: Intent? = IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { intFilter ->
context.registerReceiver(null, intFilter)
}
@@ -213,8 +200,8 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
level / scale.toFloat()
}
- batteryRatio ?: return -1.0f
- return batteryRatio
+ batteryRatio ?: return -1.0
+ return batteryRatio.toDouble()
}
fun getNumberOfCpuCores(): Int {
@@ -225,7 +212,7 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
return SystemClock.elapsedRealtime() / 1000.0
}
- fun cpuUsage() : Array {
+ fun getCpuUsage() : Array {
return hwPropertiesManager.cpuUsages
}
@@ -255,7 +242,11 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
return Build.MANUFACTURER
}
- //TODO has_celular
- //TODO has_wifi
- //TODO prefix metrics with exporter name - android_ ...
+ fun getHasCellularConnected() : Boolean {
+ TODO()
+ }
+
+ fun getHasWiFiConnected() : Boolean {
+ TODO()
+ }
}
diff --git a/server/configuration/prometheus.yaml b/server/configuration/prometheus.yaml
index 500407a..d4b39e0 100644
--- a/server/configuration/prometheus.yaml
+++ b/server/configuration/prometheus.yaml
@@ -2,7 +2,7 @@
# Prometheus global configuration file
global:
- scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
+ scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_configs:
- job_name: "prometheus"