mirror of
https://github.com/mii443/prometheus-android-exporter.git
synced 2025-12-16 17:08:49 +00:00
keepalive
This commit is contained in:
4
client/.idea/deploymentTargetDropDown.xml
generated
4
client/.idea/deploymentTargetDropDown.xml
generated
@@ -7,11 +7,11 @@
|
|||||||
<deviceKey>
|
<deviceKey>
|
||||||
<Key>
|
<Key>
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
<type value="VIRTUAL_DEVICE_PATH" />
|
||||||
<value value="$USER_HOME$/.android/avd/X86_64_pixel.avd" />
|
<value value="$USER_HOME$/.android/avd/Pixel_XL_API_31.avd" />
|
||||||
</Key>
|
</Key>
|
||||||
</deviceKey>
|
</deviceKey>
|
||||||
</Target>
|
</Target>
|
||||||
</targetSelectedWithDropDown>
|
</targetSelectedWithDropDown>
|
||||||
<timeTargetWasSelectedWithDropDown value="2023-06-05T12:33:39.926473339Z" />
|
<timeTargetWasSelectedWithDropDown value="2023-07-11T15:42:03.701126601Z" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -103,49 +103,53 @@ dependencies {
|
|||||||
|
|
||||||
// room database end ---------------------------------------------------------------------------
|
// room database end ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// ktor
|
||||||
|
implementation "io.ktor:ktor-client-android:2.3.0"
|
||||||
|
|
||||||
// custom - tests
|
// custom - tests
|
||||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||||
androidTestUtil 'androidx.test:orchestrator:1.4.2'
|
androidTestUtil 'androidx.test:orchestrator:1.4.2'
|
||||||
|
|
||||||
// custom - work manager
|
// - work manager
|
||||||
implementation 'androidx.work:work-multiprocess:2.8.1'
|
implementation 'androidx.work:work-multiprocess:2.8.1'
|
||||||
|
|
||||||
def core_version = "1.10.1"
|
def core_version = "1.10.1"
|
||||||
|
|
||||||
// custom - prometheus client java library
|
// - prometheus client java library
|
||||||
implementation 'io.prometheus:simpleclient:0.16.0'
|
implementation 'io.prometheus:simpleclient:0.16.0'
|
||||||
implementation 'io.prometheus:simpleclient_common:0.16.0'
|
implementation 'io.prometheus:simpleclient_common:0.16.0'
|
||||||
|
|
||||||
// custom - kotlin coroutines
|
// - kotlin coroutines
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-RC"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-RC"
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0-RC"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0-RC"
|
||||||
|
|
||||||
// custom - ktor web client
|
// - ktor web client
|
||||||
implementation("io.ktor:ktor-client-core:2.3.0")
|
implementation("io.ktor:ktor-client-core:2.3.0")
|
||||||
implementation("io.ktor:ktor-client-cio:2.3.0")
|
implementation("io.ktor:ktor-client-cio:2.3.0")
|
||||||
|
|
||||||
// custom - ktor web server
|
// - ktor web server
|
||||||
implementation "io.ktor:ktor-server-cio:2.3.0"
|
implementation "io.ktor:ktor-server-cio:2.3.0"
|
||||||
implementation "io.ktor:ktor-server-core:2.3.0"
|
implementation "io.ktor:ktor-server-core:2.3.0"
|
||||||
implementation "io.ktor:ktor-server-status-pages:2.3.0"
|
implementation "io.ktor:ktor-server-status-pages:2.3.0"
|
||||||
|
|
||||||
// custom - view model for Jetpack Compose
|
// - view model for Jetpack Compose
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
|
||||||
implementation "androidx.core:core-ktx:$core_version"
|
implementation "androidx.core:core-ktx:$core_version"
|
||||||
|
|
||||||
// custom - navigation for Jetpack Compose
|
// - navigation for Jetpack Compose
|
||||||
def nav_version = "2.5.3"
|
def nav_version = "2.5.3"
|
||||||
implementation("androidx.navigation:navigation-compose:$nav_version")
|
implementation("androidx.navigation:navigation-compose:$nav_version")
|
||||||
|
|
||||||
// custom - work manager
|
// - work manager
|
||||||
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
||||||
|
|
||||||
// custom - yaml configuration parsing
|
// - yaml configuration parsing
|
||||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.1")
|
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.1")
|
||||||
implementation("com.charleskorn.kaml:kaml:0.54.0")
|
implementation("com.charleskorn.kaml:kaml:0.54.0")
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
|
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
|
||||||
|
|
||||||
// custom - protocol buffers
|
// - protocol buffers
|
||||||
implementation 'com.google.protobuf:protobuf-javalite:3.20.1'
|
implementation 'com.google.protobuf:protobuf-javalite:3.20.1'
|
||||||
implementation 'com.google.protobuf:protobuf-kotlin-lite:3.20.1'
|
implementation 'com.google.protobuf:protobuf-kotlin-lite:3.20.1'
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.PrometheusAndroidExporter"
|
android:theme="@style/Theme.PrometheusAndroidExporter"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31"
|
||||||
|
android:usesCleartextTraffic="true">
|
||||||
<activity
|
<activity
|
||||||
android:name=".compose.MainActivity"
|
android:name=".compose.MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class ExponentialBackoff {
|
|||||||
throw e
|
throw e
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// check for suppressed exceptions
|
// check for suppressed exceptions
|
||||||
|
Log.d(TAG, e.toString())
|
||||||
for (exception in e.suppressed) {
|
for (exception in e.suppressed) {
|
||||||
if (exception is CancellationException) {
|
if (exception is CancellationException) {
|
||||||
throw exception
|
throw exception
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.call.body
|
import io.ktor.client.call.body
|
||||||
|
import io.ktor.client.engine.android.Android
|
||||||
import io.ktor.client.request.post
|
import io.ktor.client.request.post
|
||||||
import io.ktor.client.request.request
|
import io.ktor.client.request.request
|
||||||
import io.ktor.client.request.setBody
|
import io.ktor.client.request.setBody
|
||||||
@@ -13,6 +14,7 @@ import io.prometheus.client.CollectorRegistry
|
|||||||
import io.prometheus.client.Counter
|
import io.prometheus.client.Counter
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
private const val TAG = "PUSHPROX_CLIENT"
|
private const val TAG = "PUSHPROX_CLIENT"
|
||||||
@@ -81,8 +83,9 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
|
|||||||
|
|
||||||
var client: HttpClient? = null
|
var client: HttpClient? = null
|
||||||
try {
|
try {
|
||||||
client = HttpClient()
|
client = createClient()
|
||||||
val context: PushProxContext = getPushProxContext(client)
|
val context: PushProxContext = getPushProxContext(client)
|
||||||
|
|
||||||
loop(context)
|
loop(context)
|
||||||
} finally {
|
} finally {
|
||||||
withContext(NonCancellable) {
|
withContext(NonCancellable) {
|
||||||
@@ -93,6 +96,16 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createClient() : HttpClient {
|
||||||
|
Log.d(TAG, "Creating http client ktor")
|
||||||
|
return HttpClient(Android) {
|
||||||
|
engine {
|
||||||
|
connectTimeout = 10_000
|
||||||
|
socketTimeout = 100_000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getPushProxContext(client: HttpClient): PushProxContext {
|
private fun getPushProxContext(client: HttpClient): PushProxContext {
|
||||||
var modifiedProxyURL = pushProxConfig.pushProxUrl.trim('/')
|
var modifiedProxyURL = pushProxConfig.pushProxUrl.trim('/')
|
||||||
|
|
||||||
@@ -171,6 +184,7 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
|
|||||||
setBody(pushRequestBody)
|
setBody(pushRequestBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pushProxConfig.countSuccessfulScrape()
|
pushProxConfig.countSuccessfulScrape()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException){
|
if (e is CancellationException){
|
||||||
|
|||||||
Reference in New Issue
Block a user