11import time
2+
23from prometheus_client import Counter , Histogram
34
45
@@ -9,7 +10,6 @@ class SwarmMetrics:
910 """
1011
1112 def __init__ (self ):
12-
1313 # ---------------------------
1414 # incoming connections
1515 # ---------------------------
@@ -40,19 +40,14 @@ def __init__(self):
4040 "swarm_connections_establishment_duration_seconds" ,
4141 "Time taken to establish connection" ,
4242 ["role" , "protocols" ],
43- buckets = (
44- 0.01 , 0.02 , 0.05 , 0.1 ,
45- 0.2 , 0.5 , 1 , 2 , 5 , 10
46- ),
43+ buckets = (0.01 , 0.02 , 0.05 , 0.1 , 0.2 , 0.5 , 1 , 2 , 5 , 10 ),
4744 )
4845
4946 self .connections_duration = Histogram (
5047 "swarm_connections_duration_seconds" ,
5148 "Time a connection was alive" ,
5249 ["role" , "protocols" , "cause" ],
53- buckets = (
54- 0.01 , 0.1 , 1 , 5 , 10 , 30 , 60 , 300 , 600
55- ),
50+ buckets = (0.01 , 0.1 , 1 , 5 , 10 , 30 , 60 , 300 , 600 ),
5651 )
5752
5853 # ---------------------------
@@ -135,11 +130,9 @@ def record(self, event):
135130 """
136131 Record a SwarmEvent-like object.
137132 """
138-
139133 etype = event ["type" ]
140134
141135 if etype == "ConnectionEstablished" :
142-
143136 role = event ["role" ]
144137 protocols = event ["protocols" ]
145138 conn_id = event ["connection_id" ]
@@ -158,7 +151,6 @@ def record(self, event):
158151 self .connections [conn_id ] = time .time ()
159152
160153 elif etype == "ConnectionClosed" :
161-
162154 conn_id = event ["connection_id" ]
163155 role = event ["role" ]
164156 protocols = event ["protocols" ]
@@ -174,65 +166,40 @@ def record(self, event):
174166 ).observe (elapsed )
175167
176168 elif etype == "IncomingConnection" :
177-
178- self .connections_incoming .labels (
179- protocols = event ["protocols" ]
180- ).inc ()
169+ self .connections_incoming .labels (protocols = event ["protocols" ]).inc ()
181170
182171 elif etype == "IncomingConnectionError" :
183-
184172 self .connections_incoming_error .labels (
185173 error = event ["error" ],
186174 protocols = event ["protocols" ],
187175 ).inc ()
188176
189177 elif etype == "OutgoingConnectionError" :
190-
191178 self .outgoing_connection_error .labels (
192179 peer = event ["peer" ],
193180 error = event ["error" ],
194181 ).inc ()
195182
196183 elif etype == "NewListenAddr" :
197-
198- self .new_listen_addr .labels (
199- protocols = event ["protocols" ]
200- ).inc ()
184+ self .new_listen_addr .labels (protocols = event ["protocols" ]).inc ()
201185
202186 elif etype == "ExpiredListenAddr" :
203-
204- self .expired_listen_addr .labels (
205- protocols = event ["protocols" ]
206- ).inc ()
187+ self .expired_listen_addr .labels (protocols = event ["protocols" ]).inc ()
207188
208189 elif etype == "ListenerClosed" :
209-
210- self .listener_closed .labels (
211- protocols = event ["protocols" ]
212- ).inc ()
190+ self .listener_closed .labels (protocols = event ["protocols" ]).inc ()
213191
214192 elif etype == "ListenerError" :
215-
216193 self .listener_error .inc ()
217194
218195 elif etype == "Dialing" :
219-
220196 self .dial_attempt .inc ()
221197
222198 elif etype == "NewExternalAddrCandidate" :
223-
224- self .external_addr_candidates .labels (
225- protocols = event ["protocols" ]
226- ).inc ()
199+ self .external_addr_candidates .labels (protocols = event ["protocols" ]).inc ()
227200
228201 elif etype == "ExternalAddrConfirmed" :
229-
230- self .external_addr_confirmed .labels (
231- protocols = event ["protocols" ]
232- ).inc ()
202+ self .external_addr_confirmed .labels (protocols = event ["protocols" ]).inc ()
233203
234204 elif etype == "ExternalAddrExpired" :
235-
236- self .external_addr_expired .labels (
237- protocols = event ["protocols" ]
238- ).inc ()
205+ self .external_addr_expired .labels (protocols = event ["protocols" ]).inc ()
0 commit comments