mirror of
https://github.com/mii443/prometheus-android-exporter.git
synced 2025-08-22 23:25:40 +00:00
added many new sensors
This commit is contained in:
16
README.md
16
README.md
@ -74,9 +74,25 @@ $ ansible-playbook ansible_playbook.yaml --tags config
|
||||
|
||||
## List of exported metrics:
|
||||
|
||||
### Android hardware sensors
|
||||
`android_sensor_heading_degrees` - Data from the Android heading sensor
|
||||
`android_sensor_proximity_metres` - Data from the proximity sensor
|
||||
`android_sensor_heading_accuracy_degrees` - Data from Android the heading sensor
|
||||
`android_sensor_hinge_angle_degrees` - How much is the hinge opened
|
||||
`android_sensor_accelerometer{axis}` - Data from the accelerometer
|
||||
`android_sensor_magnetic_field_tesla{axis}` - Data from the magnetic field sensor in base units
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
`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
|
||||
`android_scrape_duration_seconds` - Duration of the metric scrape
|
||||
|
||||
### PushProx client mode specific metrics
|
||||
`pushprox_client_poll_errors_total` - Number of errored /poll requests
|
||||
`pushprox_client_scrape_errors_total` - Total number of scrape errors the PushProx client mode has encountered
|
||||
`pushprox_client_push_errors_total` - Total number of errored /push requests
|
||||
|
@ -8,7 +8,6 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.DEVICE_POWER"/>
|
||||
|
||||
|
||||
<application
|
||||
|
@ -16,34 +16,23 @@ class AndroidCustomExporter(private val metricEngine: MetricsEngine) : Collector
|
||||
Log.d(TAG, "Collecting metrics now")
|
||||
val mfs: MutableList<MetricFamilySamples> = ArrayList()
|
||||
|
||||
//TODO scrape_duration gauge
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
// metrics definitions
|
||||
collectBatteryChargeRatio(mfs)
|
||||
collectUptimeInSeconds(mfs)
|
||||
// collectDeviceTemperatures(mfs)
|
||||
// collectCpuUsage(mfs)
|
||||
collectHasWiFiConnection(mfs)
|
||||
collectHasCellularConnection(mfs)
|
||||
// collectDeviceTemperatures(mfs)
|
||||
collectAndroidInfo(mfs)
|
||||
|
||||
collectHardwareSensors(mfs)
|
||||
collectScrapeDuration(mfs, startTime)
|
||||
|
||||
Log.d(TAG, "Metrics collected")
|
||||
return mfs
|
||||
}
|
||||
|
||||
private fun collectSteps(mfs: MutableList<MetricFamilySamples>){
|
||||
val gauge = GaugeMetricFamily(
|
||||
"steps",
|
||||
"Number of steps", listOf(),
|
||||
)
|
||||
|
||||
gauge.addMetric(listOf(), 1.0)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
private fun collectBatteryChargeRatio(mfs : MutableList<MetricFamilySamples>){
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_battery_charge_ratio",
|
||||
@ -124,20 +113,74 @@ class AndroidCustomExporter(private val metricEngine: MetricsEngine) : Collector
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
private fun collectNumberOfCpuCores(mfs : MutableList<MetricFamilySamples>){
|
||||
private fun collectHardwareSensors(mfs : MutableList<MetricFamilySamples>){
|
||||
metricEngine.hwSensorsValues().headingDegrees?.let {
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_system_info",
|
||||
"Static information about the android phone",
|
||||
listOf("manufacturer", "model", "os_release",)
|
||||
"android_sensor_heading_degrees",
|
||||
"Heading sensor data",
|
||||
listOf()
|
||||
)
|
||||
gauge.addMetric(listOf(
|
||||
metricEngine.getAndroidManufacturer(),
|
||||
metricEngine.getAndroidModel(),
|
||||
metricEngine.getAndroidOsVersion(),
|
||||
), 1.0)
|
||||
gauge.addMetric(listOf(), it)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
metricEngine.hwSensorsValues().proximityCentimeters?.let {
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_sensor_proximity_metres",
|
||||
"Data from the proximity sensor",
|
||||
listOf()
|
||||
)
|
||||
gauge.addMetric(listOf(), it / 100.0)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
metricEngine.hwSensorsValues().headingAccuracyDegrees?.let {
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_sensor_heading_accuracy_degrees",
|
||||
"Data from the heading sensor",
|
||||
listOf()
|
||||
)
|
||||
gauge.addMetric(listOf(), it)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
metricEngine.hwSensorsValues().hingeAngleDegrees?.let {
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_sensor_hinge_angle_degrees",
|
||||
"Information about how much is the hinge opened",
|
||||
listOf()
|
||||
)
|
||||
gauge.addMetric(listOf(), it)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
metricEngine.hwSensorsValues().accelerometer?.let {
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_sensor_accelerometer",
|
||||
"Accelerometer sensor data in m/s^2",
|
||||
listOf("axis")
|
||||
)
|
||||
addAxisSpecificGauge(gauge, it)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
metricEngine.hwSensorsValues().magneticFieldMicroTesla?.let {
|
||||
val coefficient = 1_000_000.0
|
||||
val baseUnits = AxisSpecificGauge(
|
||||
x = it.x / coefficient,
|
||||
y = it.y / coefficient,
|
||||
z = it.z / coefficient,
|
||||
)
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_sensor_magnetic_field_tesla",
|
||||
"Magnetic field sensor data in Tesla units",
|
||||
listOf("axis")
|
||||
)
|
||||
addAxisSpecificGauge(gauge, baseUnits)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectScrapeDuration(mfs : MutableList<MetricFamilySamples>, startTime : Long){
|
||||
val gauge = GaugeMetricFamily(
|
||||
"android_scrape_duration_seconds",
|
||||
@ -149,4 +192,10 @@ class AndroidCustomExporter(private val metricEngine: MetricsEngine) : Collector
|
||||
gauge.addMetric(listOf(), differenceMilis / 1000.0)
|
||||
mfs.add(gauge)
|
||||
}
|
||||
|
||||
private fun addAxisSpecificGauge(gauge: GaugeMetricFamily, data : AxisSpecificGauge){
|
||||
gauge.addMetric(listOf("x"), data.x)
|
||||
gauge.addMetric(listOf("y"), data.y)
|
||||
gauge.addMetric(listOf("z"), data.z)
|
||||
}
|
||||
}
|
||||
|
@ -27,20 +27,20 @@ data class AxisSpecificGauge(
|
||||
)
|
||||
|
||||
class HwSensorsCache(
|
||||
var headingDegrees : Double? = null,
|
||||
var headingAccuracyDegrees : Double? = null,
|
||||
var hingeAngleDegrees : Double? = null,
|
||||
var headingDegrees : Double? = null, //DONE
|
||||
var headingAccuracyDegrees : Double? = null, //DONE
|
||||
var hingeAngleDegrees : Double? = null, //DONE
|
||||
var offbodyDetect : Double? = null,
|
||||
var ambientTemperatureCelsius : Double? = null,
|
||||
var relativeHumidityPercent : Double? = null,
|
||||
|
||||
var accelerometer : AxisSpecificGauge? = null,
|
||||
var magneticFieldMicroTesla : AxisSpecificGauge? = null,
|
||||
var accelerometer : AxisSpecificGauge? = null, //DONE
|
||||
var magneticFieldMicroTesla : AxisSpecificGauge? = null, //DONE
|
||||
var gyroscopeRadiansPerSecond: AxisSpecificGauge? = null,
|
||||
|
||||
var ambientLightLux : Double? = null,
|
||||
var pressureHectoPascal : Double? = null,
|
||||
var proximityCentimeters : Double? = null,
|
||||
var proximityCentimeters : Double? = null, //DONE
|
||||
|
||||
var gravityAcceleration : AxisSpecificGauge? = null,
|
||||
var linearAcceleration : AxisSpecificGauge? = null,
|
||||
|
Reference in New Issue
Block a user