监控 Linux + Nginx + MySQL + PHP(LNMP) 的性能,一般分为 系统层、Web层、数据库层、PHP层 四个维度。下面给你一套实用、可落地的监控方案。
top / htop
free -h
df -h
iostat -x 1
vmstat 1
sar -u 1 # 需要 sysstat
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
访问:http://IP:19999
server {
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
查看:
curl http://127.0.0.1/nginx_status
指标说明:
awk '{print $7}' access.log | sort | uniq -c | sort -nr | head
SHOW PROCESSLIST;
SHOW STATUS LIKE 'Threads%';
SHOW GLOBAL STATUS;
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
分析:
mysqldumpslow -s t /var/log/mysql/slow.log
pm.status_path = /status
Nginx 配置:
location /php_status {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
查看:
curl http://127.0.0.1/php_status
关注:
slowlog = /var/log/php-fpm/slow.log
request_slowlog_timeout = 2s
Netdata / Zabbix
Prometheus + Node Exporter
+ Nginx Exporter
+ MySQL Exporter
+ PHP-FPM Exporter
+ Grafana
PMM (Percona)
top)free)iostat)如果你愿意,我可以:
你现在是学习 / 线上排查 / 搭建监控平台?