mirror of
https://github.com/mii443/prometheus-android-exporter.git
synced 2025-08-22 15:15:35 +00:00
notifications fix
This commit is contained in:
@ -73,3 +73,5 @@ $ ansible-playbook ansible_playbook.yaml --tags config
|
||||
```
|
||||
|
||||
## List of exported metrics:
|
||||
|
||||
TODO: add grafana dashboard json here
|
4
client/.idea/deploymentTargetDropDown.xml
generated
4
client/.idea/deploymentTargetDropDown.xml
generated
@ -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>
|
@ -29,6 +29,7 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
debuggable false
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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_ ...
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user