add rtt tool
parent
0734216837
commit
b1efce3e34
@ -0,0 +1,43 @@
|
|||||||
|
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 core.tools.builtin_tool.providers.utils import APOUtils
|
||||||
|
|
||||||
|
class ContainerRTTTool(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 = tool_parameters.get("pod")
|
||||||
|
namespace = tool_parameters.get("namespace")
|
||||||
|
start_time = tool_parameters.get("startTime")
|
||||||
|
end_time = tool_parameters.get("endTime")
|
||||||
|
params = {
|
||||||
|
'metricName': '基础设施情况 - 容器网络 - 与下游服务RTT',
|
||||||
|
'params': {
|
||||||
|
"pod": pod,
|
||||||
|
"namespace": namespace
|
||||||
|
},
|
||||||
|
'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': 'memory',
|
||||||
|
'display': True,
|
||||||
|
'unit': list['unit'],
|
||||||
|
'data': list['timeseries']
|
||||||
|
})
|
||||||
|
yield self.create_text_message(list)
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
identity:
|
||||||
|
name: container_rtt
|
||||||
|
author: APO
|
||||||
|
label:
|
||||||
|
en_US: Query container rtt
|
||||||
|
zh_Hans: 查询容器网络与下游RTT
|
||||||
|
pt_BR: Query container rtt
|
||||||
|
description:
|
||||||
|
human:
|
||||||
|
en_US: Query container rtt
|
||||||
|
zh_Hans: 查询容器网络与下游RTT
|
||||||
|
pt_BR: Query container rtt
|
||||||
|
llm: Query container rtt
|
||||||
|
display:
|
||||||
|
type: network
|
||||||
|
unit: seconds
|
||||||
|
parameters:
|
||||||
|
- name: pod
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
label:
|
||||||
|
en_US: pod
|
||||||
|
zh_Hans: pod
|
||||||
|
pt_BR: pod
|
||||||
|
human_description:
|
||||||
|
en_US: Specified pod name
|
||||||
|
zh_Hans: 指定的容器POD名称
|
||||||
|
pt_BR: Specified pod name
|
||||||
|
llm_description: Specified pod name
|
||||||
|
form: llm
|
||||||
|
- name: namespace
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
label:
|
||||||
|
en_US: namespace
|
||||||
|
zh_Hans: namespace
|
||||||
|
pt_BR: namespace
|
||||||
|
human_description:
|
||||||
|
en_US: Specified namespace
|
||||||
|
zh_Hans: 指定的容器所在Namespace
|
||||||
|
pt_BR: Specified namespace
|
||||||
|
llm_description: Specified namespace
|
||||||
|
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
|
||||||
Loading…
Reference in New Issue