Files

54 lines
3.3 KiB
Python
Raw Permalink Normal View History

2026-07-13 15:37:05 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# time: 2022/7/26 14:12
# file: monitor.py
# author: 臧成龙
# QQ: 939589097
from ninja import Router
from django.core.cache import cache
from utils.fu_response import FuResponse
from utils.system import system
router = Router()
@router.get("/monitor")
def list_role(request):
data = cache.get('local_inspection_data')
qs = system().GetSystemAllInfo()
if data and isinstance(data, dict):
qs['local_inspection_data'] = {
'cpu0_usage': data.get('cpu0_usage'),
'cpu1_usage': data.get('cpu1_usage')
}
else:
# 如果data为空或不是字典类型设置默认值
qs['local_inspection_data'] = {
'cpu0_usage': None,
'cpu1_usage': None
}
# print("从系统获取监控数据:", qs)
return FuResponse(data=qs)
@router.get("/get_sbb")
def list_role(request):
sbb_data = {}
# 循环获取sbb1-sbb6的缓存数据
for i in range(1, 7):
key = f'sbb{i}'
value = cache.get(key)
print(f"sbb{i}缓存数据:", value)
sbb_data[key] = value
print("从缓存获取sbb数据", sbb_data)
# 模拟的sbb数据字典包含sbb1-sbb6这六个字段
# sample_sbb_data = {
# "sbb1": {'type': 1, 'satellite_id': 2, 'primary_network_id': 0, 'roaming_network_id': 0, 'sbb_version': 152, 'start_time': 181303439, 'validity_period': 1440, 'itu_compatibility': 0, 'reserved_bits': 0, 'sbb_spare_frequency': 1226, 'uplink_max_length': 26, 'reserved': 0, 'total_message_length': 20},
# "sbb2": {'type': 2, 'downlink_frequency_a': 2226, 'uplink_frequency_a': 1226, 'downlink_bandwidth_a': 1, 'uplink_bandwidth_a': 1, 'channel_slot_lengths_a': [6, 6, 2, 6, 6, 6, 6, 2, 2, 12, 0, 0], 'channel_functions_a': [0, 1, 4, 4, 4, 4, 4, 4, 2, 3, 5, 5], 'downlink_frequency_b': 1226, 'uplink_frequency_b': 2226, 'downlink_bandwidth_b': 1, 'uplink_bandwidth_b': 1, 'channel_slot_lengths_b': [6, 6, 2, 6, 6, 6, 6, 2, 2, 12, 0, 0], 'channel_functions_b': [0, 1, 4, 4, 4, 4, 4, 4, 2, 3, 5, 5]},
# "sbb3": {'type': 3, 'downlink_frequency_c': 2284, 'uplink_frequency_c': 1225, 'downlink_bandwidth_c': 2, 'uplink_bandwidth_c': 1, 'channel_slot_lengths_c': [6, 6, 2, 6, 6, 6, 6, 2, 2, 12, 0, 0], 'channel_functions_c': [5, 5, 4, 4, 4, 4, 4, 4, 2, 3, 5, 5], 'downlink_frequency_d': 1284, 'uplink_frequency_d': 2225, 'downlink_bandwidth_d': 2, 'uplink_bandwidth_d': 1, 'channel_slot_lengths_d': [6, 6, 2, 6, 6, 6, 6, 2, 2, 12, 0, 0], 'channel_functions_d': [5, 5, 4, 4, 4, 4, 4, 4, 2, 3, 5, 5]},
# "sbb4": {'type': 4, 'downlink_frequency_e': 2225, 'uplink_frequency_e': 1224, 'downlink_bandwidth_e': 3, 'uplink_bandwidth_e': 1, 'channel_slot_lengths_e': [6, 6, 2, 6, 6, 6, 6, 2, 2, 12, 0, 0], 'channel_functions_e': [5, 5, 4, 4, 4, 4, 4, 4, 2, 3, 5, 5], 'downlink_frequency_f': 1225, 'uplink_frequency_f': 2224, 'downlink_bandwidth_f': 3, 'uplink_bandwidth_f': 1, 'channel_slot_lengths_f': [6, 6, 2, 6, 6, 6, 6, 2, 2, 12, 0, 0], 'channel_functions_f': [5, 5, 4, 4, 4, 4, 4, 4, 2, 3, 5, 5]},
# "sbb5": {'type': 5, 'digital_signature_part1': '00000000400050033a529c960c39c0a44afbcc752414aa14b540233ada55b61d'},
# "sbb6": {'type': 5, 'digital_signature_part1': '00000000400050033a529c960c39c0a44afbcc752414aa14b540233ada55b61d'}
# }
return sbb_data