You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2023/01/30 22:33:25 UTC
[incubator-tuweni] branch main updated: Ethstats docs
This is an automated email from the ASF dual-hosted git repository.
toulmean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/main by this push:
new 5ceee3eaf Ethstats docs
new 94b013efc Merge pull request #509 from atoulme/ethstats_docs
5ceee3eaf is described below
commit 5ceee3eaf437960ca2e5019ac69130b691fc0839
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sun Jan 29 22:23:51 2023 -0800
Ethstats docs
---
ethstats/README.md | 9 ++++
ethstats/build.gradle | 3 +-
.../opentelemetry/OpenTelemetryServerController.kt | 56 ++++++++++++++++++++++
3 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/ethstats/README.md b/ethstats/README.md
index 85d5a52d4..dcfe8e94f 100644
--- a/ethstats/README.md
+++ b/ethstats/README.md
@@ -17,5 +17,14 @@ specific language governing permissions and limitations under the License.
| Stability | [alpha] |
| Component Type | [library] |
+This library defines [`EthStatsServer`](https://tuweni.apache.org/docs/org.apache.tuweni.ethstats/-eth-stats-server/index.html),
+a server implementing the EthStats protocol. Over a websocket connection, Ethereum clients can connect and send information
+to this server.
+
+The server accepts a [EthStatsServerController](https://tuweni.apache.org/docs/org.apache.tuweni.ethstats/-eth-stats-server-controller/index.html) which will receive all the information from clients.
+
+You will need to implement your own controller. There is a controller for OpenTelemetry provided as example in this library, `OpenTelemetryServerController`.
+
+
[alpha]:https://github.com/apache/incubator-tuweni/tree/main/docs/index.md#alpha
[library]:https://github.com/apache/incubator-tuweni/tree/main/docs/index.md#library
\ No newline at end of file
diff --git a/ethstats/build.gradle b/ethstats/build.gradle
index 608fae2bd..08e89cb6d 100644
--- a/ethstats/build.gradle
+++ b/ethstats/build.gradle
@@ -11,7 +11,7 @@
* specific language governing permissions and limitations under the License.
*/
-description = 'ETHStats client library'
+description = 'ETHStats server library'
dependencies {
@@ -22,6 +22,7 @@ dependencies {
implementation 'org.bouncycastle:bcprov-jdk15on'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core'
implementation 'org.slf4j:slf4j-api'
+ compileOnly 'io.opentelemetry:opentelemetry-api'
implementation project(':bytes')
implementation project(':concurrent')
diff --git a/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/opentelemetry/OpenTelemetryServerController.kt b/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/opentelemetry/OpenTelemetryServerController.kt
new file mode 100644
index 000000000..fe5a2b1fd
--- /dev/null
+++ b/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/opentelemetry/OpenTelemetryServerController.kt
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tuweni.ethstats.opentelemetry
+
+import io.opentelemetry.api.common.AttributeKey
+import io.opentelemetry.api.common.Attributes
+import io.opentelemetry.api.metrics.Meter
+import org.apache.tuweni.ethstats.BlockStats
+import org.apache.tuweni.ethstats.EthStatsServerController
+
+/**
+ * Ethstats server controller for an OpenTelemetry meter.
+ */
+class OpenTelemetryServerController(meter: Meter) : EthStatsServerController {
+
+ private val latencyGauge = meter.gaugeBuilder("ethstats.latency").ofLongs().setUnit("ms").buildObserver()
+
+ private val latestBlockGauge = meter.gaugeBuilder("ethstats.latestBlock").ofLongs().buildObserver()
+
+ private val pendingTxCount = meter.gaugeBuilder("ethstats.pendingTx").ofLongs().buildObserver()
+
+ override fun readLatency(remoteAddress: String, id: String, latency: Long) {
+ latencyGauge.record(
+ latency,
+ Attributes.of(AttributeKey.stringKey("address"), remoteAddress, AttributeKey.stringKey("id"), id)
+ )
+ }
+
+ override fun readBlock(remoteAddress: String, id: String, block: BlockStats) {
+ latestBlockGauge.record(
+ block.number.toLong(),
+ Attributes.of(AttributeKey.stringKey("address"), remoteAddress, AttributeKey.stringKey("id"), id)
+ )
+ }
+
+ override fun readPendingTx(remoteAddress: String, id: String, pendingTx: Long) {
+ pendingTxCount.record(
+ pendingTx,
+ Attributes.of(AttributeKey.stringKey("address"), remoteAddress, AttributeKey.stringKey("id"), id)
+ )
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org