“
atop是Linux下的一款系统资源与进程监控工具。其能够记录全部进程的活动,并将采集到的指标数据写入文件存档分析,包括常见的磁盘,内存,CPU,网络,进程运行情况等。如果是说容器环境还能记录容器ID等,能够帮助你快速知道进程所属容器。
”
软件安装
软件的安装就比较简单了,相信干这行的同仁装个软件那必定是手到擒来,完全没难度。如果没安装失败,自行解决咯。
sudo yum install atop
如需监测网络使用率,可安装网络监控模块netatop。
sudo yum install kernel-devel-$(uname -r)
sudo yum install elfutils-libelf-devel
atop服务配置及启动
- 监控周期及日志保留时间配置
vim /etc/sysconfig/atop
LOGINTERVAL:监控周期,建议将默认的监控周期600s修改为30s。 LOGGENERATIONS:日志保留时间,为避免atop长时间运行占用太多磁盘空间,建议将默认的日志保留时间28天修改为7天。
LOGOPTS=""
LOGINTERVAL=30
LOGGENERATIONS=7
LOGPATH=/var/log/atop
- 启动服务
systemctl restart atop
systemctl enable atop
使用ansible安装部署atop
- roles/atop/files目录下准备如下文件
atop #atop配置文件
atop-2.7.1-1.el7.x86_64.rpm #rpm安装包
atop.service #服务启动文件
atop.service
[Unit]
Description=Atop advanced performance monitor
Documentation=man:atop(1)
[Service]
Type=simple
Environment="LOGOPTS="
Environment="LOGINTERVAL=600"
Environment="LOGGENERATIONS=28"
Environment="LOGPATH=/var/log/atop"
EnvironmentFile=/etc/sysconfig/atop
ExecStartPre=/bin/sh -c 'test -n "$LOGINTERVAL" -a "$LOGINTERVAL" -eq "$LOGINTERVAL"'
ExecStartPre=/bin/sh -c 'test -n "$LOGGENERATIONS" -a "$LOGGENERATIONS" -eq "$LOGGENERATIONS"'
ExecStart=/bin/sh -c 'exec /usr/bin/atop ${LOGOPTS} -w "${LOGPATH}/atop_$(date +%%Y%%m%%d)" ${LOGINTERVAL}'
ExecStartPost=/usr/bin/find "${LOGPATH}" -name "atop_*" -mtime +${LOGGENERATIONS} -exec rm -v {} \;
KillSignal=SIGUSR2
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
- roles/atop/tasks/main.yml 文件如下
---
- name: create workdir /app/software/atop
file:
path: /app/software/atop
state: directory
- name: copy atop.rpm to remote hosts
copy:
src: files/atop-2.7.1-1.el7.x86_64.rpm
dest: /usr/local/src/
- name: install atop.rpm
shell: yum -y localinstall /usr/local/src/atop-2.7.1-1.el7.x86_64.rpm --disablerepo='*'
- name: copy config file atop to /etc/sysconfig/atop
copy:
src: files/atop
dest: /etc/sysconfig/atop
force: yes
backup: yes
tags:
- atop_config
- name: copy atop.service atop to /usr/lib/systemd/system/atop.service
copy:
src: files/atop.service
dest: /usr/lib/systemd/system/atop.service
force: yes
backup: no
tags:
- atop_config
- name: Daemon Reload for atop service
systemd:
daemon_reload: yes
tags:
- atop_config
- name: Enable atop.service
systemd:
name: "{{ item }}"
state: restarted
enabled: yes
with_items:
- atop
tags:
- atop_config
- name: Enable atop-rotate.service
cron: name="Atop Service Rotate" hour="0" minute="0" job="/usr/bin/systemctl try-restart atop.service"
tags:
- atop_confi
- install-atop-playbooks.yml
---
- hosts: "{{ ansible_play_hosts_all }}"
gather_facts: no
roles:
- atop
- 安装部署
# 提前将需要安装部署的主机写入ansible的hosts文件
ansible-playbooks install-atop-playbooks.yml
注意:默认大哥们对ansible有一定的使用基础,这里就不说那么多废话咯,有问题可联系我。