Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
dc824437
提交
dc824437
authored
5月 25, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [tasks] 新增摄像头状态巡检任务
上级
5f0e701f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
103 行增加
和
17 行删除
+103
-17
merger.py
isc_video_record/merger.py
+2
-2
tasks.py
isc_video_record/tasks.py
+98
-12
alarm_utils.py
isc_video_record/utils/alarm_utils.py
+2
-2
setup.py
setup.py
+1
-1
没有找到文件。
isc_video_record/merger.py
浏览文件 @
dc824437
...
@@ -138,8 +138,8 @@ class EventMergerJob:
...
@@ -138,8 +138,8 @@ class EventMergerJob:
body
[
'ex'
]
=
event_duration
+
10
body
[
'ex'
]
=
event_duration
+
10
if
event_duration
>
0
:
if
event_duration
>
0
:
self
.
send_mq_message
(
body
)
self
.
send_mq_message
(
body
)
log
.
info
(
body
)
log
.
info
(
body
)
return
body
[
'ex'
]
return
body
[
'ex'
]
def
run
(
self
):
def
run
(
self
):
...
@@ -177,7 +177,7 @@ class EventMergerJob:
...
@@ -177,7 +177,7 @@ class EventMergerJob:
'value'
:
float
(
total_video_duration
),
'value'
:
float
(
total_video_duration
),
'camera_count'
:
camera_count
'camera_count'
:
camera_count
},
},
time
:
datetime
.
now
()
'time'
:
datetime
.
now
()
}],
retention_policy
=
'one_week'
)
}],
retention_policy
=
'one_week'
)
def
send_mq_message
(
self
,
body
):
def
send_mq_message
(
self
,
body
):
...
...
isc_video_record/tasks.py
浏览文件 @
dc824437
...
@@ -5,6 +5,8 @@ import pytz
...
@@ -5,6 +5,8 @@ import pytz
from
apscheduler.schedulers.blocking
import
BlockingScheduler
from
apscheduler.schedulers.blocking
import
BlockingScheduler
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
intelab_python_sdk.logger
import
log
from
isc_video_record.db
import
redis_connect
,
mysql
,
influxdb
from
isc_video_record.db
import
redis_connect
,
mysql
,
influxdb
from
isc_video_record.utils.alarm_utils
import
send_markdown
from
isc_video_record.utils.alarm_utils
import
send_markdown
from
isc_video_record.utils.record_utils
import
get_time_str
from
isc_video_record.utils.record_utils
import
get_time_str
...
@@ -12,14 +14,31 @@ from isc_video_record.const import LAST_CHECK_TIME_KEY, PROCESSING_CAMERA_KEY
...
@@ -12,14 +14,31 @@ from isc_video_record.const import LAST_CHECK_TIME_KEY, PROCESSING_CAMERA_KEY
from
isc_video_record.utils.excel_utils
import
gen_excel
from
isc_video_record.utils.excel_utils
import
gen_excel
from
isc_video_record.utils.aliyun_oss
import
oss_upload_file
from
isc_video_record.utils.aliyun_oss
import
oss_upload_file
from
isc_video_record.db.mysql
import
get_camera_info
from
isc_video_record.db.mysql
import
get_camera_info
from
isc_video_record.utils.api_helper
import
IntelabApiHelper
api_helper
=
IntelabApiHelper
()
TIMEZONE
=
'Asia/Shanghai'
TIMEZONE
=
'Asia/Shanghai'
tz
=
pytz
.
timezone
(
TIMEZONE
)
tz
=
pytz
.
timezone
(
TIMEZONE
)
text
=
"""
text
=
""" ## isc视频录制巡检报告
- 当前处于录制中的摄像头个数为:{}
● 当前处于录制中的摄像头个数为:{}
\n
- 未处理视频总时长:{}
● 未处理视频总时长:{}
\n
- 所属视频摄像头个数:{}
● 当前在线摄像头个数:{}
\n
● 当前离线摄像头个数:{}
\n
● 摄像头状态巡检时间:{}
\n
"""
daily_text
=
""" ## {}日报, 共{}路摄像头
● 总视频时长为: {}
\n
● 录制完成时长: {}
\n
● 稍后重试时长: {}
\n
● 不再重试时长: {}
\n
[摄像头视频时长详情]({})
"""
"""
...
@@ -33,10 +52,34 @@ class Tasks:
...
@@ -33,10 +52,34 @@ class Tasks:
schedulers
=
BlockingScheduler
({
schedulers
=
BlockingScheduler
({
'apscheduler.timezone'
:
TIMEZONE
})
'apscheduler.timezone'
:
TIMEZONE
})
schedulers
.
add_job
(
self
.
run_moniter_online
,
'interval'
,
minutes
=
3
,
seconds
=
10
)
schedulers
.
add_job
(
self
.
run_moniter_hour
,
'cron'
,
minute
=
'0,30'
)
schedulers
.
add_job
(
self
.
run_moniter_hour
,
'cron'
,
minute
=
'0,30'
)
schedulers
.
add_job
(
self
.
run_moniter_daily
,
'cron'
,
hour
=
10
,
minute
=
30
)
schedulers
.
add_job
(
self
.
run_moniter_daily
,
'cron'
,
hour
=
10
,
minute
=
30
)
schedulers
.
start
()
schedulers
.
start
()
@staticmethod
def
run_moniter_online
():
measure_points
=
[]
for
camera
in
get_camera_info
():
online_info
=
api_helper
.
get_camera_online
(
camera
[
'device_code'
])
log
.
info
(
'camera[
%
s] online:
%
s, collect_time:
%
s'
,
camera
[
'device_code'
],
online_info
.
get
(
'online'
,
0
),
online_info
.
get
(
'collectTime'
))
measure_points
.
append
({
'measurement'
:
'isc_camera_status'
,
'tags'
:
{
'camera_code'
:
camera
[
'device_code'
],
'camera_index'
:
camera
[
'point_index_code'
]
},
'fields'
:
{
'value'
:
online_info
.
get
(
'online'
,
0
)
},
'time'
:
online_info
[
'collectTime'
]
})
if
len
(
measure_points
):
influxdb
.
reconnect
()
influxdb
.
write_points
(
measure_points
,
retention_policy
=
'one_week'
)
@staticmethod
@staticmethod
def
clean
():
def
clean
():
pipe
=
redis_connect
()
pipe
=
redis_connect
()
...
@@ -50,16 +93,46 @@ class Tasks:
...
@@ -50,16 +93,46 @@ class Tasks:
定时检查视频推流服务情况,并发送钉钉报警
定时检查视频推流服务情况,并发送钉钉报警
"""
"""
influxdb
.
reconnect
()
influxdb
.
reconnect
()
# 获取当前录制数量
res
=
influxdb
.
query
(
res
=
influxdb
.
query
(
'select * from one_week.pre_video_duration order by time desc limit 1'
)
'select * from one_week.pre_video_duration order by time desc limit 1'
)
pre_video_duration
=
list
(
res
[
'pre_video_duration'
])[
0
]
if
res
and
len
(
res
)
>
0
else
{
pre_video_duration
=
list
(
res
[
'pre_video_duration'
])[
0
]
if
res
and
len
(
res
)
>
0
else
{
'value'
:
0
,
'camera_count'
:
0
}
'value'
:
0
,
'camera_count'
:
0
}
# 获取摄像头在线\离线数量
collect_time
=
datetime
.
utcnow
()
-
timedelta
(
minutes
=
5.1
)
query_str
=
'''
select mode(value), count(value)
from one_week.isc_camera_status
where time >= '{}'
group by value
'''
.
format
(
collect_time
)
status_res
=
list
(
influxdb
.
query
(
query_str
))
online_count
=
offline_count
=
0
if
status_res
:
status_res
=
status_res
[
0
]
for
status
in
status_res
:
if
status
[
'mode'
]
==
1
:
online_count
=
status
[
'count'
]
else
:
offline_count
=
status
[
'count'
]
collect_time
=
status
[
'time'
]
if
isinstance
(
collect_time
,
str
):
collect_time
=
datetime
.
strptime
(
collect_time
,
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
fZ'
)
mobiles
=
None
if
online_count
<=
3
:
mobiles
=
[
'15131601294'
]
with
redis_connect
()
as
pipe
:
with
redis_connect
()
as
pipe
:
send_markdown
(
'isc巡检'
,
text
.
format
(
send_markdown
(
'isc巡检'
,
text
.
format
(
len
(
pipe
.
keys
(
PROCESSING_CAMERA_KEY
.
format
(
'*'
))),
len
(
pipe
.
keys
(
PROCESSING_CAMERA_KEY
.
format
(
'*'
))),
get_time_str
(
pre_video_duration
[
'value'
]),
get_time_str
(
pre_video_duration
[
'value'
]),
pre_video_duration
[
'camera_count'
]
online_count
,
offline_count
,
))
collect_time
.
astimezone
(
tz
)
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
),
mobiles
)
@staticmethod
@staticmethod
def
run_moniter_daily
():
def
run_moniter_daily
():
...
@@ -78,7 +151,9 @@ class Tasks:
...
@@ -78,7 +151,9 @@ class Tasks:
start_time
=
end_time
-
timedelta
(
days
=
1
)
start_time
=
end_time
-
timedelta
(
days
=
1
)
file_name
=
'isc-daily-{}.xlsx'
.
format
(
end_time
.
strftime
(
'
%
Y
%
m
%
d'
))
file_name
=
'isc-daily-{}.xlsx'
.
format
(
end_time
.
strftime
(
'
%
Y
%
m
%
d'
))
camera_count
=
0
camera_count
=
0
daily_duration
=
0
daily_total_duration
=
daily_done_duration
=
0
daily_failed_duration
=
daily_retry_duration
=
0
results
=
[]
results
=
[]
for
camera
in
get_camera_info
():
for
camera
in
get_camera_info
():
...
@@ -107,7 +182,10 @@ class Tasks:
...
@@ -107,7 +182,10 @@ class Tasks:
camera
[
'total'
]
=
get_time_str
(
total
)
camera
[
'total'
]
=
get_time_str
(
total
)
results
.
append
(
camera
)
results
.
append
(
camera
)
daily_duration
+=
total
daily_total_duration
+=
total
daily_done_duration
+=
done
daily_failed_duration
+=
unknown
daily_retry_duration
+=
failed
camera_count
+=
1
camera_count
+=
1
with
tempfile
.
TemporaryDirectory
()
as
tmp
:
with
tempfile
.
TemporaryDirectory
()
as
tmp
:
...
@@ -117,13 +195,21 @@ class Tasks:
...
@@ -117,13 +195,21 @@ class Tasks:
send_markdown
(
send_markdown
(
'isc-daily'
,
'isc-daily'
,
(
'**{}日报**
\n\n
共{}路摄像头,总视频时长为:{}
\n\n
[摄像头视频时长详情]({}) '
)
daily_text
.
format
(
.
format
(
end_time
.
strftime
(
'
%
Y-
%
m-
%
d'
),
camera_count
,
get_time_str
(
daily_duration
),
end_time
.
strftime
(
'
%
Y-
%
m-
%
d'
),
url
)
camera_count
,
get_time_str
(
daily_total_duration
),
get_time_str
(
daily_done_duration
),
get_time_str
(
daily_retry_duration
),
get_time_str
(
daily_failed_duration
),
url
)
)
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
intelab_python_sdk.logger
import
log_init
log_init
(
__name__
,
False
)
t
=
Tasks
()
t
=
Tasks
()
t
.
run_moniter_daily
()
# t.start
()
t
.
run_moniter_hour
()
t
.
run_moniter_hour
()
isc_video_record/utils/alarm_utils.py
浏览文件 @
dc824437
...
@@ -19,8 +19,8 @@ def send_alarm_to_developer(service_name, e):
...
@@ -19,8 +19,8 @@ def send_alarm_to_developer(service_name, e):
t
.
start
()
t
.
start
()
def
send_markdown
(
title
,
text
):
def
send_markdown
(
title
,
text
,
mobiles
=
None
):
dingtalk_config
=
settings
.
get
(
'DINGTALK'
)
dingtalk_config
=
settings
.
get
(
'DINGTALK'
)
dingtalk
=
DingTalkMessage
(
dingtalk_config
.
get
(
'WEBHOOK'
),
dingtalk
=
DingTalkMessage
(
dingtalk_config
.
get
(
'WEBHOOK'
),
dingtalk_config
.
get
(
'SECRET'
))
dingtalk_config
.
get
(
'SECRET'
))
dingtalk
.
send_markdown
(
title
,
text
)
dingtalk
.
send_markdown
(
title
,
text
,
mobiles
)
setup.py
浏览文件 @
dc824437
...
@@ -23,7 +23,7 @@ requires = [
...
@@ -23,7 +23,7 @@ requires = [
setuptools
.
setup
(
setuptools
.
setup
(
name
=
'isc-video-record'
,
name
=
'isc-video-record'
,
version
=
'1.0.0a
19
'
,
version
=
'1.0.0a
20
'
,
description
=
'ISC motion detection playback video stream recording service.'
,
description
=
'ISC motion detection playback video stream recording service.'
,
long_description
=
long_description
,
long_description
=
long_description
,
long_description_content_type
=
'text/markdown'
,
long_description_content_type
=
'text/markdown'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论