1
1
use std:: io:: { Read , Write } ;
2
2
use std:: net:: { TcpListener , TcpStream } ;
3
- use std:: sync:: RwLock ;
3
+ use std:: sync:: { LazyLock , RwLock } ;
4
4
use std:: thread;
5
5
6
- use prometheus_client:: encoding:: text:: encode;
7
6
use prometheus_client:: encoding:: EncodeLabelSet ;
7
+ use prometheus_client:: encoding:: text:: encode;
8
8
use prometheus_client:: metrics:: counter:: Counter ;
9
9
use prometheus_client:: metrics:: family:: Family ;
10
10
use prometheus_client:: registry:: { Metric , Registry } ;
@@ -15,34 +15,43 @@ struct UdpLabels {
15
15
r#type : String ,
16
16
}
17
17
18
- lazy_static ! {
19
- static ref REGISTRY : RwLock <Registry > = RwLock :: new( <Registry >:: default ( ) ) ;
20
-
21
- // UDP sent
22
- static ref UDP_SENT_COUNT : Family <UdpLabels , Counter > = {
23
- let counter = Family :: <UdpLabels , Counter >:: default ( ) ;
24
- register( "udp_sent_count" , "Number of UDP datagrams sent" , counter. clone( ) ) ;
25
- counter
26
- } ;
27
- static ref UDP_SENT_BYTES : Family <UdpLabels , Counter > = {
28
- let counter = Family :: <UdpLabels , Counter >:: default ( ) ;
29
- register( "udp_sent_bytes" , "Number of bytes sent over UDP" , counter. clone( ) ) ;
30
- counter
31
- } ;
32
-
33
-
34
- // UDP received
35
- static ref UDP_RECEIVED_COUNT : Family <UdpLabels , Counter > = {
36
- let counter = Family :: <UdpLabels , Counter >:: default ( ) ;
37
- register( "udp_received_count" , "Number of UDP datagrams received" , counter. clone( ) ) ;
38
- counter
39
- } ;
40
- static ref UDP_RECEIVED_BYTES : Family <UdpLabels , Counter > = {
41
- let counter = Family :: <UdpLabels , Counter >:: default ( ) ;
42
- register( "udp_received_bytes" , "Number of bytes received over UDP" , counter. clone( ) ) ;
43
- counter
44
- } ;
45
- }
18
+ static REGISTRY : LazyLock < RwLock < Registry > > = LazyLock :: new ( || RwLock :: new ( Registry :: default ( ) ) ) ;
19
+ static UDP_SENT_COUNT : LazyLock < Family < UdpLabels , Counter > > = LazyLock :: new ( || {
20
+ let counter = Family :: < UdpLabels , Counter > :: default ( ) ;
21
+ register (
22
+ "udp_sent_count" ,
23
+ "Number of UDP datagrams sent" ,
24
+ counter. clone ( ) ,
25
+ ) ;
26
+ counter
27
+ } ) ;
28
+ static UDP_SENT_BYTES : LazyLock < Family < UdpLabels , Counter > > = LazyLock :: new ( || {
29
+ let counter = Family :: < UdpLabels , Counter > :: default ( ) ;
30
+ register (
31
+ "udp_sent_bytes" ,
32
+ "Number of bytes sent over UDP" ,
33
+ counter. clone ( ) ,
34
+ ) ;
35
+ counter
36
+ } ) ;
37
+ static UDP_RECEIVED_COUNT : LazyLock < Family < UdpLabels , Counter > > = LazyLock :: new ( || {
38
+ let counter = Family :: < UdpLabels , Counter > :: default ( ) ;
39
+ register (
40
+ "udp_received_count" ,
41
+ "Number of UDP datagrams received" ,
42
+ counter. clone ( ) ,
43
+ ) ;
44
+ counter
45
+ } ) ;
46
+ static UDP_RECEIVED_BYTES : LazyLock < Family < UdpLabels , Counter > > = LazyLock :: new ( || {
47
+ let counter = Family :: < UdpLabels , Counter > :: default ( ) ;
48
+ register (
49
+ "udp_received_bytes" ,
50
+ "Number of bytes received over UDP" ,
51
+ counter. clone ( ) ,
52
+ ) ;
53
+ counter
54
+ } ) ;
46
55
47
56
fn register ( name : & str , help : & str , metric : impl Metric ) {
48
57
let mut registry_w = REGISTRY . write ( ) . unwrap ( ) ;
0 commit comments