{"id":28960237,"url":"https://github.com/lework/dify-plugin-prometheus","last_synced_at":"2025-07-08T07:33:00.617Z","repository":{"id":282389502,"uuid":"948430289","full_name":"lework/dify-plugin-prometheus","owner":"lework","description":"dify-plugin-prometheus","archived":false,"fork":false,"pushed_at":"2025-07-01T09:01:42.000Z","size":34,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T09:44:23.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-14T10:21:27.000Z","updated_at":"2025-07-01T08:59:59.000Z","dependencies_parsed_at":"2025-03-14T11:38:38.649Z","dependency_job_id":null,"html_url":"https://github.com/lework/dify-plugin-prometheus","commit_stats":null,"previous_names":["lework/dify-plugin-prometheus"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lework/dify-plugin-prometheus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lework%2Fdify-plugin-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lework%2Fdify-plugin-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lework%2Fdify-plugin-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lework%2Fdify-plugin-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lework","download_url":"https://codeload.github.com/lework/dify-plugin-prometheus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lework%2Fdify-plugin-prometheus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264221795,"owners_count":23575104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-24T01:10:59.500Z","updated_at":"2025-07-08T07:33:00.612Z","avatar_url":"https://github.com/lework.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## prometheus\n\n**Author:** lework\n**Version:** 0.0.1\n**Type:** tool\n\n### Description\n\n## 创建 Dify 插件\n\ndify plugin init\n\n## 打包插件\n\ndify plugin package ./prometheus\n\n# Prometheus 查询插件\n\nDify 的 Prometheus 查询插件，允许用户通过 PromQL 查询 Prometheus 指标数据。\n\n## 功能\n\n- 使用 PromQL 查询 Prometheus 指标数据\n- 支持时间范围查询（相对时间和绝对时间）\n- 支持基本认证和令牌认证\n- 自动格式化结果以便于理解\n- **支持 Markdown 表格输出**，将标签作为列清晰展示每个指标的最新值\n- **Kubernetes Pod 资源指标查询**，获取 Pod 的 CPU、内存使用情况和重启次数\n\n## 配置\n\n在使用此插件前，需要配置以下信息：\n\n- **API URL**: Prometheus 服务器的 URL，例如 `http://localhost:9090`\n- **用户名/密码**: (可选) 基本认证的用户名和密码\n- **令牌**: (可选) Bearer 令牌认证\n\n## 工具\n\n### 1. Prometheus 查询\n\n#### 参数\n\n- **PromQL 查询语句**: 必填，要执行的 PromQL 查询语句\n- **开始时间**: 可选，查询的开始时间，支持以下格式：\n  - RFC3339/ISO8601 格式: `2023-01-01T00:00:00Z`\n  - 相对时间: `1h`, `2d`, `3w`, `4m`, `5y` 等\n  - 默认值: `1h` (1 小时前)\n- **结束时间**: 可选，查询的结束时间，支持与开始时间相同的格式\n  - 默认值: `now` (当前时间)\n- **步长**: 可选，查询分辨率步长\n  - 格式: `15s`, `1m`, `1h` 等\n  - 默认值: `15s` (15 秒)\n\n#### 示例\n\n##### 查询 CPU 使用率\n\n```\nquery: 100 - (avg by (instance) (irate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)\nstart_time: 1h\nend_time: now\nstep: 1m\n```\n\n##### 查询内存使用率\n\n```\nquery: 100 * (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes))\nstart_time: 12h\nend_time: now\nstep: 5m\n```\n\n### 2. Kubernetes Pod 资源指标查询\n\n获取 Kubernetes Pod 的资源使用情况，包括 CPU、内存使用率以及重启次数等信息，并以 Markdown 表格的形式展示。\n\n#### 参数\n\n- **命名空间**: 可选，Kubernetes 命名空间名称，不填则查询所有命名空间\n- **标签选择器**: 可选，用于过滤 Pod 的标签选择器，例如 `app=myapp,component=database`\n- **Pod 名称模式**: 可选，用于过滤 Pod 名称的正则表达式，例如 `frontend-.*`\n\n#### 示例\n\n##### 查询特定命名空间的 Pod 资源使用情况\n\n```\nnamespace: default\n```\n\n##### 查询特定应用的 Pod 资源使用情况\n\n```\nselector: app=myapp\n```\n\n##### 查询特定前缀的 Pod 资源使用情况\n\n```\npod_name_pattern: frontend-.*\n```\n\n#### 返回结果\n\n返回包含以下信息的 Markdown 表格：\n\n| Pod 名称 | 存活时长 | 命名空间 | 节点  | 就绪状态 | Phase   | CPU 使用% | 内存使用 MiB | CPU 请求 | CPU 限制 | 内存请求 MiB | 内存限制 MiB | 24h 重启次数 |\n| -------- | -------- | -------- | ----- | -------- | ------- | --------- | ------------ | -------- | -------- | ------------ | ------------ | ------------ |\n| pod-1    | 1.0 天   | default  | node1 | ✓        | Running | 0.819%    | 500 MiB      | 0.100    | 1        | 500 MiB      | 2 GiB        | 0            |\n| pod-2    | 1.7 天   | default  | node2 | ✓        | Running | 0.380%    | 256 MiB      | 0.100    | 1        | 256 MiB      | 2 GiB        | 0            |\n\n## 返回结果\n\n### Markdown 表格格式 (新增特性)\n\n对于矩阵类型的查询结果，插件会生成 Markdown 表格，**将标签作为表格列**，便于清晰展示数据：\n\n```markdown\n### node_cpu_seconds_total\n\n| timestamp           | instance       | job        | mode   | value |\n| :------------------ | :------------- | :--------- | :----- | ----: |\n| 2023-03-11T18:15:00 | 10.131.242.148 | prometheus | idle   | 0.278 |\n| 2023-03-11T18:15:00 | 10.131.242.149 | prometheus | system | 0.156 |\n\n_显示最近的数据点_\n```\n\n### JSON 格式\n\n当无法生成 Markdown 表格时，插件会返回 JSON 格式的完整结果：\n\n```json\n{\n  \"success\": true,\n  \"result_type\": \"matrix\",\n  \"data\": [\n    {\n      \"metric\": \"metric_name\",\n      \"labels\": {\n        \"instance\": \"localhost:9090\",\n        \"job\": \"prometheus\"\n      },\n      \"values\": [\n        {\n          \"timestamp\": \"2023-01-01T00:00:00.000000\",\n          \"value\": 12.34\n        },\n        ...\n      ]\n    },\n    ...\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flework%2Fdify-plugin-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flework%2Fdify-plugin-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flework%2Fdify-plugin-prometheus/lists"}