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
8911f4dc
authored
Nov 21, 2019
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update pep8
parent
2d8a3116
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
28 deletions
monitor.py
utils/glo.py
utils/mongo.py
monitor.py
View file @
8911f4dc
...
...
@@ -58,10 +58,11 @@ def task_running_flag_monitor():
dd_send_msg
(
traceback
.
format_exc
())
time
.
sleep
(
60
*
5
)
def
mongo_none_data_rate_monitor
():
while
True
:
try
:
msg
=
mongo
.
get_platform_none_data_rate
()
msg
=
mongo
.
get_platform_none_data_rate
()
if
msg
:
logger
.
info
(
msg
)
dd_send_msg
(
msg
)
...
...
@@ -71,6 +72,7 @@ def mongo_none_data_rate_monitor():
dd_send_msg
(
traceback
.
format_exc
())
time
.
sleep
(
60
*
5
)
def
main
():
thread_monitor1
=
threading
.
Thread
(
target
=
task_fail_rate_monitor
)
thread_monitor1
.
start
()
...
...
utils/glo.py
View file @
8911f4dc
...
...
@@ -5,14 +5,13 @@ class Glo():
global
_global_dict
_global_dict
=
{}
def
set_value
(
self
,
key
,
value
):
def
set_value
(
self
,
key
,
value
):
_global_dict
[
key
]
=
value
def
get_value
(
self
,
key
):
def
get_value
(
self
,
key
):
try
:
return
_global_dict
[
key
]
except
KeyError
:
return
None
\ No newline at end of file
return
None
utils/mongo.py
View file @
8911f4dc
...
...
@@ -7,7 +7,7 @@ import pymongo
from
utils.glo
import
Glo
from
urllib.parse
import
quote_plus
glo
=
Glo
()
glo
=
Glo
()
MG_HOST_SET
=
{
'test'
:
'192.168.1.237'
,
...
...
@@ -41,10 +41,8 @@ class MongoOperator:
# element14 chip1stop ti
self
.
colls
=
(
'alliedelec'
,
'arrow'
,
'avnet'
,
'buerklin'
,
'digikey'
,
'master'
,
'rs'
,
'rochester'
,
'verical'
,
"powell"
,
'microchip'
,
'tme'
,
'heilind'
,
'maxim'
,
'aipco'
,
'company'
,
'rutronik'
,
'mouser'
,
'corestaff'
,
'wpg'
,
'szlc'
,
'element14'
,
'chip1stop'
,
'future'
,
"nep"
,
"cdi"
,
"nac"
,
"richardsonrfpd"
,
"pui"
)
'mouser'
,
'corestaff'
,
'wpg'
,
'szlc'
,
'element14'
,
'chip1stop'
,
'future'
,
"nep"
,
"cdi"
,
"nac"
,
"richardsonrfpd"
,
"pui"
)
@staticmethod
def
get_unexpired_time
(
plat
):
...
...
@@ -70,10 +68,10 @@ class MongoOperator:
@staticmethod
def
get_mongo_query
():
stock_query
=
{
"stock.1"
:{
"$lte"
:
0
}}
#
获取库存为零
tiered_query
=
{
"tiered"
:
[]}
#
获取价格阶梯为空
stock_query
=
{
"stock.1"
:
{
"$lte"
:
0
}}
#
获取库存为零
tiered_query
=
{
"tiered"
:
[]}
#
获取价格阶梯为空
total_query
=
{}
return
stock_query
,
tiered_query
,
total_query
return
stock_query
,
tiered_query
,
total_query
def
get_platform_data_expired_rate
(
self
):
msg
=
'数据过期率监控预警 过去3小时内:
\n
'
...
...
@@ -113,37 +111,35 @@ class MongoOperator:
msgs
=
[]
for
plat
in
self
.
colls
:
coll
=
self
.
db
[
plat
]
snq
,
tnq
,
tq
=
self
.
get_mongo_query
()
snq
,
tnq
,
tq
=
self
.
get_mongo_query
()
stock_num
=
coll
.
count
(
snq
)
tiered_num
=
coll
.
count
(
tnq
)
total
=
coll
.
count
(
tq
)
if
total
>
0
:
if
total
>
0
:
stock_rate
=
stock_num
/
total
*
100
tiered_rate
=
tiered_num
/
total
*
100
old_stock_rate
=
glo
.
get_value
(
plat
)[
"stock"
]
if
glo
.
get_value
(
plat
)
else
0
old_stock_rate
=
glo
.
get_value
(
plat
)[
"stock"
]
if
glo
.
get_value
(
plat
)
else
0
old_tiered_rate
=
glo
.
get_value
(
plat
)[
"tiered"
]
if
glo
.
get_value
(
plat
)
else
0
if
stock_rate
>=
10
or
tiered_rate
>=
10
:
msg_line
=
""
if
old_stock_rate
==
0
:
msg_line
=
""
if
old_stock_rate
==
0
:
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
,
"空库存率"
,
stock_rate
,
"空价格率"
,
tiered_rate
,
)
msg_line
=
demo1
.
format
(
plat
,
stock_rate
,
tiered_rate
)
msg_line
=
demo1
.
format
(
plat
,
stock_rate
,
tiered_rate
)
else
:
stock__ontrast_ratio
=
stock_rate
-
old_stock_rate
tiered__ontrast_ratio
=
tiered_rate
-
old_tiered_rate
if
not
-
10
<
stock__ontrast_ratio
<
10
or
not
-
10
<
tiered__ontrast_ratio
<
10
:
if
not
-
10
<
stock__ontrast_ratio
<
10
or
not
-
10
<
tiered__ontrast_ratio
<
10
:
msg_line
=
demo2
.
format
(
plat
,
stock__ontrast_ratio
,
tiered__ontrast_ratio
)
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
,
"空库存率"
,
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
,
"空库存率"
,
stock_rate
,
"空价格率"
,
tiered_rate
,
"空库存变化率"
,
stock__ontrast_ratio
,
"空价格变化率"
,
tiered__ontrast_ratio
,)
glo
.
set_value
(
plat
,
{
"stock"
:
stock_rate
,
"tiered"
:
tiered_rate
})
"空价格变化率"
,
tiered__ontrast_ratio
,
)
glo
.
set_value
(
plat
,
{
"stock"
:
stock_rate
,
"tiered"
:
tiered_rate
})
if
msg_line
:
msgs
.
append
(
msg_line
)
msg
+=
msg_line
+
'
\n
'
else
:
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
)
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
)
if
msgs
:
return
msg
else
:
return
\ 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