Skip to content

Commit

Permalink
Add connections_opened metric
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Sep 19, 2024
1 parent 4853f84 commit e4047a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/src/user-guide/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ This optional interface will serve Prometheus metrics from `/metrics`. It will b
| `shotover_chain_failures_count` | `chain` | [counter](#counter) | Counts the amount of times `chain` fails |
| `shotover_chain_latency_seconds` | `chain` | [histogram](#histogram) | The latency for running `chain` |
| `shotover_chain_messages_per_batch_count` | `chain` | [histogram](#histogram) | The number of messages in each batch passing through `chain`. |
| `shotover_available_connections_count` | `source` | [gauge](#gauge) | The number of connections currently connected to `source` |
| `shotover_available_connections_count` | `source` | [gauge](#gauge) | How many more connections can be opened to `source` before new connections will be rejected. |
| `connections_opened` | `source` | [counter](#counter) | Counts the total number of connections that clients have opened against this source. |
| `shotover_source_to_sink_latency_seconds` | `sink` | [histogram](#histogram) | The milliseconds between reading a request from a source TCP connection and writing it to a sink TCP connection |
| `shotover_sink_to_source_latency_seconds` | `source` | [histogram](#histogram) | The milliseconds between reading a response from a sink TCP connection and writing it to a source TCP connection |

Expand Down
6 changes: 5 additions & 1 deletion shotover/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::{anyhow, Result};
use bytes::BytesMut;
use futures::future::join_all;
use futures::{SinkExt, StreamExt};
use metrics::{gauge, Gauge};
use metrics::{counter, gauge, Counter, Gauge};
use std::io::ErrorKind;
use std::net::SocketAddr;
use std::sync::Arc;
Expand Down Expand Up @@ -65,6 +65,7 @@ pub struct TcpCodecListener<C: CodecBuilder> {
/// Keep track of how many connections we have received so we can use it as a request id.
connection_count: u64,

connections_opened: Counter,
available_connections_gauge: Gauge,

/// Timeout after which to kill an idle connection. No timeout means connections will never be timed out.
Expand All @@ -91,6 +92,7 @@ impl<C: CodecBuilder + 'static> TcpCodecListener<C> {
) -> Result<Self, Vec<String>> {
let available_connections_gauge =
gauge!("shotover_available_connections_count", "source" => source_name.clone());
let connections_opened = counter!("connections_opened", "chain" => source_name.clone());
available_connections_gauge.set(limit_connections.available_permits() as f64);

let chain_usage_config = TransformContextConfig {
Expand Down Expand Up @@ -133,6 +135,7 @@ impl<C: CodecBuilder + 'static> TcpCodecListener<C> {
tls,
connection_count: 0,
available_connections_gauge,
connections_opened,
timeout,
connection_handles: vec![],
transport,
Expand Down Expand Up @@ -187,6 +190,7 @@ impl<C: CodecBuilder + 'static> TcpCodecListener<C> {
debug!("got socket");
self.available_connections_gauge
.set(self.limit_connections.available_permits() as f64);
self.connections_opened.increment(1);

let client_details = stream
.peer_addr()
Expand Down

0 comments on commit e4047a6

Please sign in to comment.