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:
TODO: add grafana dashboard json here

View File

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

View File

@ -29,6 +29,7 @@ android {
buildTypes {
release {
debuggable false
minifyEnabled false
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_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
android:allowBackup="true"

View File

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

View File

@ -47,10 +47,7 @@ class AndroidCustomExporter(private val metricEngine: MetricsEngine) : Collector
"Number of steps", listOf(),
)
Log.d(TAG, metricEngine.hwSensorsValues().numberOfSteps.toString())
metricEngine.hwSensorsValues().numberOfSteps?.let{
gauge.addMetric(listOf(), it.toDouble())
mfs.add(gauge)
}
gauge.addMetric(listOf(), 1.0)
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
init {
registerAllHwEventHandlers()
//TODO
//registerAllHwEventHandlers()
}
fun hwSensorsValues(): HwSensorsCache {
@ -107,7 +108,7 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
}
fun dispose() {
sensorManager.unregisterListener(this)
//sensorManager.unregisterListener(this)
}
override fun onSensorChanged(event: SensorEvent?) {
@ -256,4 +257,5 @@ class MetricsEngine(private val context: Context) : SensorEventListener {
//TODO has_celular
//TODO has_wifi
//TODO prefix metrics with exporter name - android_ ...
}

View File

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