list_prometheus_label_values
Retrieve available values for a specific Prometheus label, with options to filter by series selectors and time range for precise monitoring data analysis.
Instructions
Get the values for a specific label name in Prometheus. Allows filtering by series selectors and time range.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datasourceUid | Yes | The UID of the datasource to query | |
| endRfc3339 | No | The end time of the query | |
| labelName | Yes | The name of the label to query | |
| limit | No | Maximum number of results | |
| matches | No | Selectors to filter the results | |
| startRfc3339 | No | The start time of the query |
Input Schema (JSON Schema)
{
"properties": {
"datasourceUid": {
"description": "The UID of the datasource to query",
"type": "string"
},
"endRfc3339": {
"description": "The end time of the query",
"type": "string"
},
"labelName": {
"description": "The name of the label to query",
"type": "string"
},
"limit": {
"description": "Maximum number of results",
"type": "number"
},
"matches": {
"description": "Selectors to filter the results",
"items": {
"additionalProperties": false,
"properties": {
"filters": {
"items": {
"additionalProperties": false,
"properties": {
"name": {
"description": "The name of the label to match against",
"type": "string"
},
"type": {
"description": "The match operator",
"enum": [
"=",
"!=",
"=~",
"!~"
],
"type": "string"
},
"value": {
"description": "The value to match against",
"type": "string"
}
},
"required": [
"name",
"value",
"type"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"filters"
],
"type": "object"
},
"type": "array"
},
"startRfc3339": {
"description": "The start time of the query",
"type": "string"
}
},
"required": [
"datasourceUid",
"labelName"
],
"type": "object"
}
Implementation Reference
- src/tools/prometheus.ts:190-213 (handler)The ToolDefinition object including the handler function that executes the logic for listing Prometheus label values using the PrometheusClient.export const listPrometheusLabelValues: ToolDefinition = { name: 'list_prometheus_label_values', description: 'Get the values for a specific label name in Prometheus. Allows filtering by series selectors and time range.', inputSchema: ListPrometheusLabelValuesSchema, handler: async (params, context: ToolContext) => { try { const client = new PrometheusClient(context.config.grafanaConfig, params.datasourceUid); const match = params.matches?.map((m: any) => buildSelector(m.filters)) || []; const values = await client.getLabelValues( params.labelName, match.length > 0 ? match : undefined, params.startRfc3339, params.endRfc3339 ); const limited = params.limit ? values.slice(0, params.limit) : values; return createToolResult(limited); } catch (error: any) { return createErrorResult(error.message); } }, };
- src/tools/prometheus.ts:35-48 (schema)Zod schema defining the input parameters for the list_prometheus_label_values tool.const ListPrometheusLabelValuesSchema = z.object({ datasourceUid: z.string().describe('The UID of the datasource to query'), labelName: z.string().describe('The name of the label to query'), matches: z.array(z.object({ filters: z.array(z.object({ name: z.string().describe('The name of the label to match against'), value: z.string().describe('The value to match against'), type: z.enum(['=', '!=', '=~', '!~']).describe('The match operator'), })), })).optional().describe('Selectors to filter the results'), startRfc3339: z.string().optional().describe('The start time of the query'), endRfc3339: z.string().optional().describe('The end time of the query'), limit: z.number().optional().describe('Maximum number of results'), });
- src/tools/prometheus.ts:232-238 (registration)Registration function for Prometheus tools, including the registration of listPrometheusLabelValues tool.export function registerPrometheusTools(server: any) { server.registerTool(queryPrometheus); server.registerTool(listPrometheusMetricNames); server.registerTool(listPrometheusLabelNames); server.registerTool(listPrometheusLabelValues); server.registerTool(listPrometheusMetricMetadata); }
- src/tools/prometheus.ts:84-98 (helper)Helper function used in the handler to build Prometheus label matchers/selectors from input filters.function buildSelector(filters: any[]): string { if (!filters || filters.length === 0) return '{}'; const parts = filters.map(f => { switch (f.type) { case '=': return `${f.name}="${f.value}"`; case '!=': return `${f.name}!="${f.value}"`; case '=~': return `${f.name}=~"${f.value}"`; case '!~': return `${f.name}!~"${f.value}"`; default: return ''; } }).filter(p => p); return `{${parts.join(',')}}`; }