add log error level count

pull/17608/head^2
fuwx 1 year ago
parent f8431313d3
commit 1a699a2481
No known key found for this signature in database
GPG Key ID: C8FA8C18DFB4702B

@ -0,0 +1,48 @@
import json
from collections.abc import Generator
from typing import Any, Optional
import requests
from configs import dify_config
from core.tools.builtin_tool.tool import BuiltinTool
from core.tools.entities.tool_entities import ToolInvokeMessage
from libs.apo_utils import APOUtils
class LogErrorLevelCountTool(BuiltinTool):
def _invoke(
self,
user_id: str,
tool_parameters: dict[str, Any],
conversation_id: Optional[str] = None,
app_id: Optional[str] = None,
message_id: Optional[str] = None,
) -> Generator[ToolInvokeMessage, None, None]:
pod_name = tool_parameters.get('pod_name', '.*')
namespace = tool_parameters.get('namespace', '.*')
pid = tool_parameters.get('pid', '.*')
start_time = tool_parameters.get("startTime")
end_time = tool_parameters.get("endTime")
params = {
'metricName': '宿主机监控指标 - 日志解析错误计数总览 - log error level count',
'params': {
'pod_name': pod_name,
'namespace': namespace,
'pid': pid
},
'startTime': start_time,
'endTime': end_time,
'step': APOUtils.get_step(start_time, end_time),
}
resp = requests.post(dify_config.APO_BACKEND_URL + '/api/metric/query', json=params)
list = resp.json()['result']
list = json.dumps({
'type': 'metric',
'display': True,
'unit': list['unit'],
'data': {
'timeseries': list['timeseries']
}
})
yield self.create_text_message(list)

@ -0,0 +1,75 @@
identity:
name: 记录了日志解析系统中按错误级别统计的总次数
author: APO
label:
en_US: Records the total count of log parsing system errors categorized by error level
zh_Hans: 记录了日志解析系统中按错误级别统计的总次数
description:
human:
en_US: Records the total count of log parsing system errors categorized by error level
zh_Hans: 记录了日志解析系统中按错误级别统计的总次数
llm: Records the total count of log parsing system errors categorized by error level
display:
type: metric
title: 宿主机监控指标 - 日志解析错误计数总览 - log error level count
unit: "short"
parameters:
- name: pod_name
type: string
required: False
label:
en_US: Pod name
zh_Hans: Pod名称
human_description:
en_US: Pod name
zh_Hans: Pod名称
llm_description: Pod name
form: llm
- name: namespace
type: string
required: False
label:
en_US: Namespace
zh_Hans: 命名空间
human_description:
en_US: Namespace
zh_Hans: 命名空间
llm_description: Namespace
form: llm
- name: pid
type: string
required: False
label:
en_US: Process ID
zh_Hans: 进程ID
human_description:
en_US: Process ID
zh_Hans: 进程ID
llm_description: Process ID
form: llm
- name: startTime
type: number
required: true
label:
en_US: startTime
zh_Hans: startTime
pt_BR: startTime
human_description:
en_US: Data query start time(Microsecond)
zh_Hans: 开始时间 (微秒)
pt_BR: Data query start time
llm_description: Data query start time(Microsecond)
form: llm
- name: endTime
type: number
required: true
label:
en_US: endTime
zh_Hans: endTime
pt_BR: endTime
human_description:
en_US: Data query end time(Microsecond)
zh_Hans: 结束时间 (微秒)
pt_BR: Data query end time(Microsecond)
llm_description: Data query end time(Microsecond)
form: llm

@ -41,15 +41,13 @@ class ThreadPolarisP90(BuiltinTool):
values = [float(value[1]) for value in entry["values"]] values = [float(value[1]) for value in entry["values"]]
stats[tid] = { stats[tid] = {
"max": max(values), "avg": sum(values) / len(values),
"min": min(values)
} }
return json.dumps(stats) return json.dumps(stats)
def get_metrics(self, type: str, pod: str, start: int, end: int) -> dict: def get_metrics(self, type: str, pod: str, start: int, end: int) -> dict:
pre_query = '''histogram_quantile(0.9, sum(rate(originx_thread_polaris_nanoseconds_bucket{pod="''' query = 'increase(originx_thread_polaris_nanoseconds_sum{pod="' + pod + '", type="cpu"}[1m])'
query = pre_query + pod + '''", type="''' + type + '''"}[1m])) by (tid, vmrange))'''
step = '10m' step = '10m'
hour = 3600 * 1000 hour = 3600 * 1000

@ -11,6 +11,8 @@ import os
def run_initializers(app: Flask): def run_initializers(app: Flask):
if os.environ.get("MODE") != "api": if os.environ.get("MODE") != "api":
return return
if os.environ.get("APO_INIT") == "false":
return
with app.app_context(): with app.app_context():
for func, _ in sorted(_initializers, key=lambda x: x[1]): for func, _ in sorted(_initializers, key=lambda x: x[1]):
func() func()
Loading…
Cancel
Save