提交 3d52fc30 authored 作者: zw.wang's avatar zw.wang

feat: [tasks] 更改influxdb查询

上级 dc824437
...@@ -72,9 +72,10 @@ class Tasks: ...@@ -72,9 +72,10 @@ class Tasks:
'camera_index': camera['point_index_code'] 'camera_index': camera['point_index_code']
}, },
'fields': { 'fields': {
'value': online_info.get('online', 0) 'value': online_info.get('online', 0),
'collect_time': online_info['collectTime']
}, },
'time': online_info['collectTime'] 'time': datetime.utcnow()
}) })
if len(measure_points): if len(measure_points):
influxdb.reconnect() influxdb.reconnect()
...@@ -101,26 +102,21 @@ class Tasks: ...@@ -101,26 +102,21 @@ class Tasks:
'value': 0, 'camera_count': 0} 'value': 0, 'camera_count': 0}
# 获取摄像头在线\离线数量 # 获取摄像头在线\离线数量
collect_time = datetime.utcnow() - timedelta(minutes=5.1) collect_time = datetime.utcnow() - timedelta(minutes=4.1)
query_str = ''' query_str = '''
select mode(value), count(value) select * from one_week.isc_camera_status
from one_week.isc_camera_status group by camera_code
where time >= '{}' order by time desc limit 1
group by value '''
'''.format(collect_time)
status_res = list(influxdb.query(query_str)) status_res = list(influxdb.query(query_str))
online_count = offline_count = 0 online_count = offline_count = 0
if status_res: for res in status_res:
status_res = status_res[0] for status in res:
for status in status_res: if status['value'] == 1:
if status['mode'] == 1: online_count += 1
online_count = status['count']
else: else:
offline_count = status['count'] offline_count += 1
collect_time = status['time'] collect_time = status['time']
if isinstance(collect_time, str):
collect_time = datetime.strptime(
collect_time, '%Y-%m-%dT%H:%M:%S.%fZ')
mobiles = None mobiles = None
if online_count <= 3: if online_count <= 3:
...@@ -212,4 +208,5 @@ if __name__ == '__main__': ...@@ -212,4 +208,5 @@ if __name__ == '__main__':
log_init(__name__, False) log_init(__name__, False)
t = Tasks() t = Tasks()
# t.start() # t.start()
t.run_moniter_hour() # t.run_moniter_hour()
t.run_moniter_online()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论