在CentOS系统中,监控关键进程是确保系统稳定运行的重要步骤。以下是一些常用的方法和工具来监控CentOS的关键进程:
top
命令top
是一个实时显示系统进程信息的动态视图工具。
top
你可以按 P
键按CPU使用率排序,按 M
键按内存使用率排序。
htop
命令htop
是 top
的增强版本,提供了更友好的用户界面和更多的功能。
首先,安装 htop
:
sudo yum install htop
然后运行:
htop
ps
命令ps
命令可以用来查看当前运行的进程。
ps aux
你可以结合 grep
来查找特定的进程:
ps aux | grep <process_name>
systemd
和 journalctl
如果你的系统使用 systemd
,可以使用 journalctl
来查看系统日志,包括进程的启动和停止信息。
journalctl -u <service_name>
nmon
nmon
是一个性能监控工具,可以监控CPU、内存、磁盘和网络的使用情况。
首先,安装 nmon
:
sudo yum install nmon
然后运行:
nmon
glances
glances
是一个跨平台的系统监控工具,可以监控CPU、内存、磁盘、网络、传感器等。
首先,安装 glances
:
sudo yum install glances
然后运行:
glances
Prometheus
和 Grafana
对于更复杂的监控需求,可以使用 Prometheus
来收集指标,并使用 Grafana
来可视化这些指标。
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gz
cd prometheus-2.30.3.linux-amd64
编辑 prometheus.yml
文件,添加监控目标:
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
./prometheus --config.file=prometheus.yml
wget https://dl.grafana.com/oss/release/grafana-8.2.0.linux-amd64.tar.gz
tar xvfz grafana-8.2.0.linux-amd64.tar.gz
cd grafana-8.2.0
./bin/grafana-server
访问 Grafana Web界面(默认地址是 http://localhost:3000
),使用默认用户名和密码(admin/admin)登录。
添加 Prometheus 数据源:
http://localhost:9090
,然后点击“Save & Test”。up
来检查所有服务的状态。通过这些工具和方法,你可以有效地监控CentOS系统中的关键进程,确保系统的稳定运行。