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
07446ae5
authored
Apr 14, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
测试
parent
34c195bb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
28 deletions
utils/mongo.py
utils/mongo.py
View file @
07446ae5
...
@@ -6,8 +6,10 @@ import pymongo
...
@@ -6,8 +6,10 @@ import pymongo
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
glo
=
Glo
()
mysql_db
=
MySqlOperator
(
'dashboard'
)
glo
=
Glo
()
MG_HOST_SET
=
{
MG_HOST_SET
=
{
'test'
:
'192.168.1.237'
,
'test'
:
'192.168.1.237'
,
...
@@ -30,6 +32,9 @@ def get_mongo_conf():
...
@@ -30,6 +32,9 @@ def get_mongo_conf():
return
conf
return
conf
filter_pn
=
(
"cdi"
,
"richardsonrfpd"
,
"company"
,
"wpg"
,)
class
MongoOperator
:
class
MongoOperator
:
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -41,19 +46,19 @@ class MongoOperator:
...
@@ -41,19 +46,19 @@ class MongoOperator:
# element14 chip1stop ti
# element14 chip1stop ti
self
.
colls
=
(
'alliedelec'
,
'arrow'
,
'avnet'
,
'buerklin'
,
'digikey'
,
'master'
,
'rs'
,
'rochester'
,
self
.
colls
=
(
'alliedelec'
,
'arrow'
,
'avnet'
,
'buerklin'
,
'digikey'
,
'master'
,
'rs'
,
'rochester'
,
'verical'
,
"powell"
,
'microchip'
,
'tme'
,
'heilind'
,
'maxim'
,
'aipco'
,
'company'
,
'rutronik'
,
'verical'
,
"powell"
,
'microchip'
,
'tme'
,
'heilind'
,
'maxim'
,
'aipco'
,
'company'
,
'rutronik'
,
'mouser'
,
'corestaff'
,
'wpg'
,
'szlc'
,
'element14'
,
'chip1stop'
,
'future'
,
"nep"
,
"cdi"
,
'mouser'
,
'corestaff'
,
'wpg'
,
'szlc'
,
'element14'
,
'chip1stop'
,
'future'
,
"nep"
,
"cdi"
,
"nac"
,
"richardsonrfpd"
,
"pui"
)
"nac"
,
"richardsonrfpd"
,
"pui"
)
@staticmethod
@staticmethod
def
get_unexpired_time
(
plat
):
def
get_unexpired_time
(
plat
):
if
plat
==
'powell'
:
if
plat
==
'powell'
:
ts
=
int
(
time
.
time
())
-
3600
*
24
*
7
# 5d
ts
=
int
(
time
.
time
())
-
3600
*
24
*
7
# 5d
elif
plat
in
(
'digikey'
,):
elif
plat
in
(
'digikey'
,
'avnet'
,
):
ts
=
int
(
time
.
time
())
-
3600
*
72
# 72h
ts
=
int
(
time
.
time
())
-
3600
*
72
# 72h
elif
plat
in
(
'microchip'
,
'heilind'
,
'element14'
,
'chip1stop'
,
'future'
):
elif
plat
in
(
'microchip'
,
'heilind'
,
'element14'
,
'chip1stop'
,
'future'
,
):
ts
=
int
(
time
.
time
())
-
3600
*
24
# 24h
ts
=
int
(
time
.
time
())
-
3600
*
24
# 24h
elif
plat
in
(
"richardsonrfpd"
,):
ts
=
int
(
time
.
time
())
-
3600
*
96
# 96h
else
:
else
:
ts
=
int
(
time
.
time
())
-
3600
*
48
# 48
ts
=
int
(
time
.
time
())
-
3600
*
48
# 48
return
ts
return
ts
...
@@ -70,15 +75,16 @@ class MongoOperator:
...
@@ -70,15 +75,16 @@ class MongoOperator:
@staticmethod
@staticmethod
def
get_mongo_query
():
def
get_mongo_query
():
stock_query
=
{
"stock.1"
:{
"$lte"
:
0
}}
#
获取库存为零
stock_query
=
{
"stock.1"
:
{
"$lte"
:
0
}}
#
获取库存为零
tiered_query
=
{
"tiered"
:
[]}
#
获取价格阶梯为空
tiered_query
=
{
"tiered"
:
[]}
#
获取价格阶梯为空
total_query
=
{}
total_query
=
{}
return
stock_query
,
tiered_query
,
total_query
return
stock_query
,
tiered_query
,
total_query
def
get_platform_data_expired_rate
(
self
):
def
get_platform_data_expired_rate
(
self
):
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 +105,13 @@ class MongoOperator:
...
@@ -99,9 +105,13 @@ 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
())
for
k
,
v
in
expired_dict
.
items
():
mysql_db
.
insert_expired_data
(
ts
,
k
,
v
)
return
msg
return
msg
else
:
else
:
return
return
...
@@ -109,40 +119,42 @@ class MongoOperator:
...
@@ -109,40 +119,42 @@ class MongoOperator:
def
get_platform_none_data_rate
(
self
):
def
get_platform_none_data_rate
(
self
):
msg
=
'空数据预警 过去3小时内:
\n
'
msg
=
'空数据预警 过去3小时内:
\n
'
demo1
=
'平台:{} 第一次运行,库存空数据率为{:.2f}
%
,价格空数据率为{:.2f}
%
'
demo1
=
'平台:{} 第一次运行,库存空数据率为{:.2f}
%
,价格空数据率为{:.2f}
%
'
demo2
=
'平台:{} 相比上一次监控库存空数据率变化为{:.2f}
%
,价格空数据率变化为{:.2f}
%
'
demo2
=
'平台:{} 相比上一次监控库存空数据率变化为{:.2f}
%
,价格空数据率变化为{:.2f}
%
,当前空库存率为{:.2f}
%
,当前空价格率为{:.2f}
%
'
msgs
=
[]
msgs
=
[]
for
plat
in
self
.
colls
:
for
plat
in
self
.
colls
:
coll
=
self
.
db
[
plat
]
coll
=
self
.
db
[
plat
]
snq
,
tnq
,
tq
=
self
.
get_mongo_query
()
snq
,
tnq
,
tq
=
self
.
get_mongo_query
()
stock_num
=
coll
.
count
(
snq
)
stock_num
=
coll
.
count
(
snq
)
tiered_num
=
coll
.
count
(
tnq
)
tiered_num
=
coll
.
count
(
tnq
)
total
=
coll
.
count
(
tq
)
total
=
coll
.
count
(
tq
)
if
total
>
0
:
if
total
>
0
:
stock_rate
=
stock_num
/
total
*
100
stock_rate
=
stock_num
/
total
*
100
tiered_rate
=
tiered_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
None
old_tiered_rate
=
glo
.
get_value
(
plat
)[
"tiered"
]
if
glo
.
get_value
(
plat
)
else
0
old_tiered_rate
=
glo
.
get_value
(
plat
)[
"tiered"
]
if
glo
.
get_value
(
plat
)
else
None
if
stock_rate
>=
10
or
tiered_rate
>=
10
:
if
stock_rate
>=
10
or
tiered_rate
>=
10
:
msg_line
=
""
msg_line
=
""
if
old_stock_rate
==
0
:
if
old_stock_rate
is
None
or
old_tiered_rate
is
None
:
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
,
"空库存率"
,
stock_rate
,
"空价格率"
,
tiered_rate
,
)
,
"空库存率"
,
stock_rate
,
"空价格率"
,
tiered_rate
,
)
msg_line
=
demo1
.
format
(
plat
,
stock_rate
,
tiered_rate
)
msg_line
=
demo1
.
format
(
plat
,
stock_rate
,
tiered_rate
)
else
:
else
:
stock__ontrast_ratio
=
stock_rate
-
old_stock_rate
stock_ontrast_ratio
=
stock_rate
-
old_stock_rate
tiered__ontrast_ratio
=
tiered_rate
-
old_tiered_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
-
3
<
stock_ontrast_ratio
<
3
or
not
-
3
<
tiered_ontrast_ratio
<
3
or
stock_rate
>
90
or
tiered_rate
>
90
:
msg_line
=
demo2
.
format
(
plat
,
stock__ontrast_ratio
,
tiered__ontrast_ratio
)
if
plat
not
in
filter_pn
:
msg_line
=
demo2
.
format
(
plat
,
stock_ontrast_ratio
,
tiered_ontrast_ratio
,
stock_rate
,
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
,
"空库存率"
,
tiered_rate
)
stock_rate
,
"空价格率"
,
tiered_rate
,
"空库存变化率"
,
stock__ontrast_ratio
,
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
,
"空库存率"
,
"空价格变化率"
,
tiered__ontrast_ratio
,)
stock_rate
,
"空价格率"
,
tiered_rate
,
"空库存变化率"
,
stock_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
:
if
msg_line
:
msgs
.
append
(
msg_line
)
msgs
.
append
(
msg_line
)
msg
+=
msg_line
+
'
\n
'
msg
+=
msg_line
+
'
\n
'
else
:
else
:
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
)
print
(
plat
,
"空库存数量"
,
stock_num
,
"空价格数量"
,
stock_num
,
"总量"
,
total
)
if
msgs
:
if
msgs
:
return
msg
return
msg
else
:
else
:
...
...
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