From 97068153190f9197ecfe05a7458eb3c6d28694b4 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 27 Aug 2012 23:01:24 +0200 Subject: Fix missing transport service_info when there are no watchdogs --- lib/diameter/src/base/diameter_service.erl | 39 +++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'lib/diameter/src/base') diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl index f586cef11a..a4f4382697 100644 --- a/lib/diameter/src/base/diameter_service.erl +++ b/lib/diameter/src/base/diameter_service.erl @@ -2917,7 +2917,7 @@ info_stats(#state{peerT = PeerT}) -> %% the accumulated values for the ref and associated peer pids. info_transport(S) -> - PeerD = peer_dict(S), + PeerD = peer_dict(S, config_dict(S)), RefsD = dict:map(fun(_, Ls) -> [P || L <- Ls, {peer, {P,_}} <- L] end, PeerD), Refs = lists:append(dict:fold(fun(R, Ps, A) -> [[R|Ps] | A] end, @@ -2932,18 +2932,29 @@ info_transport(S) -> [], PeerD). +%% Only a config entry for a listening transport: use it. +transport([[{type, listen}, _] = L]) -> + L ++ [{accept, []}]; + +%% Only one config or peer entry for a connecting transport: use it. transport([[{type, connect} | _] = L]) -> L; +%% Peer entries: discard config. Note that the peer entries have +%% length at least 3. +transport([[_,_] | L]) -> + transport(L); + +%% Possibly many peer entries for a listening transport. Note that all +%% have the same options by construction, which is not terribly space +%% efficient. (TODO: all entries for the same Ref should share options.) transport([[{type, accept}, {options, Opts} | _] | _] = Ls) -> [{type, listen}, {options, Opts}, {accept, [lists:nthtail(2,L) || L <- Ls]}]. -%% Note that all peer records for a listening transport (ie. same Ref) -%% have the same options. (TODO) -peer_dict(#state{peerT = PeerT, connT = ConnT}) -> - ets:foldl(fun(T,A) -> peer_acc(ConnT, A, T) end, dict:new(), PeerT). +peer_dict(#state{peerT = PeerT, connT = ConnT}, Dict0) -> + ets:foldl(fun(T,A) -> peer_acc(ConnT, A, T) end, Dict0, PeerT). peer_acc(ConnT, Acc, #peer{pid = Pid, type = Type, @@ -2966,6 +2977,22 @@ info_conn(ConnT, TPid, true) info_conn(_, _, _) -> []. +%% The point of extracting the config here is so that 'transport' info +%% has one entry for each transport ref, the peer table only +%% containing entries that have a living watchdog. + +config_dict(#state{service_name = SvcName}) -> + lists:foldl(fun config_acc/2, + dict:new(), + diameter_config:lookup(SvcName)). + +config_acc({Ref, T, Opts}, Dict) + when T == listen; + T == connect -> + dict:store(Ref, [[{type, T}, {options, Opts}]], Dict); +config_acc(_, Dict) -> + Dict. + wd_state({_,S}) -> S; wd_state(?STATE_UP) -> @@ -3040,7 +3067,7 @@ info_connections(S) -> [L ++ [stats([P], Stats)] || L <- ConnL, {peer, {P,_}} <- L]. conn_list(S) -> - lists:append(dict:fold(fun conn_acc/3, [], peer_dict(S))). + lists:append(dict:fold(fun conn_acc/3, [], peer_dict(S, dict:new()))). conn_acc(Ref, Peers, Acc) -> [[[{ref, Ref} | L] || L <- Peers, lists:keymember(peer, 1, L)] -- cgit v1.2.3 From 858b3c001b895866d463eff529f9c6cc3b817a58 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 28 Aug 2012 00:41:27 +0200 Subject: Tweak info presentation --- lib/diameter/src/base/diameter_service.erl | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'lib/diameter/src/base') diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl index a4f4382697..a44ab283ed 100644 --- a/lib/diameter/src/base/diameter_service.erl +++ b/lib/diameter/src/base/diameter_service.erl @@ -3016,7 +3016,9 @@ info_port(Pid) -> {TPid, {_Type, TMod, _Cfg}} = T, {_, TD} = process_info(TPid, dictionary), {_, Data} = lists:keyfind({TMod, info}, 1, TD), - [{owner, TPid}, {module, TMod} | [_|_] = TMod:info(Data)]. + [{owner, TPid}, + {module, TMod} + | try TMod:info(Data) catch _:_ -> [] end]. %% Use the fields names from diameter_caps instead of %% diameter_base_CER to distinguish between the 2-tuple values @@ -3029,14 +3031,8 @@ info_caps(#diameter_caps{} = C) -> info_apps(#state{service = #diameter_service{applications = Apps}}) -> lists:map(fun mk_app/1, Apps). -mk_app(#diameter_app{alias = Alias, - dictionary = Dict, - module = ModX, - id = Id}) -> - [{alias, Alias}, - {dictionary, Dict}, - {module, ModX}, - {id, Id}]. +mk_app(#diameter_app{} = A) -> + lists:zip(record_info(fields, diameter_app), tl(tuple_to_list(A))). %% info_pending/1 %% -- cgit v1.2.3 From d5f20be12d3b7c7ca0313d23275d7a52159c5ffd Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 28 Aug 2012 20:28:41 +0200 Subject: Minor counting fix --- lib/diameter/src/base/diameter_service.erl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/diameter/src/base') diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl index a44ab283ed..18460a113f 100644 --- a/lib/diameter/src/base/diameter_service.erl +++ b/lib/diameter/src/base/diameter_service.erl @@ -3084,26 +3084,24 @@ stats_acc(Ref, Dict, Stats) -> %% info_peers/1 %% %% One entry per peer Origin-Host. Statistics for each entry are -%% accumulated values for all associated transport refs and peer pids. +%% accumulated values for all peer pids. info_peers(S) -> - ConnL = conn_list(S), {PeerD, RefD} = lists:foldl(fun peer_acc/2, {dict:new(), dict:new()}, - ConnL), - Refs = lists:append(dict:fold(fun(_, Rs, A) -> [lists:append(Rs) | A] end, + conn_list(S)), + Refs = lists:append(dict:fold(fun(_, Rs, A) -> [Rs|A] end, [], RefD)), Stats = diameter_stats:read(Refs), dict:fold(fun(OH, Cs, A) -> - Rs = lists:append(dict:fetch(OH, RefD)), - [{OH, [{connections, Cs}, stats(Rs, Stats)]} - | A] + Rs = dict:fetch(OH, RefD), + [{OH, [{connections, Cs}, stats(Rs, Stats)]} | A] end, [], PeerD). peer_acc(Peer, {PeerD, RefD}) -> - [Ref, {TPid, _}, [{origin_host, {_, OH}} | _]] - = [proplists:get_value(K, Peer) || K <- [ref, peer, caps]], - {dict:append(OH, Peer, PeerD), dict:append(OH, [Ref, TPid], RefD)}. + [{TPid, _}, [{origin_host, {_, OH}} | _]] + = [proplists:get_value(K, Peer) || K <- [peer, caps]], + {dict:append(OH, Peer, PeerD), dict:append(OH, TPid, RefD)}. -- cgit v1.2.3