blob: 2f5b18b2fcc2a993a5f45a40c3f4b360d819e30f [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
5
Wei-Yu Chen49950b92021-11-08 19:19:18 +08006"""
7Copyright 2020 The Magma Authors.
8
9This source code is licensed under the BSD-style license found in the
10LICENSE file in the root directory of this source tree.
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17"""
18
19from prometheus_client import Counter, Gauge
20
21# Gauges for current eNodeB status
22STAT_ENODEB_CONNECTED = Gauge(
23 'enodeb_mgmt_connected',
24 'ENodeB management plane connected',
25)
26STAT_ENODEB_CONFIGURED = Gauge(
27 'enodeb_mgmt_configured',
28 'ENodeB is in configured state',
29)
30STAT_OPSTATE_ENABLED = Gauge(
31 'enodeb_opstate_enabled',
32 'ENodeB operationally enabled',
33)
34STAT_RF_TX_ENABLED = Gauge(
35 'enodeb_rf_tx_enabled',
36 'ENodeB RF transmitter enabled',
37)
38STAT_RF_TX_DESIRED = Gauge(
39 'enodeb_rf_tx_desired',
40 'ENodeB RF transmitter desired state',
41)
42STAT_GPS_CONNECTED = Gauge(
43 'enodeb_gps_connected',
44 'ENodeB GPS synchronized',
45)
46STAT_PTP_CONNECTED = Gauge(
47 'enodeb_ptp_connected',
48 'ENodeB PTP/1588 synchronized',
49)
50STAT_MME_CONNECTED = Gauge(
51 'enodeb_mme_connected',
52 'ENodeB connected to MME',
53)
54STAT_ENODEB_REBOOT_TIMER_ACTIVE = Gauge(
55 'enodeb_reboot_timer_active',
56 'Timer for ENodeB reboot active',
57)
58STAT_ENODEB_REBOOTS = Counter(
59 'enodeb_reboots',
60 'ENodeB reboots by enodebd', ['cause'],
61)
Wei-Yu Chen49950b92021-11-08 19:19:18 +080062
63# Metrics that are accumulated by eNodeB. Use gauges to avoid 'double-counting',
64# since eNodeB does accumulation.
65STAT_RRC_ESTAB_ATT = Gauge(
66 'rrc_estab_attempts', 'RRC establishment attempts',
67)
68STAT_RRC_ESTAB_SUCC = Gauge(
69 'rrc_estab_successes', 'RRC establishment successes',
70)
71STAT_RRC_REESTAB_ATT = Gauge(
72 'rrc_reestab_attempts', 'RRC re-establishment attempts',
73)
74STAT_RRC_REESTAB_ATT_RECONF_FAIL = Gauge(
75 'rrc_reestab_attempts_reconf_fail',
76 'RRC re-establishment attempts due to reconfiguration failure',
77)
78STAT_RRC_REESTAB_ATT_HO_FAIL = Gauge(
79 'rrc_reestab_attempts_ho_fail',
80 'RRC re-establishment attempts due to handover failure',
81)
82STAT_RRC_REESTAB_ATT_OTHER = Gauge(
83 'rrc_reestab_attempts_other',
84 'RRC re-establishment attempts due to other cause',
85)
86STAT_RRC_REESTAB_SUCC = Gauge(
87 'rrc_reestab_successes', 'RRC re-establishment successes',
88)
89STAT_ERAB_ESTAB_ATT = Gauge(
90 'erab_estab_attempts', 'ERAB establishment attempts',
91)
92STAT_ERAB_ESTAB_SUCC = Gauge(
93 'erab_estab_successes', 'ERAB establishment successes',
94)
95STAT_ERAB_ESTAB_FAIL = Gauge(
96 'erab_estab_failures', 'ERAB establishment failures',
97)
98STAT_ERAB_REL_REQ = Gauge(
99 'erab_release_requests', 'ERAB release requests',
100)
101STAT_ERAB_REL_REQ_USER_INAC = Gauge(
102 'erab_release_requests_user_inactivity',
103 'ERAB release requests due to user inactivity',
104)
105STAT_ERAB_REL_REQ_NORMAL = Gauge(
106 'erab_release_requests_normal', 'ERAB release requests due to normal cause',
107)
108STAT_ERAB_REL_REQ_RES_NOT_AVAIL = Gauge(
109 'erab_release_requests_radio_resources_not_available',
110 'ERAB release requests due to radio resources not available',
111)
112STAT_ERAB_REL_REQ_REDUCE_LOAD = Gauge(
113 'erab_release_requests_reduce_load',
114 'ERAB release requests due to reducing load in serving cell',
115)
116STAT_ERAB_REL_REQ_FAIL_IN_RADIO = Gauge(
117 'erab_release_requests_fail_in_radio_proc',
118 'ERAB release requests due to failure in the radio interface procedure',
119)
120STAT_ERAB_REL_REQ_EUTRAN_REAS = Gauge(
121 'erab_release_requests_eutran_reas',
122 'ERAB release requests due to EUTRAN generated reasons',
123)
124STAT_ERAB_REL_REQ_RADIO_CONN_LOST = Gauge(
125 'erab_release_requests_radio_radio_conn_lost',
126 'ERAB release requests due to radio connection with UE lost',
127)
128STAT_ERAB_REL_REQ_OAM_INTV = Gauge(
129 'erab_release_requests_oam_intervention',
130 'ERAB release requests due to OAM intervention',
131)
132STAT_PDCP_USER_PLANE_BYTES_UL = Gauge(
133 'pdcp_user_plane_bytes_ul', 'User plane uplink bytes at PDCP', ['enodeb'],
134)
135STAT_PDCP_USER_PLANE_BYTES_DL = Gauge(
136 'pdcp_user_plane_bytes_dl', 'User plane downlink bytes at PDCP', ['enodeb'],
137)
Wei-Yu Chenb91af852022-03-15 22:24:49 +0800138
139# Aether-use Status
140
141STAT_ENODEB_LAST_CONFIGURED_TIME = Gauge(
142 'enodeb_last_configured_time',
143 'Information of configured eNodeB', ['serial_number', 'ip_address']
144)
145
146STATE_ENODEB_CURRENT_STATUS = Gauge(
147 'enodeb_current_status', 'The Current Configuration Status of specific enodeb', [
148 'serial_number',
149 'connected', 'disconnected', 'firmware_upgrading', 'configured'
150 ]
151)
152
153STATE_ENODEB_GPS_STATUS = Gauge(
154 'enodeb_gps_status', 'The Current GPS Status of specific enodeb', [
155 'serial_number'
156 ]
157)
158
159STATE_ENODEB_GPS_STATUS_LAT = Gauge(
160 'enodeb_gps_status_lat', 'The Current GPS Latitude Status of specific enodeb', [
161 'serial_number'
162 ]
163)
164
165STATE_ENODEB_GPS_STATUS_LONG = Gauge(
166 'enodeb_gps_status_long', 'The Current GPS Longtitude Status of specific enodeb', [
167 'serial_number'
168 ]
169)
170
171STATE_ENODEB_OP_STATE = Gauge(
172 'enodeb_op_status', 'The Current Operating Status of specific enodeb', [
173 'serial_number', 'op_state'
174 ]
175)
176
177# key = serial number / value = labels (serial_number, ip_address, )
178stat_enodeb_last_configured_time_dict = dict()
179# key = serial number / value = labels (sn, connected, disconnected, firmware_upgrading, configured)
180state_enodeb_current_status_dict = dict()
181state_enodeb_op_status_dict = dict()
182
183
184def set_enb_last_configured_time(serial_number, ip_address, time):
185 if serial_number in stat_enodeb_last_configured_time_dict:
186 STAT_ENODEB_LAST_CONFIGURED_TIME.remove(
187 *stat_enodeb_last_configured_time_dict.pop(serial_number)
188 )
189 else:
190 stat_enodeb_last_configured_time_dict[serial_number] = [
191 serial_number, ip_address
192 ]
193
194 STAT_ENODEB_LAST_CONFIGURED_TIME.labels(
195 serial_number=serial_number,
196 ip_address=ip_address
197 ).set(time)
198
199def set_enb_status(serial_number, status=["connected", "disconnected", "firmware_upgrading", "configured"]):
200 status_list = ["connected", "disconnected", "firmware_upgrading", "configured"]
201
202 if serial_number in state_enodeb_current_status_dict:
203 STATE_ENODEB_CURRENT_STATUS.remove(
204 *state_enodeb_current_status_dict.pop(serial_number)
205 )
206 else:
207 state_enodeb_current_status_dict[serial_number] = [
208 serial_number,
209 int(status == "connected"),
210 int(status == "disconnected"),
211 int(status == "firmware_upgrading"),
212 int(status == "configured")
213 ]
214
215 STATE_ENODEB_CURRENT_STATUS.labels(
216 serial_number=serial_number,
217 connected=int(status == "connected"),
218 disconnected=int(status == "disconnected"),
219 firmware_upgrading=int(status == "firmware_upgrading"),
220 configured=int(status == "configured")
221 ).set(status_list.index(status))
222
223def set_enb_gps_status(serial_number, lat, long, gps_state):
224 mapped_status = int()
225 if gps_state in ["Success", "Running", "1"]:
226 mapped_status = 1
227 else:
228 mapped_status = 0
229
230 lat_div_million = float(lat) / 1000000
231 lon_div_million = float(long) / 1000000
232
233 STATE_ENODEB_GPS_STATUS.labels(serial_number=serial_number).set(mapped_status)
234 STATE_ENODEB_GPS_STATUS_LAT.labels(serial_number=serial_number).set(lat_div_million)
235 STATE_ENODEB_GPS_STATUS_LONG.labels(serial_number=serial_number).set(lon_div_million)
236
237def set_enb_op_status(serial_number, op_state):
238 mapped_status = int()
239 if op_state in ["enabled"]:
240 mapped_status = 1
241 else:
242 mapped_status = 0
243
244 if serial_number in state_enodeb_op_status_dict:
245 STATE_ENODEB_OP_STATE.remove(
246 *state_enodeb_op_status_dict.pop(serial_number)
247 )
248 else:
249 state_enodeb_op_status_dict[serial_number] = [
250 serial_number, op_state
251 ]
252
253 STATE_ENODEB_OP_STATE.labels(
254 serial_number=serial_number, op_state=op_state
255 ).set(mapped_status)