diff options
author | Maria-12648430 <[email protected]> | 2020-09-04 14:32:41 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-09-10 15:01:49 +0200 |
commit | 03a8256e989091d7d153b8632c25fdc64c88ada1 (patch) | |
tree | 9493887c7cbd1f4fb3335a966e9367eb1527d3d4 /src/ranch.erl | |
parent | a57210e4e06358304b8d49ae955ab6466e0a289b (diff) | |
download | ranch-03a8256e989091d7d153b8632c25fdc64c88ada1.tar.gz ranch-03a8256e989091d7d153b8632c25fdc64c88ada1.tar.bz2 ranch-03a8256e989091d7d153b8632c25fdc64c88ada1.zip |
Metric counters for connection accepts and terminates
Diffstat (limited to 'src/ranch.erl')
-rw-r--r-- | src/ranch.erl | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/ranch.erl b/src/ranch.erl index 4adb1d8..a83402d 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -420,7 +420,8 @@ listener_info(Ref, Pid) -> transport => Transport, transport_options => TransOpts, protocol => Protocol, - protocol_options => ProtoOpts + protocol_options => ProtoOpts, + metrics => metrics(Ref) }. -spec procs(ref(), acceptors | connections) -> [pid()]. @@ -447,6 +448,23 @@ procs1(ListenerSup, connections) -> ), lists:flatten(Conns). +-spec metrics(ref()) -> #{}. +metrics(Ref) -> + Counters = ranch_server:get_stats_counters(Ref), + CounterInfo = counters:info(Counters), + NumCounters = maps:get(size, CounterInfo), + NumConnsSups = NumCounters div 2, + lists:foldl( + fun (Id, Acc) -> + Acc#{ + {conns_sup, Id, accept} => counters:get(Counters, 2*Id-1), + {conns_sup, Id, terminate} => counters:get(Counters, 2*Id) + } + end, + #{}, + lists:seq(1, NumConnsSups) + ). + -spec wait_for_connections (ref(), '>' | '>=' | '==' | '=<', non_neg_integer()) -> ok; (ref(), '<', pos_integer()) -> ok. |