Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ban peers metric #3605

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions comms/src/connectivity/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ impl ConnectivityManagerActor {

self.peer_manager.ban_peer_by_node_id(node_id, duration, reason).await?;

#[cfg(feature = "metrics")]
super::metrics::banned_peers_counter(node_id).inc();

self.publish_event(ConnectivityEvent::PeerBanned(node_id.clone()));

if let Some(conn) = self.pool.get_connection_mut(node_id) {
Expand Down
17 changes: 15 additions & 2 deletions comms/src/connectivity/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::connection_manager::ConnectionDirection;
use crate::{connection_manager::ConnectionDirection, peer_manager::NodeId};
use once_cell::sync::Lazy;
use tari_metrics::{IntGauge, IntGaugeVec};
use tari_metrics::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec};

pub fn connections(direction: ConnectionDirection) -> IntGauge {
static METER: Lazy<IntGaugeVec> = Lazy::new(|| {
Expand All @@ -43,3 +43,16 @@ pub fn uptime() -> IntGauge {

METER.clone()
}

pub fn banned_peers_counter(peer: &NodeId) -> IntCounter {
static METER: Lazy<IntCounterVec> = Lazy::new(|| {
tari_metrics::register_int_counter_vec(
"comms::connectivity::banned_peers",
"The number of peer bans by peer",
&["peer_id"],
)
.unwrap()
});

METER.with_label_values(&[peer.to_string().as_str()])
}