From 563aae330b8e1555d34549641f29a29f255b0173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pt=C3=A1=C4=8Dek?= Date: Mon, 5 Jun 2023 22:26:07 +0200 Subject: [PATCH] wip --- README.md | 5 +++ .../exporter/worker/RemoteWriteSender.kt | 32 ++++++++++++++----- .../android/exporter/worker/ScrapeRecorder.kt | 26 +++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/ScrapeRecorder.kt diff --git a/README.md b/README.md index 251030c..ecdb5ba 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ to run as ROOT. Exposes various hardware sensor metrics. # Client +## To format code in android studio +``` +CTRL + SHIFT + ALT + L +``` + ## File configuration Client application is configurable via a configuration file. Place such file on your android device at a following path: diff --git a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/RemoteWriteSender.kt b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/RemoteWriteSender.kt index 4583e67..5a29092 100644 --- a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/RemoteWriteSender.kt +++ b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/RemoteWriteSender.kt @@ -22,18 +22,35 @@ data class RemoteWriteConfiguration( val performScrape: () -> String, //TODO this class needs it structured in objects ) +//TODO implement this thing class RemoteWriteSender(private val config: RemoteWriteConfiguration) { - //TODO implement this thing private fun getRequestBody(): ByteArray { - val label: Label = Label.newBuilder() - .setName("labelNameTest") - .setValue("labelValueTest").build() + val label1: Label = Label.newBuilder() + .setName("code") + .setValue("200").build() - val nameLabel: Label = Label.newBuilder() + val label2: Label = Label.newBuilder() + .setName("handler") + .setValue("/static/*filepath").build() + + val label3: Label = Label.newBuilder() + .setName("instance") + .setValue("localhost:9090").build() + + val label4: Label = Label.newBuilder() + .setName("job") + .setValue("prometheus").build() + + val label5: Label = Label.newBuilder() .setName("__name__") - .setValue("testremotewritemetriccccccccvv") + .setValue("prometheus_http_requests_total") + .build() + + val specialLabel: Label = Label.newBuilder() + .setName("prometheus_android_exporter") + .setValue("remote_written") .build() val sample: RemoteWrite.Sample = RemoteWrite.Sample.newBuilder() @@ -41,8 +58,7 @@ class RemoteWriteSender(private val config: RemoteWriteConfiguration) { .setTimestamp(System.currentTimeMillis()).build() val timeSeries: TimeSeries = TimeSeries.newBuilder() - .addLabels(label) - .addLabels(nameLabel) + .addAllLabels(listOf(label1, label2, label3, label4, label5, specialLabel)) .addSamples(sample) .build() diff --git a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/ScrapeRecorder.kt b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/ScrapeRecorder.kt new file mode 100644 index 0000000..140259d --- /dev/null +++ b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/worker/ScrapeRecorder.kt @@ -0,0 +1,26 @@ +package com.birdthedeveloper.prometheus.android.prometheus.android.exporter.worker + +private const val TAG = "SCRAPE_RECORDER" + +//TODO implement this thing +// mutex with last scraped time +class ScrapeRecorder{ + + //TODO mutex variable if mode is {pushprox / prometheus server} or {remote write} + //TODO go back to mode {pushprox / prometheus server} only after N succesfull scrapes and no failures + + fun countSuccesfullScrape(){ + //TODO implement this thing + // write to mutex that scrape has happend at this current time + // set timer to 2 x remote_write_scrape_interval seconds to check if next scrape has happened + } + + private fun onTimerTick(){ + //TODO implement this + // check if other scrape has happened + // if no scrape happened, go to mode {remote write} + // + + //TODO finite state machine of this stuff !!! + } +} \ No newline at end of file