Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 1 | # 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 Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 6 | """ |
| 7 | Copyright 2020 The Magma Authors. |
| 8 | |
| 9 | This source code is licensed under the BSD-style license found in the |
| 10 | LICENSE file in the root directory of this source tree. |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | """ |
| 18 | |
| 19 | from prometheus_client import Counter, Gauge |
| 20 | |
| 21 | # Gauges for current eNodeB status |
| 22 | STAT_ENODEB_CONNECTED = Gauge( |
| 23 | 'enodeb_mgmt_connected', |
| 24 | 'ENodeB management plane connected', |
| 25 | ) |
| 26 | STAT_ENODEB_CONFIGURED = Gauge( |
| 27 | 'enodeb_mgmt_configured', |
| 28 | 'ENodeB is in configured state', |
| 29 | ) |
| 30 | STAT_OPSTATE_ENABLED = Gauge( |
| 31 | 'enodeb_opstate_enabled', |
| 32 | 'ENodeB operationally enabled', |
| 33 | ) |
| 34 | STAT_RF_TX_ENABLED = Gauge( |
| 35 | 'enodeb_rf_tx_enabled', |
| 36 | 'ENodeB RF transmitter enabled', |
| 37 | ) |
| 38 | STAT_RF_TX_DESIRED = Gauge( |
| 39 | 'enodeb_rf_tx_desired', |
| 40 | 'ENodeB RF transmitter desired state', |
| 41 | ) |
| 42 | STAT_GPS_CONNECTED = Gauge( |
| 43 | 'enodeb_gps_connected', |
| 44 | 'ENodeB GPS synchronized', |
| 45 | ) |
| 46 | STAT_PTP_CONNECTED = Gauge( |
| 47 | 'enodeb_ptp_connected', |
| 48 | 'ENodeB PTP/1588 synchronized', |
| 49 | ) |
| 50 | STAT_MME_CONNECTED = Gauge( |
| 51 | 'enodeb_mme_connected', |
| 52 | 'ENodeB connected to MME', |
| 53 | ) |
| 54 | STAT_ENODEB_REBOOT_TIMER_ACTIVE = Gauge( |
| 55 | 'enodeb_reboot_timer_active', |
| 56 | 'Timer for ENodeB reboot active', |
| 57 | ) |
| 58 | STAT_ENODEB_REBOOTS = Counter( |
| 59 | 'enodeb_reboots', |
| 60 | 'ENodeB reboots by enodebd', ['cause'], |
| 61 | ) |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 62 | |
| 63 | # Metrics that are accumulated by eNodeB. Use gauges to avoid 'double-counting', |
| 64 | # since eNodeB does accumulation. |
| 65 | STAT_RRC_ESTAB_ATT = Gauge( |
| 66 | 'rrc_estab_attempts', 'RRC establishment attempts', |
| 67 | ) |
| 68 | STAT_RRC_ESTAB_SUCC = Gauge( |
| 69 | 'rrc_estab_successes', 'RRC establishment successes', |
| 70 | ) |
| 71 | STAT_RRC_REESTAB_ATT = Gauge( |
| 72 | 'rrc_reestab_attempts', 'RRC re-establishment attempts', |
| 73 | ) |
| 74 | STAT_RRC_REESTAB_ATT_RECONF_FAIL = Gauge( |
| 75 | 'rrc_reestab_attempts_reconf_fail', |
| 76 | 'RRC re-establishment attempts due to reconfiguration failure', |
| 77 | ) |
| 78 | STAT_RRC_REESTAB_ATT_HO_FAIL = Gauge( |
| 79 | 'rrc_reestab_attempts_ho_fail', |
| 80 | 'RRC re-establishment attempts due to handover failure', |
| 81 | ) |
| 82 | STAT_RRC_REESTAB_ATT_OTHER = Gauge( |
| 83 | 'rrc_reestab_attempts_other', |
| 84 | 'RRC re-establishment attempts due to other cause', |
| 85 | ) |
| 86 | STAT_RRC_REESTAB_SUCC = Gauge( |
| 87 | 'rrc_reestab_successes', 'RRC re-establishment successes', |
| 88 | ) |
| 89 | STAT_ERAB_ESTAB_ATT = Gauge( |
| 90 | 'erab_estab_attempts', 'ERAB establishment attempts', |
| 91 | ) |
| 92 | STAT_ERAB_ESTAB_SUCC = Gauge( |
| 93 | 'erab_estab_successes', 'ERAB establishment successes', |
| 94 | ) |
| 95 | STAT_ERAB_ESTAB_FAIL = Gauge( |
| 96 | 'erab_estab_failures', 'ERAB establishment failures', |
| 97 | ) |
| 98 | STAT_ERAB_REL_REQ = Gauge( |
| 99 | 'erab_release_requests', 'ERAB release requests', |
| 100 | ) |
| 101 | STAT_ERAB_REL_REQ_USER_INAC = Gauge( |
| 102 | 'erab_release_requests_user_inactivity', |
| 103 | 'ERAB release requests due to user inactivity', |
| 104 | ) |
| 105 | STAT_ERAB_REL_REQ_NORMAL = Gauge( |
| 106 | 'erab_release_requests_normal', 'ERAB release requests due to normal cause', |
| 107 | ) |
| 108 | STAT_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 | ) |
| 112 | STAT_ERAB_REL_REQ_REDUCE_LOAD = Gauge( |
| 113 | 'erab_release_requests_reduce_load', |
| 114 | 'ERAB release requests due to reducing load in serving cell', |
| 115 | ) |
| 116 | STAT_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 | ) |
| 120 | STAT_ERAB_REL_REQ_EUTRAN_REAS = Gauge( |
| 121 | 'erab_release_requests_eutran_reas', |
| 122 | 'ERAB release requests due to EUTRAN generated reasons', |
| 123 | ) |
| 124 | STAT_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 | ) |
| 128 | STAT_ERAB_REL_REQ_OAM_INTV = Gauge( |
| 129 | 'erab_release_requests_oam_intervention', |
| 130 | 'ERAB release requests due to OAM intervention', |
| 131 | ) |
| 132 | STAT_PDCP_USER_PLANE_BYTES_UL = Gauge( |
| 133 | 'pdcp_user_plane_bytes_ul', 'User plane uplink bytes at PDCP', ['enodeb'], |
| 134 | ) |
| 135 | STAT_PDCP_USER_PLANE_BYTES_DL = Gauge( |
| 136 | 'pdcp_user_plane_bytes_dl', 'User plane downlink bytes at PDCP', ['enodeb'], |
| 137 | ) |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 138 | |
| 139 | # Aether-use Status |
| 140 | |
| 141 | STAT_ENODEB_LAST_CONFIGURED_TIME = Gauge( |
| 142 | 'enodeb_last_configured_time', |
| 143 | 'Information of configured eNodeB', ['serial_number', 'ip_address'] |
| 144 | ) |
| 145 | |
| 146 | STATE_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 | |
| 153 | STATE_ENODEB_GPS_STATUS = Gauge( |
| 154 | 'enodeb_gps_status', 'The Current GPS Status of specific enodeb', [ |
| 155 | 'serial_number' |
| 156 | ] |
| 157 | ) |
| 158 | |
| 159 | STATE_ENODEB_GPS_STATUS_LAT = Gauge( |
| 160 | 'enodeb_gps_status_lat', 'The Current GPS Latitude Status of specific enodeb', [ |
| 161 | 'serial_number' |
| 162 | ] |
| 163 | ) |
| 164 | |
| 165 | STATE_ENODEB_GPS_STATUS_LONG = Gauge( |
| 166 | 'enodeb_gps_status_long', 'The Current GPS Longtitude Status of specific enodeb', [ |
| 167 | 'serial_number' |
| 168 | ] |
| 169 | ) |
| 170 | |
| 171 | STATE_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, ) |
| 178 | stat_enodeb_last_configured_time_dict = dict() |
| 179 | # key = serial number / value = labels (sn, connected, disconnected, firmware_upgrading, configured) |
| 180 | state_enodeb_current_status_dict = dict() |
| 181 | state_enodeb_op_status_dict = dict() |
| 182 | |
| 183 | |
| 184 | def 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 | |
| 199 | def 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 | |
| 223 | def 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 | |
| 237 | def 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) |