This project includes an AI-powered chatbot that can translate natural language questions into PromQL queries using OpenAI's GPT models.
- Natural Language to PromQL: Ask questions like "What is my memory usage?" and get translated PromQL queries
- Smart Metric Selection: AI automatically selects the most appropriate metrics from your available Prometheus metrics
- Interactive Chat Interface: Chat with the AI assistant directly in the Query tab
- Query Suggestions: Get AI-powered PromQL query suggestions
- Seamless Integration: Generated queries can be directly used in the PromQL input
- Visit OpenAI Platform
- Sign in or create an account
- Create a new API key
- Copy the API key (it starts with
sk-)
Set the OPENAI_API_KEY environment variable:
Linux/macOS:
export OPENAI_API_KEY="sk-your-api-key-here"Windows:
set OPENAI_API_KEY=sk-your-api-key-hereDocker:
docker run -e OPENAI_API_KEY="sk-your-api-key-here" your-imageDocker Compose:
environment:
- OPENAI_API_KEY=sk-your-api-key-hereThe OpenAI package has been added to requirements.txt. Install it:
pip install -r requirements.txtRestart your FastAPI backend for the changes to take effect.
- Navigate to the Query tab
- Click the AI Assistant button to switch to AI mode
- Ask questions like:
- "What is my memory usage?"
- "Show me CPU utilization"
- "How much disk space is available?"
- "What's the network traffic like?"
- "Is my system running properly?"
The AI will:
- Translate your question to PromQL
- Explain why it chose specific metrics
- Show which metrics were used
- Provide buttons to:
- Use Query: Copy the generated PromQL to the input field
- Copy: Copy the PromQL to clipboard
- AI Mode: Chat with the AI assistant
- PromQL Mode: Direct PromQL query input (default)
| Natural Language | Generated PromQL | Explanation |
|---|---|---|
| "What is my memory usage?" | go_memstats_alloc_bytes |
Shows current memory allocation |
| "Show me CPU utilization" | rate(node_cpu_seconds_total[5m]) |
CPU usage rate over 5 minutes |
| "How much disk space is available?" | node_filesystem_avail_bytes |
Available disk space in bytes |
| "What's the network traffic like?" | rate(node_network_receive_bytes_total[5m]) |
Network receive rate over 5 minutes |
If you see "OpenAI API not configured":
- Check that
OPENAI_API_KEYis set correctly - Verify the API key is valid
- Ensure the backend has been restarted
If queries fail to translate:
- Check your internet connection
- Verify OpenAI API quota/credits
- Try rephrasing your question
- Check the backend logs for detailed error messages
- The AI translation takes a few seconds depending on your question complexity
- Consider using more specific questions for better results
- The AI uses available metrics from your Prometheus instance for context
- Never commit your API key to version control
- Use environment variables or secure secret management
- Monitor your OpenAI API usage and costs
- Consider rate limiting for production use
- OpenAI charges per API call (typically $0.002 per 1K tokens)
- Each translation uses approximately 100-200 tokens
- Monitor usage at OpenAI Usage Dashboard
For issues with the AI integration:
- Check the backend logs for error messages
- Verify your OpenAI API key and quota
- Ensure all dependencies are installed
- Check that the backend is running and accessible