notifications fix

This commit is contained in:
Martin Ptáček
2023-07-28 10:13:23 +02:00
parent 4696f932e8
commit bf580ba41b
8 changed files with 29 additions and 17 deletions

View File

@ -73,3 +73,5 @@ $ ansible-playbook ansible_playbook.yaml --tags config
``` ```
## List of exported metrics: ## List of exported metrics:
TODO: add grafana dashboard json here

View File

@ -7,11 +7,11 @@
<deviceKey> <deviceKey>
<Key> <Key>
<type value="VIRTUAL_DEVICE_PATH" /> <type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/new_device.avd" /> <value value="$USER_HOME$/.android/avd/new3_device.avd" />
</Key> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</targetSelectedWithDropDown> </targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-07-25T10:44:56.638251709Z" /> <timeTargetWasSelectedWithDropDown value="2023-07-27T06:47:49.277741303Z" />
</component> </component>
</project> </project>

View File

@ -29,6 +29,7 @@ android {
buildTypes { buildTypes {
release { release {
debuggable false
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }

View File

@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" /> <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application <application
android:allowBackup="true" android:allowBackup="true"

View File

@ -337,12 +337,11 @@ private fun RemoteWritePage(
TextField( TextField(
value = uiState.promConfig.remoteWriteMaxSamplesPerExport, value = uiState.promConfig.remoteWriteMaxSamplesPerExport,
singleLine = true, singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
onValueChange = { onValueChange = {
promViewModel.updatePromConfig(UpdatePromConfig.RemoteWriteMaxSamplesPerExport, it) promViewModel.updatePromConfig(UpdatePromConfig.RemoteWriteMaxSamplesPerExport, it)
}, },
label = { label = {
Text(text = "Max number of samples per export") Text(text = "Target label instance")
}, },
enabled = uiState.exporterState == ExporterState.NotRunning, enabled = uiState.exporterState == ExporterState.NotRunning,
) )
@ -350,12 +349,11 @@ private fun RemoteWritePage(
TextField( TextField(
value = uiState.promConfig.remoteWriteExportInterval, value = uiState.promConfig.remoteWriteExportInterval,
singleLine = true, singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
onValueChange = { onValueChange = {
promViewModel.updatePromConfig(UpdatePromConfig.RemoteWriteExportInterval, it) promViewModel.updatePromConfig(UpdatePromConfig.RemoteWriteExportInterval, it)
}, },
label = { label = {
Text(text = "Export interval in seconds") Text(text = "Target label job")
}, },
enabled = uiState.exporterState == ExporterState.NotRunning, enabled = uiState.exporterState == ExporterState.NotRunning,
) )

View File

@ -47,10 +47,7 @@ class AndroidCustomExporter(private val metricEngine: MetricsEngine) : Collector
"Number of steps", listOf(), "Number of steps", listOf(),
) )
Log.d(TAG, metricEngine.hwSensorsValues().numberOfSteps.toString()) gauge.addMetric(listOf(), 1.0)
metricEngine.hwSensorsValues().numberOfSteps?.let{ mfs.add(gauge)
gauge.addMetric(listOf(), it.toDouble())
mfs.add(gauge)
}
} }
} }

View File

@ -86,7 +86,8 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
val hwPropertiesManager = context.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE) as HardwarePropertiesManager val hwPropertiesManager = context.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE) as HardwarePropertiesManager
init { init {
registerAllHwEventHandlers() //TODO
//registerAllHwEventHandlers()
} }
fun hwSensorsValues(): HwSensorsCache { fun hwSensorsValues(): HwSensorsCache {
@ -107,7 +108,7 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
} }
fun dispose() { fun dispose() {
sensorManager.unregisterListener(this) //sensorManager.unregisterListener(this)
} }
override fun onSensorChanged(event: SensorEvent?) { override fun onSensorChanged(event: SensorEvent?) {
@ -256,4 +257,5 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
//TODO has_celular //TODO has_celular
//TODO has_wifi //TODO has_wifi
//TODO prefix metrics with exporter name - android_ ...
} }

View File

@ -2,6 +2,7 @@
package com.birdthedeveloper.prometheus.android.exporter.worker package com.birdthedeveloper.prometheus.android.exporter.worker
import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
@ -125,6 +126,8 @@ class PromWorker(
val inputConfiguration: PromConfiguration = PromConfiguration.fromWorkData(inputData) val inputConfiguration: PromConfiguration = PromConfiguration.fromWorkData(inputData)
Log.d(TAG, "Launching PromWorker with the following config: $inputConfiguration") Log.d(TAG, "Launching PromWorker with the following config: $inputConfiguration")
//setForeground(createForegroundInfo())
startServicesInOneThread(inputConfiguration) startServicesInOneThread(inputConfiguration)
return Result.success() return Result.success()
@ -134,23 +137,31 @@ class PromWorker(
return createForegroundInfo() return createForegroundInfo()
} }
//TODO format this thing
private fun createForegroundInfo(): ForegroundInfo { private fun createForegroundInfo(): ForegroundInfo {
// create a notification channel first
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channel_id = "CHANNEL_ID"
val channel = NotificationChannel("CHANNEL_ID",
"YOUR_CHANNEL_NAME", NotificationManager.IMPORTANCE_DEFAULT)
channel.description = "YOUR_NOTIFICATION_CHANNEL_DESCRIPTION"
mNotificationManager.createNotificationChannel(channel)
val id = "id1" val id = "id1"
val title = "title1" val title = "Prometheus android exporter running"
val cancel = "cancel1" val cancel = "cancel1"
// This PendingIntent can be used to cancel the worker // This PendingIntent can be used to cancel the worker
val intent = WorkManager.getInstance(applicationContext) val intent = WorkManager.getInstance(applicationContext)
.createCancelPendingIntent(getId()) .createCancelPendingIntent(getId())
val notification = NotificationCompat.Builder(applicationContext, id) val notification = NotificationCompat.Builder(applicationContext, channel_id)
.setContentTitle(title) .setContentTitle(title)
.setTicker(title) .setTicker(title)
.setContentText("progress1")
.setSmallIcon(R.drawable.ic_launcher_foreground) .setSmallIcon(R.drawable.ic_launcher_foreground)
.setOngoing(true) .setOngoing(true)
// Add the cancel action to the notification which can // Add the cancel action to the notification which can
// be used to cancel the worker // be used to cancel the worker
.addAction(android.R.drawable.ic_delete, cancel, intent)
.build() .build()
return ForegroundInfo(0, notification) return ForegroundInfo(0, notification)