Skip to content

Commit

Permalink
update tokio and add more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Oct 23, 2024
1 parent 39c4159 commit f18a791
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 19 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ hdrhistogram = { version = "7.5", default-features = false }
clap = "4.5.20"
clap_complete = "4.5.33"
#
tokio = "1.39.1"
tokio = "1.41.0"
tokio-util = "0.7"
tokio-stream = "0.1"
futures-util = "0.3"
Expand Down
1 change: 1 addition & 0 deletions g3proxy/doc/metrics/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ The following is the common tags for all metrics:
user
user_site
logger
runtime
37 changes: 37 additions & 0 deletions g3proxy/doc/metrics/runtime.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _metrics_runtime:

###############
Runtime Metrics
###############

The metrics for runtimes that support metrics.

The following are the tags for all logger metrics:

* :ref:`daemon_group <metrics_tag_daemon_group>`
* :ref:`stat_id <metrics_tag_stat_id>`

* runtime_id

Show the runtime ID / label.

There maybe many instances for the same runtime type, this field is used to distinguish between them.

.. _metrics_runtime_tokio:

Tokio Runtime Metrics
=====================

The metrics from tokio runtime.

* runtime.tokio.alive_tasks

**type**: gauge

Show the current number of alive tasks in the runtime.

* runtime.tokio.global_queue_depth

**type**: gauge

Show the number of tasks currently scheduled in the runtime's global queue.
82 changes: 82 additions & 0 deletions g3tiles/doc/configuration/values/db.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.. _configure_db_value_types:

**
DB
**

.. _conf_value_db_redis:

redis
=====

**yaml type**: map

Set the redis database address and connection params.

The following fields are supported:

* addr

**required**, **type**: :ref:`upstream str <conf_value_upstream_str>`

Set the address of the redis instance. The default port is 6379 which can be omitted.

* tls_client

**optional**, **type**: :ref:`rustls client config <conf_value_rustls_client_config>`

Enable tls and set the config.

**default**: not set

.. versionadded:: 1.9.7

* tls_name

**optional**, **type**: :ref:`tls name <conf_value_tls_name>`

Set the tls server name to verify peer certificate.

**default**: not set

.. versionadded:: 1.9.7

* db

**optional**, **type**: int

Set the database.

**default**: 0

* username

**optional**, **type**: str

Set the username for redis 6 database if needed. It is required if connect to an ACL enabled redis 6 database.

**default**: not set

* password

**optional**, **type**: str

Set the password.

**default**: not set

* connect_timeout

**optional**, **type**: :ref:`humanize duration <conf_value_humanize_duration>`

Set the connect timeout.

**default**: 5s

* response_timeout

**optional**, **type**: :ref:`humanize duration <conf_value_humanize_duration>`

Set the read timeout for redis command response.

**default**: 2s, **alias**: read_timeout
1 change: 1 addition & 0 deletions g3tiles/doc/configuration/values/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The meanings and formats of them are described as follows:

base
fs
db
network
acl
tls
Expand Down
1 change: 1 addition & 0 deletions g3tiles/doc/metrics/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ The following is the common tags for all metrics:
server
logger
backend/index
runtime
37 changes: 37 additions & 0 deletions g3tiles/doc/metrics/runtime.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _metrics_runtime:

###############
Runtime Metrics
###############

The metrics for runtimes that support metrics.

The following are the tags for all logger metrics:

* :ref:`daemon_group <metrics_tag_daemon_group>`
* :ref:`stat_id <metrics_tag_stat_id>`

* runtime_id

Show the runtime ID / label.

There maybe many instances for the same runtime type, this field is used to distinguish between them.

.. _metrics_runtime_tokio:

Tokio Runtime Metrics
=====================

The metrics from tokio runtime.

* runtime.tokio.alive_tasks

**type**: gauge

Show the current number of alive tasks in the runtime.

* runtime.tokio.global_queue_depth

**type**: gauge

Show the number of tasks currently scheduled in the runtime's global queue.
8 changes: 8 additions & 0 deletions lib/g3-daemon/src/runtime/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::metrics::TAG_KEY_STAT_ID;
const TAG_KEY_RUNTIME_ID: &str = "runtime_id";

const METRIC_NAME_RUNTIME_TOKIO_ALIVE_TASKS: &str = "runtime.tokio.alive_tasks";
const METRIC_NAME_RUNTIME_TOKIO_GLOBAL_QUEUE_DEPTH: &str = "runtime.tokio.global_queue_depth";

static TOKIO_STATS_VEC: Mutex<Vec<TokioStatsValue>> = Mutex::new(Vec::new());

Expand Down Expand Up @@ -66,4 +67,11 @@ fn emit_tokio_stats(client: &mut StatsdClient, v: &mut TokioStatsValue) {
&common_tags,
)
.send();
client
.gauge_with_tags(
METRIC_NAME_RUNTIME_TOKIO_GLOBAL_QUEUE_DEPTH,
v.stats.global_queue_depth(),
&common_tags,
)
.send();
}

0 comments on commit f18a791

Please sign in to comment.