fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41760?usp=email )
Change subject: enb_proxy: add per-eNB and global counters
......................................................................
enb_proxy: add per-eNB and global counters
Change-Id: I3670db6a519ec8070ada6aecd471c4630ad53c86
Related: SYS#7052
---
M include/s1gw_metrics.hrl
M src/enb_proxy.erl
M src/s1gw_metrics.erl
3 files changed, 80 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw
refs/changes/60/41760/1
diff --git a/include/s1gw_metrics.hrl b/include/s1gw_metrics.hrl
index 8f78821..ecdf315 100644
--- a/include/s1gw_metrics.hrl
+++ b/include/s1gw_metrics.hrl
@@ -39,6 +39,17 @@
-define(S1GW_CTR_S1AP_PROXY_OUT_PKT_REPLY_ALL, [ctr, s1ap, proxy, out_pkt,
reply, all]).
-define(S1GW_CTR_S1AP_PROXY_OUT_PKT_REPLY_ERAB_SETUP_RSP, [ctr, s1ap, proxy,
out_pkt, reply, erab_setup_rsp]).
+%% enb_proxy related metrics
+-define(S1GW_CTR_ENB_PROXY_S1_SETUP_REQ, [ctr, enb_proxy, s1setup, req]).
+-define(S1GW_CTR_ENB_PROXY_S1_SETUP_RSP, [ctr, enb_proxy, s1setup, rsp]).
+-define(S1GW_CTR_ENB_PROXY_S1_SETUP_FAILURE, [ctr, enb_proxy, s1setup,
failure]).
+-define(S1GW_CTR_ENB_PROXY_S1_SETUP_REQ_TIMEOUT, [ctr, enb_proxy, s1setup,
req, timeout]).
+-define(S1GW_CTR_ENB_PROXY_S1_SETUP_RSP_TIMEOUT, [ctr, enb_proxy, s1setup,
rsp, timeout]).
+-define(S1GW_CTR_ENB_PROXY_CONN_EST_TIMEOUT, [ctr, enb_proxy, conn_est,
timeout]).
+-define(S1GW_CTR_ENB_PROXY_CONN_EST_FAILURE, [ctr, enb_proxy, conn_est,
failure]).
+-define(S1GW_CTR_ENB_PROXY_UNEXPECTED_PDU, [ctr, enb_proxy, unexpected_pdu]).
+-define(S1GW_CTR_ENB_PROXY_MALFORMED_PDU, [ctr, enb_proxy, malformed_pdu]).
+
%% SCTP related metrics
-define(S1GW_CTR_SCTP_ERROR_ALL, [ctr, sctp, error, all]).
-define(S1GW_CTR_SCTP_ERROR_SEND_FAILED, [ctr, sctp, error, send_failed]).
diff --git a/src/enb_proxy.erl b/src/enb_proxy.erl
index 7a51221..4495e31 100644
--- a/src/enb_proxy.erl
+++ b/src/enb_proxy.erl
@@ -136,8 +136,9 @@
[{state_timeout, 5_000, s1setup_req_timeout}]};
%% Handle S1 SETUP REQUEST timeout
-wait_s1setup_req(state_timeout, s1setup_req_timeout, _S) ->
+wait_s1setup_req(state_timeout, s1setup_req_timeout, S) ->
?LOG_ERROR("Timeout waiting for S1 SETUP REQUEST from eNB"),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_S1_SETUP_REQ_TIMEOUT, S),
{stop, {shutdown, s1setup_req_timeout}};
%% Handle PDUs coming from the eNB
@@ -151,6 +152,10 @@
%% use it as the logging prefix
osmo_s1gw:set_log_prefix("eNB " ++ GlobalENBId),
?LOG_INFO("Rx S1 SETUP REQUEST from eNB"),
+ %% register per-eNB metrics
+ ctr_reg_all(GlobalENBId),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_S1_SETUP_REQ,
+ S#state{genb_id_str = GlobalENBId}),
%% signal the Global-eNB-ID to other modules
s1ap_proxy:set_genb_id(S#state.handler, GlobalENBId),
enb_registry:enb_event(S#state.enb_handle, {s1setup, GENBId}),
@@ -160,8 +165,10 @@
genb_id_str = GlobalENBId}};
{{Proc, Type}, IEs} ->
?LOG_ERROR("Rx unexpected S1AP PDU from eNB: ~p/~p, ~p", [Proc,
Type, IEs]),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_UNEXPECTED_PDU, S),
{stop, {shutdown, s1setup_error}};
{error, _Error} ->
+ ctr_inc(?S1GW_CTR_ENB_PROXY_MALFORMED_PDU, S),
{stop, {shutdown, s1setup_error}}
end;
@@ -180,12 +187,14 @@
[{state_timeout, 2_000, conn_est_timeout}]};
%% Handle connection establishment timeout
-connecting(state_timeout, conn_est_timeout, _S) ->
+connecting(state_timeout, conn_est_timeout, S) ->
+ ctr_inc(?S1GW_CTR_ENB_PROXY_CONN_EST_TIMEOUT, S),
{stop, {shutdown, conn_est_timeout}};
%% Handle PDUs coming from the eNB
-connecting(cast, {send_data, Data}, _S) ->
+connecting(cast, {send_data, Data}, S) ->
?LOG_ERROR("Rx unexpected S1AP PDU from eNB: ~p", [Data]),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_UNEXPECTED_PDU, S),
keep_state_and_data;
%% Handle an #sctp_assoc_change event (connection state)
@@ -202,6 +211,7 @@
{next_state, wait_s1setup_rsp, S#state{mme_aid = Aid}};
_ ->
?LOG_NOTICE("MME connection establishment failed: ~p",
[ConnState]),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_CONN_EST_FAILURE, S),
{stop, {shutdown, conn_est_fail}}
end;
@@ -216,13 +226,15 @@
[{state_timeout, 5_000, s1setup_rsp_timeout}]};
%% Handle S1 SETUP RESPONSE timeout
-wait_s1setup_rsp(state_timeout, s1setup_rsp_timeout, _S) ->
+wait_s1setup_rsp(state_timeout, s1setup_rsp_timeout, S) ->
?LOG_ERROR("Timeout waiting for S1 SETUP RESPONSE from MME"),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_S1_SETUP_RSP_TIMEOUT, S),
{stop, {shutdown, s1setup_rsp_timeout}};
%% Handle PDUs coming from the eNB
-wait_s1setup_rsp(cast, {send_data, Data}, _S) ->
+wait_s1setup_rsp(cast, {send_data, Data}, S) ->
?LOG_ERROR("Rx unexpected S1AP PDU from eNB: ~p", [Data]),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_UNEXPECTED_PDU, S),
keep_state_and_data;
%% Handle PDUs coming from the MME
@@ -239,16 +251,20 @@
case s1ap_utils:parse_pdu(Data) of
{{?'id-S1Setup', successfulOutcome}, _IEs} ->
?LOG_INFO("Rx S1 SETUP RESPONSE from MME"),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_S1_SETUP_RSP, S),
sctp_send_from_mme(Data, S),
{next_state, connected, S};
{{?'id-S1Setup', unsuccessfulOutcome}, _IEs} ->
?LOG_NOTICE("Rx S1 SETUP FAILURE from MME"),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_S1_SETUP_FAILURE, S),
sctp_send_from_mme(Data, S),
{stop, {shutdown, s1setup_error}};
{{Proc, Type}, IEs} ->
?LOG_ERROR("Rx unexpected S1AP PDU from MME: ~p/~p, ~p", [Proc,
Type, IEs]),
+ ctr_inc(?S1GW_CTR_ENB_PROXY_UNEXPECTED_PDU, S),
{stop, {shutdown, s1setup_error}};
{error, _Error} ->
+ ctr_inc(?S1GW_CTR_ENB_PROXY_MALFORMED_PDU, S),
{stop, {shutdown, s1setup_error}}
end;
@@ -455,4 +471,41 @@
end.
+%% register a single per-eNB counter
+-spec ctr_reg(C, GlobalENBId) -> C
+ when C :: s1gw_metrics:counter(),
+ GlobalENBId :: string().
+ctr_reg([ctr, ?MODULE | _] = C0, GlobalENBId) ->
+ C1 = s1gw_metrics:enb_metric(C0, GlobalENBId),
+ %% counter may already exist, so catch exceptions here
+ catch exometer:new(C1, counter),
+ C0;
+
+ctr_reg(C0, _GlobalENBId) -> C0.
+
+
+%% register all per-eNB counters
+-spec ctr_reg_all(string()) -> list().
+ctr_reg_all(GlobalENBId) ->
+ Ctrs = s1gw_metrics:ctr_list(),
+ lists:map(fun(Name) -> ctr_reg(Name, GlobalENBId) end, Ctrs).
+
+
+%% increment the global and/or per-eNB counters
+-spec ctr_inc(C0, S) -> term()
+ when C0 :: s1gw_metrics:counter(),
+ S :: state().
+ctr_inc([ctr, ?MODULE | _] = C0,
+ #state{genb_id_str = undefined}) ->
+ %% increment the global counter only
+ s1gw_metrics:ctr_inc(C0);
+
+ctr_inc([ctr, ?MODULE | _] = C0,
+ #state{genb_id_str = GlobalENBId}) ->
+ %% increment both the global and per-eNB counters
+ C1 = s1gw_metrics:enb_metric(C0, GlobalENBId),
+ s1gw_metrics:ctr_inc(C0),
+ s1gw_metrics:ctr_inc(C1).
+
+
%% vim:set ts=4 sw=4 et:
diff --git a/src/s1gw_metrics.erl b/src/s1gw_metrics.erl
index 1368c5b..52a5a10 100644
--- a/src/s1gw_metrics.erl
+++ b/src/s1gw_metrics.erl
@@ -96,6 +96,17 @@
?S1GW_CTR_S1AP_PROXY_OUT_PKT_REPLY_ALL, %% replied: total
?S1GW_CTR_S1AP_PROXY_OUT_PKT_REPLY_ERAB_SETUP_RSP, %% replied: E-RAB
SETUP.rsp
+ %% enb_proxy related metrics
+ ?S1GW_CTR_ENB_PROXY_S1_SETUP_REQ, %% S1 SETUP
REQUEST PDUs
+ ?S1GW_CTR_ENB_PROXY_S1_SETUP_RSP, %% S1 SETUP
RESPONSE PDUs
+ ?S1GW_CTR_ENB_PROXY_S1_SETUP_FAILURE, %% S1 SETUP
FAILURE PDUs
+ ?S1GW_CTR_ENB_PROXY_S1_SETUP_REQ_TIMEOUT, %% S1 SETUP
REQUEST timeout
+ ?S1GW_CTR_ENB_PROXY_S1_SETUP_RSP_TIMEOUT, %% S1 SETUP
RESPONSE timeout
+ ?S1GW_CTR_ENB_PROXY_CONN_EST_TIMEOUT, %% MME connection
establishment timeout
+ ?S1GW_CTR_ENB_PROXY_CONN_EST_FAILURE, %% MME connection
establishment failure
+ ?S1GW_CTR_ENB_PROXY_UNEXPECTED_PDU, %% unexpected PDUs
received from eNB/MME
+ ?S1GW_CTR_ENB_PROXY_MALFORMED_PDU, %% malformed PDUs
received from eNB/MME
+
%% SCTP related counters
?S1GW_CTR_SCTP_ERROR_ALL, %% total number of
SCTP errors
?S1GW_CTR_SCTP_ERROR_SEND_FAILED, %% send operation
failed
--
To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41760?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: I3670db6a519ec8070ada6aecd471c4630ad53c86
Gerrit-Change-Number: 41760
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>