16
16
*/
17
17
18
18
use prometheus_client:: {
19
- encoding:: { EncodeLabelSet , EncodeLabelValue } ,
19
+ encoding:: EncodeLabelSet ,
20
20
metrics:: { family:: Family , gauge} ,
21
21
registry:: Registry ,
22
22
} ;
23
23
24
- #[ derive( Clone , Debug , Hash , PartialEq , Eq , EncodeLabelValue ) ]
25
- pub enum ObClientRuntimeGaugeType {
26
- Default = 0 ,
27
- ConnWriter = 1 ,
28
- ConnReader = 2 ,
24
+ use crate :: monitors:: prometheus:: OBKV_CLIENT_REGISTRY ;
25
+
26
+ lazy_static ! {
27
+ pub static ref OBKV_RUNTIME_GAUGE_METRICS : RuntimeGaugeMetrics = {
28
+ let runtime_metrics = RuntimeGaugeMetrics :: default ( ) ;
29
+ runtime_metrics. register( & mut OBKV_CLIENT_REGISTRY . lock( ) . unwrap( ) . registry) ;
30
+ runtime_metrics
31
+ } ;
29
32
}
30
33
31
34
#[ derive( Clone , Debug , Hash , PartialEq , Eq , EncodeLabelSet ) ]
32
- pub struct RuntimeThreadLabels {
33
- pub rt_type : ObClientRuntimeGaugeType ,
35
+ pub struct RuntimeNameLabels {
36
+ pub string_type : String ,
34
37
}
35
38
36
39
#[ derive( Default ) ]
37
40
pub struct RuntimeGaugeMetrics {
38
- runtime_thread_alive_gauges : Family < RuntimeThreadLabels , gauge:: Gauge > ,
39
- runtime_thread_idle_gauges : Family < RuntimeThreadLabels , gauge:: Gauge > ,
41
+ runtime_thread_alive_gauges : Family < RuntimeNameLabels , gauge:: Gauge > ,
42
+ runtime_thread_idle_gauges : Family < RuntimeNameLabels , gauge:: Gauge > ,
40
43
}
41
44
42
45
impl RuntimeGaugeMetrics {
@@ -54,35 +57,95 @@ impl RuntimeGaugeMetrics {
54
57
) ;
55
58
}
56
59
57
- pub fn on_thread_start ( & self , rt_type : ObClientRuntimeGaugeType ) {
60
+ pub fn on_thread_start ( & self , rt_name : & str ) {
58
61
self . runtime_thread_alive_gauges
59
- . get_or_create ( & RuntimeThreadLabels { rt_type } )
62
+ . get_or_create ( & RuntimeNameLabels {
63
+ string_type : rt_name. to_string ( ) ,
64
+ } )
60
65
. inc ( ) ;
61
66
}
62
67
63
- pub fn on_thread_stop ( & self , rt_type : ObClientRuntimeGaugeType ) {
68
+ pub fn on_thread_stop ( & self , rt_name : & str ) {
64
69
self . runtime_thread_alive_gauges
65
- . get_or_create ( & RuntimeThreadLabels { rt_type } )
70
+ . get_or_create ( & RuntimeNameLabels {
71
+ string_type : rt_name. to_string ( ) ,
72
+ } )
66
73
. dec ( ) ;
67
74
}
68
75
69
- pub fn on_thread_park ( & self , rt_type : ObClientRuntimeGaugeType ) {
70
- self . runtime_thread_alive_gauges
71
- . get_or_create ( & RuntimeThreadLabels { rt_type } )
76
+ pub fn on_thread_park ( & self , rt_name : & str ) {
77
+ self . runtime_thread_idle_gauges
78
+ . get_or_create ( & RuntimeNameLabels {
79
+ string_type : rt_name. to_string ( ) ,
80
+ } )
72
81
. inc ( ) ;
73
82
}
74
83
75
- pub fn on_thread_unpark ( & self , rt_type : ObClientRuntimeGaugeType ) {
76
- self . runtime_thread_alive_gauges
77
- . get_or_create ( & RuntimeThreadLabels { rt_type } )
84
+ pub fn on_thread_unpark ( & self , rt_name : & str ) {
85
+ self . runtime_thread_idle_gauges
86
+ . get_or_create ( & RuntimeNameLabels {
87
+ string_type : rt_name. to_string ( ) ,
88
+ } )
78
89
. dec ( ) ;
79
90
}
80
91
81
- pub fn get_runtime_thread_alive_gauges ( & self ) -> & Family < RuntimeThreadLabels , gauge:: Gauge > {
92
+ pub fn get_runtime_thread_alive_gauges ( & self ) -> & Family < RuntimeNameLabels , gauge:: Gauge > {
82
93
& self . runtime_thread_alive_gauges
83
94
}
84
95
85
- pub fn get_runtime_thread_idle_gauges ( & self ) -> & Family < RuntimeThreadLabels , gauge:: Gauge > {
96
+ pub fn get_runtime_thread_idle_gauges ( & self ) -> & Family < RuntimeNameLabels , gauge:: Gauge > {
86
97
& self . runtime_thread_idle_gauges
87
98
}
88
99
}
100
+
101
+ /// Runtime metrics.
102
+ #[ derive( Debug ) ]
103
+ pub struct RuntimeMetrics {
104
+ pub runtime_name : String ,
105
+ }
106
+
107
+ impl RuntimeMetrics {
108
+ pub fn new ( runtime_name : & str ) -> Self {
109
+ Self {
110
+ runtime_name : runtime_name. to_owned ( ) ,
111
+ }
112
+ }
113
+
114
+ pub fn set_runtime_name ( & mut self , runtime_name : String ) {
115
+ self . runtime_name = runtime_name;
116
+ }
117
+
118
+ pub fn on_thread_start ( & self ) {
119
+ OBKV_RUNTIME_GAUGE_METRICS . on_thread_start ( & self . runtime_name ) ;
120
+ }
121
+
122
+ pub fn on_thread_stop ( & self ) {
123
+ OBKV_RUNTIME_GAUGE_METRICS . on_thread_stop ( & self . runtime_name ) ;
124
+ }
125
+
126
+ pub fn on_thread_park ( & self ) {
127
+ OBKV_RUNTIME_GAUGE_METRICS . on_thread_park ( & self . runtime_name ) ;
128
+ }
129
+
130
+ pub fn on_thread_unpark ( & self ) {
131
+ OBKV_RUNTIME_GAUGE_METRICS . on_thread_unpark ( & self . runtime_name ) ;
132
+ }
133
+
134
+ pub fn get_runtime_thread_alive_gauges ( & self ) -> i64 {
135
+ OBKV_RUNTIME_GAUGE_METRICS
136
+ . get_runtime_thread_alive_gauges ( )
137
+ . get_or_create ( & RuntimeNameLabels {
138
+ string_type : self . runtime_name . clone ( ) ,
139
+ } )
140
+ . get ( )
141
+ }
142
+
143
+ pub fn get_runtime_thread_idle_gauges ( & self ) -> i64 {
144
+ OBKV_RUNTIME_GAUGE_METRICS
145
+ . get_runtime_thread_idle_gauges ( )
146
+ . get_or_create ( & RuntimeNameLabels {
147
+ string_type : self . runtime_name . clone ( ) ,
148
+ } )
149
+ . get ( )
150
+ }
151
+ }
0 commit comments