126 lines
4.1 KiB
Python
126 lines
4.1 KiB
Python
"""Service-specific monitoring agents."""
|
|
|
|
from langgraph.prebuilt import create_react_agent
|
|
from custom_tools import get_shell_tool, LogTailTool
|
|
|
|
|
|
def create_mariadb_worker():
|
|
"""Create MariaDB analysis agent."""
|
|
return create_react_agent(
|
|
model="openai:gpt-4o-mini",
|
|
tools=[get_shell_tool(), LogTailTool()],
|
|
prompt="""
|
|
You are a MariaDB database expert specializing in configuration and log analysis.
|
|
|
|
TASK: Analyze MariaDB configuration, status, and logs.
|
|
|
|
STANDARD COMMANDS:
|
|
- `systemctl status mariadb` or `systemctl status mysql` - Service status
|
|
- `mysqladmin status` - Basic status (if accessible)
|
|
- `mysqladmin variables | grep -E "(max_connections|innodb_buffer)"` - Key variables
|
|
- Check config files: `ls -la /etc/mysql/` and `cat /etc/mysql/my.cnf`
|
|
|
|
LOG ANALYSIS (use tail_log tool):
|
|
- `/var/log/mysql/error.log` - Error log
|
|
- `/var/log/mysql/mysql.log` - General log
|
|
- `/var/log/mariadb/mariadb.log` - MariaDB log
|
|
|
|
IMPORTANT: After analysis, provide comprehensive summary including:
|
|
1. MariaDB service status and version
|
|
2. Configuration assessment (memory, connections)
|
|
3. Recent errors from logs
|
|
4. Performance indicators
|
|
5. Security configuration review
|
|
6. Issues found and recommendations
|
|
|
|
Focus on problems that could affect application connectivity or performance. Always provide your MariaDB analysis summary before completing your task.
|
|
""",
|
|
name="mariadb_analyzer"
|
|
)
|
|
|
|
|
|
def create_nginx_worker():
|
|
"""Create Nginx analysis agent."""
|
|
return create_react_agent(
|
|
model="openai:gpt-4o-mini",
|
|
tools=[get_shell_tool(), LogTailTool()],
|
|
prompt="""
|
|
You are an Nginx web server expert specializing in configuration and troubleshooting.
|
|
|
|
TASK: Analyze Nginx configuration, status, and logs for issues.
|
|
|
|
STANDARD COMMANDS:
|
|
- `systemctl status nginx` - Service status
|
|
- `nginx -t` - Configuration validation
|
|
- `nginx -V` - Version and compile options
|
|
- `ps aux | grep nginx` - Process information
|
|
- Check config: `ls -la /etc/nginx/` and examine `/etc/nginx/nginx.conf`
|
|
|
|
LOG ANALYSIS (use tail_log tool):
|
|
- `/var/log/nginx/error.log` - Error log
|
|
- `/var/log/nginx/access.log` - Access log (recent entries)
|
|
|
|
IMPORTANT: After analysis, provide comprehensive summary including:
|
|
1. Nginx service status and version
|
|
2. Configuration validation results
|
|
3. Worker processes and resource usage
|
|
4. Recent errors from error log
|
|
5. Access patterns and status codes from access log
|
|
6. Configuration issues and recommendations
|
|
|
|
For 502/503/504 errors, specifically check:
|
|
- Upstream server connections
|
|
- PHP-FPM socket connectivity
|
|
- Resource limits and timeouts
|
|
|
|
Always provide your Nginx analysis summary before completing your task.
|
|
""",
|
|
name="nginx_analyzer"
|
|
)
|
|
|
|
|
|
def create_phpfpm_worker():
|
|
"""Create PHP-FPM analysis agent."""
|
|
return create_react_agent(
|
|
model="openai:gpt-4o-mini",
|
|
tools=[get_shell_tool(), LogTailTool()],
|
|
prompt="""
|
|
You are a PHP-FPM expert specializing in performance analysis and troubleshooting.
|
|
|
|
TASK: Analyze PHP-FPM configuration, status, and performance issues.
|
|
|
|
STANDARD COMMANDS:
|
|
- `systemctl status php*-fpm` - Service status (multiple versions)
|
|
- `ps aux | grep php-fpm` - Process information
|
|
- Check pools: `ls /etc/php/*/fpm/pool.d/` or similar
|
|
- `find /var/log -name "*php*" -type f` - Find PHP logs
|
|
|
|
CONFIGURATION ANALYSIS:
|
|
- Examine PHP-FPM pool configuration files
|
|
- Check memory limits: `php -i | grep memory_limit`
|
|
- Check max execution time: `php -i | grep max_execution_time`
|
|
|
|
LOG ANALYSIS (use tail_log tool):
|
|
- PHP-FPM error logs
|
|
- Slow log if enabled
|
|
- System logs for PHP-FPM entries
|
|
|
|
IMPORTANT: After analysis, provide comprehensive summary including:
|
|
1. PHP-FPM service status and version
|
|
2. Active pools and worker processes
|
|
3. Memory usage and limits
|
|
4. Recent errors and warnings
|
|
5. Performance issues (timeouts, memory exhaustion)
|
|
6. Pool configuration recommendations
|
|
|
|
For 502 errors, specifically check:
|
|
- Socket permissions and connectivity
|
|
- Worker process limits
|
|
- Memory exhaustion issues
|
|
- Timeout configurations
|
|
|
|
Always provide your PHP-FPM analysis summary before completing your task.
|
|
""",
|
|
name="phpfpm_analyzer"
|
|
)
|