@@ -3,6 +3,7 @@ use metrics::{
3
3
log_counter_with_labels,
4
4
log_distribution,
5
5
log_distribution_with_labels,
6
+ log_gauge_with_labels,
6
7
register_convex_counter,
7
8
register_convex_gauge,
8
9
register_convex_histogram,
@@ -491,3 +492,103 @@ register_convex_counter!(
491
492
pub fn log_large_statement ( labels : Vec < StaticMetricLabel > ) {
492
493
log_counter_with_labels ( & MYSQL_LARGE_STATEMENT_TOTAL , 1 , labels)
493
494
}
495
+
496
+ register_convex_gauge ! (
497
+ MYSQL_POOL_CONNECTION_COUNT_INFO ,
498
+ "Gauge of active connections to the database server, this includes both connections that have \
499
+ belong
500
+ to the pool, and connections currently owned by the application." ,
501
+ & [ "cluster_name" ] ,
502
+ ) ;
503
+ register_convex_gauge ! (
504
+ MYSQL_POOL_CONNECTIONS_IN_POOL_INFO ,
505
+ "Gauge of active connections that currently belong to the pool." ,
506
+ & [ "cluster_name" ] ,
507
+ ) ;
508
+ register_convex_gauge ! (
509
+ MYSQL_POOL_ACTIVE_WAIT_REQUESTS_INFO ,
510
+ "Gauge of GetConn requests that are currently active." ,
511
+ & [ "cluster_name" ] ,
512
+ ) ;
513
+ register_convex_gauge ! (
514
+ MYSQL_POOL_CREATE_FAILED_TOTAL ,
515
+ "Counter of connections that failed to be created." ,
516
+ & [ "cluster_name" ] ,
517
+ ) ;
518
+ register_convex_gauge ! (
519
+ MYSQL_POOL_DISCARDED_SUPERFLUOUS_CONNECTION_TOTAL ,
520
+ "Counter of connections discarded due to pool constraints." ,
521
+ & [ "cluster_name" ] ,
522
+ ) ;
523
+ register_convex_gauge ! (
524
+ MYSQL_POOL_DISCARDED_UNESTABLISHED_CONNECTION_TOTAL ,
525
+ "Counter of connections discarded due to being closed upon return to the pool." ,
526
+ & [ "cluster_name" ] ,
527
+ ) ;
528
+ register_convex_gauge ! (
529
+ MYSQL_POOL_DIRTY_CONNECTION_RETURN_TOTAL ,
530
+ "Counter of connections that have been returned to the pool dirty that needed to be cleaned
531
+ (ie. open transactions, pending queries, etc)." ,
532
+ & [ "cluster_name" ] ,
533
+ ) ;
534
+ register_convex_gauge ! (
535
+ MYSQL_POOL_DISCARDED_EXPIRED_CONNECTION_TOTAL ,
536
+ "Counter of connections that have been discarded as they were expired by the pool constraints." ,
537
+ & [ "cluster_name" ] ,
538
+ ) ;
539
+ register_convex_gauge ! (
540
+ MYSQL_POOL_RESETTING_CONNECTION_TOTAL ,
541
+ "Counter of connections that have been reset." ,
542
+ & [ "cluster_name" ] ,
543
+ ) ;
544
+ register_convex_gauge ! (
545
+ MYSQL_POOL_DISCARDED_ERROR_DURING_CLEANUP_TOTAL ,
546
+ "Counter of connections that have been discarded as they returned an error during cleanup." ,
547
+ & [ "cluster_name" ] ,
548
+ ) ;
549
+ register_convex_gauge ! (
550
+ MYSQL_POOL_CONNECTION_RETURNED_TO_POOL_TOTAL ,
551
+ "Counter of connections that have been returned to the pool." ,
552
+ & [ "cluster_name" ] ,
553
+ ) ;
554
+ pub fn log_pool_metrics ( cluster_name : & str , metrics : & mysql_async:: Metrics ) {
555
+ use std:: sync:: atomic:: Ordering ;
556
+ macro_rules! mysql_metric {
557
+ ( $name: ident, $gauge: ident) => {
558
+ log_gauge_with_labels(
559
+ & $gauge,
560
+ metrics. $name. load( Ordering :: Relaxed ) as f64 ,
561
+ vec![ cluster_name_label( cluster_name) ] ,
562
+ )
563
+ } ;
564
+ }
565
+ mysql_metric ! ( connection_count, MYSQL_POOL_CONNECTION_COUNT_INFO ) ;
566
+ mysql_metric ! ( connections_in_pool, MYSQL_POOL_CONNECTIONS_IN_POOL_INFO ) ;
567
+ mysql_metric ! ( active_wait_requests, MYSQL_POOL_ACTIVE_WAIT_REQUESTS_INFO ) ;
568
+ mysql_metric ! ( create_failed, MYSQL_POOL_CREATE_FAILED_TOTAL ) ;
569
+ mysql_metric ! (
570
+ discarded_superfluous_connection,
571
+ MYSQL_POOL_DISCARDED_SUPERFLUOUS_CONNECTION_TOTAL
572
+ ) ;
573
+ mysql_metric ! (
574
+ discarded_unestablished_connection,
575
+ MYSQL_POOL_DISCARDED_UNESTABLISHED_CONNECTION_TOTAL
576
+ ) ;
577
+ mysql_metric ! (
578
+ dirty_connection_return,
579
+ MYSQL_POOL_DIRTY_CONNECTION_RETURN_TOTAL
580
+ ) ;
581
+ mysql_metric ! (
582
+ discarded_expired_connection,
583
+ MYSQL_POOL_DISCARDED_EXPIRED_CONNECTION_TOTAL
584
+ ) ;
585
+ mysql_metric ! ( resetting_connection, MYSQL_POOL_RESETTING_CONNECTION_TOTAL ) ;
586
+ mysql_metric ! (
587
+ discarded_error_during_cleanup,
588
+ MYSQL_POOL_DISCARDED_ERROR_DURING_CLEANUP_TOTAL
589
+ ) ;
590
+ mysql_metric ! (
591
+ connection_returned_to_pool,
592
+ MYSQL_POOL_CONNECTION_RETURNED_TO_POOL_TOTAL
593
+ ) ;
594
+ }
0 commit comments