Linux system resource monitoring tools glances use detailed

Source: Internet
Author: User
Tags memory usage time interval cpu usage python script

Glances is a Linux, BSD open Source command-line system monitoring tool, which uses the Python language development, uses the Psutil library to collect the system data, can monitor the CPU, the load, the memory, the disk I/O, the network traffic, the file system, the system temperature and so on information. Compared to top/vmstat/iostat and other old monitoring tools, glances has the advantage of: Glances can monitor the local computer can also monitor other machines through the client server mode; glances provides a xml/rpc based API for other program calls, programmable Glances can save data output to a CSV or HTML-formatted file to facilitate other programs to process (report or draw graphics).
First, the installation of Glances

There are usually two ways to install glances. The first is by compiling the source code, which is more complex and may encounter a package dependency problem. There is also a simple way to install glances using specific package management tools such as Easy_install or Pip,centos called Pip-python.

How to install under Ubuntu

The code is as follows Copy Code

# sudo apt-get update
# sudo apt-get install python-pip build-essential Python-dev
# sudo pip install glances

Installation under CentOS

The code is as follows Copy Code

# RPM-IVH http://fr2.rpmfind.net/linux/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum Install Python-pip Python-devel
# Pip-python Install glances

Ii. parameters and usage of glances

Parameters of Glances

Glances is a command line tool that includes the following command options:
-B: Show network connection speed byte/seconds
-B @IP |host: Binding server-side IP address or host name
-C @IP |host: Connecting glances server Side
-C File: Setting the profile defaults to/etc/glances/glances.conf
-D: Turning off disk I/O modules
-E: Display sensor temperature
-F File: Set output file (format is HTML or CSV)
-M: Turn off Mounted disk module
-N: Shutting down the network module
-P Port: Set run port default is 61209
-p Password: Set client/server password
-S: Set glances run mode to server
-T sec: Set screen refresh time interval, in seconds, default value is 2 seconds, numeric license range: 1~32767
-H: Display Help information
-V: Display version information

Note: If you want to output temperature, you need lm_sensors support, the installation method is:

The code is as follows Copy Code

# yum Install Lm_sensors
# Pip-python Install Pysensors

Glances

The results of the operation as shown in the above, because I do not have the Lm_sensors module installed here, so I do not display temperature information, want to see the temperature screenshot can be seen in the official usage and output are similar to the top command, the interface of the operation method is similar to top, which shows the meaning of the field

Virt: Virtual Memory size
RES: The physical memory values consumed by the process
%CPU: CPU usage for this process
%mem: Percentage of physical memory and total memory consumed by this process
PID: Process ID number
User: Username for process Owner
time+: Total CPU time consumed by the process after it was started
Io_r and Io_w: Process read/write I/O rates
Name: Process names
NI: Process Priority
S: The state of the process, where s represents hibernation, R indicates that it is running, and Z denotes zombie state.

The shortcut keys that can be used under the interactive interface are as follows:

H: Display Help information
Q: Leave the program exit
C: Sort the system process according to the CPU Real time load
M: Sort system processes according to memory usage
I: Sort system processes according to I/O usage
P: Sort by process name
D: Show disk read and write status
W: Delete log files
L: Show Log
S: Display sensor information
F: Display System Information
1: Show each CPU kernel usage in turn (secondary option is only used in multi-core CPU system)

Iii. advanced usage of glances

1, output HTML format, configure Web server display

The code is as follows Copy Code

# Pip-python Install JINJA2
# Glances-o Html-f/var/www/html

Note: When exporting HTML format, you need JINJA2 support, and you need to install dependencies first. The file name for the default output is glances.html and can be accessed through http://IP/glances.html.

2, output to CSV format, and use Excel or LibreOffice view

The code is as follows Copy Code

#glances-O csv-f/home/cjh/glances.csv
#libreoffice--calc%u/tmp/glances.csv

3, C/S mode and API programming

The service side starts at the following command

The code is as follows Copy Code

# glances-s-B 192.168.10.16
Glances server is running on 192.168.10.16:61209

Note: If you use a firewall, you need to release it on the iptables.

Client view

The code is as follows Copy Code

# glances–c 192.168.10.16

If the client may have a serial display problem under the terminal. In addition, we can also use the XML-RPC API provided by glances to program, example:

$

The code is as follows Copy Code
Vim test.py
#!/usr/bin/python
Import Xmlrpclib
s = xmlrpclib. Serverproxy (' http://192.168.10.16:61209 ')
Print S.getsystem () www.111cn.net

The result of executing the Python script above is:

The code is as follows Copy Code

[root@test174 tmp]# python test.py
{"Linux_distro": "CentOS 6.4", "Platform": "64bit", "Os_name": "Linux", "hostname": "Localhost.localdomain", "Os_ Version ":" 2.6.32-358.el6.x86_64 "}

For more on the API how-to, see the wiki page for the project on GitHub.
Four, color warning and setting

Green indicates good performance without any extra effort (CPU usage, disk space usage and memory usage below 50%, system load below 0.7).

Blue indicates some minor problems with system performance, and users should begin to focus on system performance (CPU usage, disk space usage and memory usage between 50%-70% and system load between 0.7-1).

Red is the performance alarm, should take measures such as backup data (CPU utilization, disk space usage and memory utilization between 70%-90%, the system load between 1-5).

Dark red indicates a serious performance problem and may be down (at this point, CPU usage, disk space usage, and memory usage are greater than 90% and system load is greater than 5).

The specific alarm threshold can be modified by modifying the file/etc/glances/glances.conf.
V. Bulk Deployment

The official page of the program provides us with a way to use puppet to deploy glances in bulk, depending on the Puppet-glances project. In addition to puppet, the more popular batch management tool salt can also implement the bulk deployment of the tool as follows:

1, the preparation of SIS deployment files

The code is as follows Copy Code

# Vim/srv/salt/glances.sls
PYTHON-PIP:
Pkg.installed
Build-essential:
Pkg.installed
Python-dev:
Pkg.installed
Glances:
Pip.installed:
-Require:
-Pkg:python-pip

2. Enforcement status

  code is as follows copy code

# salt ' * ' State.sls Glances
...
minion1.vpsee.com:
----------
State:-pip
name:glances
function:installed
result:true
com Ment:package was successfully installed
changes:glances==1.7.1:installed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.