add preview api
parent
a6767d746d
commit
ab453fa9d6
@ -1,88 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class FaultLogTool(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]:
|
|
||||||
service = tool_parameters.get("service")
|
|
||||||
endpoint = tool_parameters.get("endpoint")
|
|
||||||
entryService = tool_parameters.get("entryService")
|
|
||||||
entryEndpoint = tool_parameters.get("entryEndpoint")
|
|
||||||
start_time = tool_parameters.get("startTime")
|
|
||||||
end_time = tool_parameters.get("endTime")
|
|
||||||
type = tool_parameters.get("type")
|
|
||||||
|
|
||||||
params = {
|
|
||||||
"anormalTypes": "app,container,infra,network,error,appInstance",
|
|
||||||
"endTime": end_time,
|
|
||||||
"endpoint": endpoint,
|
|
||||||
"entryEndpoint": entryEndpoint,
|
|
||||||
"entryService": entryService,
|
|
||||||
"service": service,
|
|
||||||
"startTime": start_time,
|
|
||||||
"step": self.get_step(start_time, end_time),
|
|
||||||
"type": [type],
|
|
||||||
"withTopology": True,
|
|
||||||
}
|
|
||||||
|
|
||||||
url = "http://192.168.1.6:13680/api/nodeinfo"
|
|
||||||
res = {}
|
|
||||||
with requests.post(url, json=params, stream=True) as response:
|
|
||||||
# 逐行读取流式响应
|
|
||||||
for line in response.iter_lines():
|
|
||||||
if line: # 过滤空行
|
|
||||||
# 解码字节为字符串
|
|
||||||
decoded_line = line.decode('utf-8')
|
|
||||||
res = json.loads(decoded_line[5:].strip())
|
|
||||||
list = json.dumps({
|
|
||||||
'type': 'nodeinfo',
|
|
||||||
'display': True,
|
|
||||||
'data': res,
|
|
||||||
})
|
|
||||||
yield self.create_text_message(list)
|
|
||||||
|
|
||||||
def get_step(self, start_time, end_time):
|
|
||||||
time_diff = end_time - start_time
|
|
||||||
|
|
||||||
SECOND = 1000000 # microseconds
|
|
||||||
MINUTE = 60 * SECOND
|
|
||||||
HOUR = 60 * MINUTE
|
|
||||||
|
|
||||||
step = SECOND # default step is 1 second
|
|
||||||
|
|
||||||
if time_diff <= 15 * MINUTE:
|
|
||||||
step = 30 * SECOND
|
|
||||||
elif time_diff <= 30 * MINUTE:
|
|
||||||
step = 1 * MINUTE
|
|
||||||
elif time_diff <= 1 * HOUR:
|
|
||||||
step = 2 * MINUTE
|
|
||||||
elif time_diff <= 1.5 * HOUR:
|
|
||||||
step = 3 * MINUTE
|
|
||||||
elif time_diff <= 3 * HOUR:
|
|
||||||
step = 6 * MINUTE
|
|
||||||
elif time_diff <= 6 * HOUR:
|
|
||||||
step = 12 * MINUTE
|
|
||||||
elif time_diff <= 12 * HOUR:
|
|
||||||
step = 24 * MINUTE
|
|
||||||
elif time_diff <= 15 * HOUR:
|
|
||||||
step = 30 * MINUTE
|
|
||||||
elif time_diff <= 30 * HOUR:
|
|
||||||
step = 1 * HOUR
|
|
||||||
else:
|
|
||||||
step = ((time_diff + 30 * SECOND - 1) // (30 * SECOND)) * SECOND
|
|
||||||
|
|
||||||
return step
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
identity:
|
|
||||||
name: node_info
|
|
||||||
author: APO
|
|
||||||
label:
|
|
||||||
en_US: node_info
|
|
||||||
zh_Hans: 获取节点信息
|
|
||||||
pt_BR: node_info
|
|
||||||
description:
|
|
||||||
human:
|
|
||||||
en_US: A tool for getting fault log.
|
|
||||||
zh_Hans: 获取节点信息
|
|
||||||
pt_BR: A tool for getting fault log.
|
|
||||||
llm: A tool for getting fault log.
|
|
||||||
display:
|
|
||||||
type: info
|
|
||||||
unit: info
|
|
||||||
parameters:
|
|
||||||
- name: entryService
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
label:
|
|
||||||
en_US: entryService
|
|
||||||
zh_Hans: 入口服务名
|
|
||||||
pt_BR: entryService
|
|
||||||
human_description:
|
|
||||||
en_US: Time format in strftime standard.
|
|
||||||
zh_Hans: 拓扑入口服务名
|
|
||||||
pt_BR: Time format in strftime standard.
|
|
||||||
llm_description: toplogy service name
|
|
||||||
form: llm
|
|
||||||
- name: entryEndpoint
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
label:
|
|
||||||
en_US: entryEndpoint
|
|
||||||
zh_Hans: 入口服务端点
|
|
||||||
pt_BR: entryEndpoint
|
|
||||||
human_description:
|
|
||||||
en_US: Time format in strftime standard.
|
|
||||||
zh_Hans: 拓扑入口服务端点
|
|
||||||
pt_BR: Time format in strftime standard.
|
|
||||||
llm_description: toplogy endpoint
|
|
||||||
form: llm
|
|
||||||
- name: service
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
label:
|
|
||||||
en_US: service
|
|
||||||
zh_Hans: 服务名
|
|
||||||
pt_BR: service
|
|
||||||
human_description:
|
|
||||||
en_US: Time format in strftime standard.
|
|
||||||
zh_Hans: 查询指定服务的名称
|
|
||||||
pt_BR: Time format in strftime standard.
|
|
||||||
llm_description: Time format in strftime standard.
|
|
||||||
form: llm
|
|
||||||
- name: endpoint
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
label:
|
|
||||||
en_US: endpoint
|
|
||||||
zh_Hans: 服务端点
|
|
||||||
pt_BR: endpoint
|
|
||||||
human_description:
|
|
||||||
en_US: Time format in strftime standard.
|
|
||||||
zh_Hans: 指定服务的端点
|
|
||||||
pt_BR: Time format in strftime standard.
|
|
||||||
llm_description: toplogy endpoint
|
|
||||||
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
|
|
||||||
zh_Hans: 开始时间 (微秒)
|
|
||||||
pt_BR: Data query start time
|
|
||||||
llm_description: Data query start time
|
|
||||||
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
|
|
||||||
zh_Hans: 结束时间 (微秒)
|
|
||||||
pt_BR: Data query end time
|
|
||||||
llm_description: Data query start time
|
|
||||||
form: llm
|
|
||||||
- name: type
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
label:
|
|
||||||
en_US: type
|
|
||||||
zh_Hans: 查询数据类型(log, slow, error)
|
|
||||||
pt_BR: type
|
|
||||||
human_description:
|
|
||||||
en_US: Time format in strftime standard.
|
|
||||||
zh_Hans: 指定查询数据类型(log, slow, error)。
|
|
||||||
pt_BR: Time format in strftime standard.
|
|
||||||
llm_description: Time format in strftime standard.
|
|
||||||
form: llm
|
|
||||||
Loading…
Reference in New Issue