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
522c98d5
authored
Apr 08, 2022
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更改es查询语法
parent
e9b6130b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
crawler_process.py
crawler_process.py
View file @
522c98d5
...
...
@@ -5,10 +5,11 @@ import hashlib
import
os
import
time
import
traceback
import
requests
from
datetime
import
datetime
,
timedelta
import
psutil
from
elasticsearch
import
Elasticsearch
#
from elasticsearch import Elasticsearch
from
utils.log_manage
import
get_logger
from
utils.mysql
import
MySqlOperator
...
...
@@ -17,7 +18,9 @@ from utils.tas_redis import task_redis
logger
=
get_logger
(
'crawler_process'
)
dashboard
=
MySqlOperator
(
'dashboard'
)
ichunt_elk
=
Elasticsearch
(
host
=
"172.18.137.50"
,
port
=
9200
,
timeout
=
20
)
# ichunt_elk = Elasticsearch(host="172.18.137.50", port=9200, timeout=20)
def
get_process_task
(
task_code
):
...
...
@@ -44,7 +47,7 @@ def get_error_ratio(task_code, time_range=30):
{
"range"
:
{
"@timestamp"
:
{
"gte"
:
utc_since
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ"
)
"gte"
:
utc_since
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S
.000
Z"
)
}
}
}
...
...
@@ -59,9 +62,12 @@ def get_error_ratio(task_code, time_range=30):
}
}
}
response
=
ichunt_elk
.
search
(
index
=
index
,
doc_type
=
'doc'
,
body
=
query
)
value
=
response
[
'aggregations'
][
'avgFailRate'
][
'value'
]
value
=
value
if
value
is
not
None
else
0.0
# response = ichunt_elk.search(index=index, doc_type='doc', body=query)
url
=
"http://172.18.137.50:9200/"
+
index
+
"/_search"
res
=
requests
.
post
(
url
,
json
=
query
)
# value = response['aggregations']['avgFailRate']['value']
value
=
res
.
json
()[
'aggregations'
][
'avgFailRate'
][
'value'
]
if
res
.
status_code
!=
200
else
0.0
return
round
(
value
,
3
)
...
...
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