Commit 522c98d5 by 陈森彬

更改es查询语法

parent e9b6130b
Showing with 12 additions and 6 deletions
......@@ -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.000Z")
}
}
}
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment