@@ -26,6 +26,28 @@ impl Default for DbMetrics {
2626impl DbMetrics {
2727 /// Creates a new instance of database metrics.
2828 pub fn new ( ) -> Self {
29+ // database tables metrics
30+ :: metrics:: describe_gauge!(
31+ "db.table_size" ,
32+ :: metrics:: Unit :: Bytes ,
33+ "Total size of the table"
34+ ) ;
35+ :: metrics:: describe_gauge!(
36+ "db.table_pages" ,
37+ :: metrics:: Unit :: Count ,
38+ "Number of pages in the table"
39+ ) ;
40+ :: metrics:: describe_gauge!(
41+ "db.table_entries" ,
42+ :: metrics:: Unit :: Count ,
43+ "Number of entries in the table"
44+ ) ;
45+ :: metrics:: describe_gauge!(
46+ "db.freelist" ,
47+ :: metrics:: Unit :: Bytes ,
48+ "Size of the database freelist"
49+ ) ;
50+
2951 Self {
3052 inner : Arc :: new ( DbMetricsInner {
3153 transaction : DbTransactionMetrics :: default ( ) ,
@@ -35,21 +57,27 @@ impl DbMetrics {
3557 }
3658
3759 /// Records a transaction creation.
38- pub fn record_tx_create ( & self , is_write : bool ) {
39- if is_write {
40- self . inner . transaction . rw_created . increment ( 1 ) ;
41- } else {
42- self . inner . transaction . ro_created . increment ( 1 ) ;
43- }
60+ pub fn record_ro_tx_create ( & self ) {
61+ self . inner . transaction . ro_created . increment ( 1 ) ;
62+ }
63+
64+ pub fn record_rw_tx_create ( & self ) {
65+ self . inner . transaction . rw_created . increment ( 1 ) ;
4466 }
4567
4668 /// Records a transaction commit with timing.
69+ ///
70+ /// ## Arguments
71+ ///
72+ /// * `duration` - Time taken for the get operation in seconds
73+ /// * `success` - Whether the commit operation completed sucessfully or not.
4774 pub fn record_tx_commit ( & self , duration : f64 , success : bool ) {
4875 if success {
4976 self . inner . transaction . commits_successful . increment ( 1 ) ;
5077 } else {
5178 self . inner . transaction . commits_failed . increment ( 1 ) ;
5279 }
80+
5381 self . inner . transaction . commit_time_seconds . record ( duration) ;
5482 }
5583
@@ -59,32 +87,51 @@ impl DbMetrics {
5987 }
6088
6189 /// Records a get operation.
90+ ///
91+ /// ## Arguments
92+ ///
93+ /// * `duration` - Time taken for the get operation in seconds
94+ /// * `found` - Whether the requested value was found
6295 pub fn record_get ( & self , duration : f64 , found : bool ) {
6396 if found {
6497 self . inner . operations . get_hits . increment ( 1 ) ;
6598 } else {
6699 self . inner . operations . get_misses . increment ( 1 ) ;
67100 }
101+
68102 self . inner . operations . get_time_seconds . record ( duration) ;
69103 }
70104
71105 /// Records a put operation.
106+ ///
107+ /// ## Arguments
108+ ///
109+ /// * `duration` - Time taken for the put operation in seconds
72110 pub fn record_put ( & self , duration : f64 ) {
73111 self . inner . operations . puts . increment ( 1 ) ;
74112 self . inner . operations . put_time_seconds . record ( duration) ;
75113 }
76114
77115 /// Records a delete operation.
116+ ///
117+ /// ## Arguments
118+ ///
119+ /// * `duration` - Time taken for the delete operation in seconds
78120 pub fn record_delete ( & self , duration : f64 , deleted : bool ) {
79121 if deleted {
80122 self . inner . operations . deletes_successful . increment ( 1 ) ;
81123 } else {
82124 self . inner . operations . deletes_failed . increment ( 1 ) ;
83125 }
126+
84127 self . inner . operations . delete_time_seconds . record ( duration) ;
85128 }
86129
87130 /// Records a clear operation.
131+ ///
132+ /// ## Arguments
133+ ///
134+ /// * `duration` - Time taken for the clear operation in seconds
88135 pub fn record_clear ( & self , duration : f64 ) {
89136 self . inner . operations . clears . increment ( 1 ) ;
90137 self . inner . operations . clear_time_seconds . record ( duration) ;
0 commit comments