Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
tas_monitor
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d2ed3cc3
authored
Mar 12, 2020
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add spider expired rate
parent
5b58ea3b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
utils/mongo.py
utils/mysql.py
utils/mongo.py
View file @
d2ed3cc3
...
@@ -3,10 +3,13 @@
...
@@ -3,10 +3,13 @@
import
sys
import
sys
import
time
import
time
import
pymongo
import
pymongo
import
json
from
utils.glo
import
Glo
from
utils.glo
import
Glo
from
urllib.parse
import
quote_plus
from
urllib.parse
import
quote_plus
from
utils.mysql
import
MySqlOperator
mysql_db
=
MySqlOperator
(
'dashboard'
)
glo
=
Glo
()
glo
=
Glo
()
MG_HOST_SET
=
{
MG_HOST_SET
=
{
...
@@ -79,6 +82,7 @@ class MongoOperator:
...
@@ -79,6 +82,7 @@ class MongoOperator:
msg
=
'数据过期率监控预警 过去3小时内:
\n
'
msg
=
'数据过期率监控预警 过去3小时内:
\n
'
demo
=
'平台:{} 数据过期率为{:.2f}
%
'
demo
=
'平台:{} 数据过期率为{:.2f}
%
'
msgs
=
[]
msgs
=
[]
expired_dict
=
{}
for
plat
in
self
.
colls
:
for
plat
in
self
.
colls
:
coll
=
self
.
db
[
plat
]
coll
=
self
.
db
[
plat
]
ts
=
self
.
get_unexpired_time
(
plat
)
ts
=
self
.
get_unexpired_time
(
plat
)
...
@@ -99,9 +103,12 @@ class MongoOperator:
...
@@ -99,9 +103,12 @@ class MongoOperator:
msg_line
=
demo
.
format
(
plat
,
rate
)
msg_line
=
demo
.
format
(
plat
,
rate
)
msgs
.
append
(
msg_line
)
msgs
.
append
(
msg_line
)
msg
+=
msg_line
+
'
\n
'
msg
+=
msg_line
+
'
\n
'
expired_dict
[
plat
]
=
"{:.2f}"
.
format
(
rate
)
else
:
else
:
print
(
plat
,
expired
,
total
)
print
(
plat
,
expired
,
total
)
if
msgs
:
if
msgs
:
ts
=
int
(
time
.
time
())
mysql_db
.
insert_expired_data
(
ts
,
json
.
dumps
(
expired_dict
))
return
msg
return
msg
else
:
else
:
return
return
...
...
utils/mysql.py
View file @
d2ed3cc3
...
@@ -58,3 +58,11 @@ class MySqlOperator:
...
@@ -58,3 +58,11 @@ class MySqlOperator:
"""
"""
cursor
.
execute
(
sql
,
(
s
,
u
))
cursor
.
execute
(
sql
,
(
s
,
u
))
self
.
db
.
commit
()
self
.
db
.
commit
()
def
insert_expired_data
(
self
,
time_stamp
,
platform_data
):
with
self
.
db
.
cursor
()
as
cursor
:
sql
=
"""
INSERT INTO lie_spider_expired_rate(time_stamp, platform_data) VALUES (
%
s,
%
s)
"""
cursor
.
execute
(
sql
,(
time_stamp
,
platform_data
))
self
.
db
.
commit
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment