prometheus
Author: lework
Version: 0.0.2
Type: tool
Description
Creating a Dify Plugin
dify plugin init
Packaging the Plugin
dify plugin package ./prometheus
Prometheus Query Plugin
A Prometheus query plugin for Dify that allows users to query Prometheus metric data using PromQL.
Features
- Query Prometheus metric data using PromQL
- Support for time range queries (relative and absolute time)
- Support for basic authentication and token authentication
- Automatic formatting of results for easy understanding
- Support for Markdown table output, clearly displaying the latest value of each metric with labels as columns
- Kubernetes Pod resource metrics query, getting CPU, memory usage and restart count for Pods
Configuration
Before using this plugin, you need to configure the following information:
- API URL: The URL of the Prometheus server, e.g.,
- Username/Password: (Optional) Username and password for basic authentication
- Token: (Optional) Bearer token for authentication
Tools
1. Prometheus Query
Parameters
- PromQL Query Statement: Required, the PromQL query statement to execute
- Start Time: Optional, the start time of the query, supports the following formats:
- RFC3339/ISO8601 format:
- Relative time: , , , , , etc.
- Default value: (1 hour ago)
- End Time: Optional, the end time of the query, supports the same formats as the start time
- Default value: (current time)
- Step: Optional, the resolution step of the query
- Format: , , , etc.
- Default value: (15 seconds)
Examples
Query CPU Usage
Query Memory Usage
2. Kubernetes Pod Resource Metrics Query
Get resource usage information for Kubernetes Pods, including CPU, memory usage and restart count, displayed in Markdown table format.
Parameters
- Namespace: Optional, Kubernetes namespace name, if not specified, queries all namespaces
- Label Selector: Optional, label selector to filter Pods, e.g.,
- Pod Name Pattern: Optional, regular expression to filter Pod names, e.g.,
Examples
Query Pod Resource Usage in a Specific Namespace
Query Pod Resource Usage for a Specific Application
Query Pod Resource Usage with a Specific Prefix
Return Result
Returns a Markdown table containing the following information:
Return Results
Markdown Table Format (New Feature)
For matrix type query results, the plugin will generate a Markdown table, using labels as table columns, making it easier to clearly display the data:
JSON Format
When a Markdown table cannot be generated, the plugin will return the complete result in JSON format: