virsh监控kvm虚拟机相关命令(二)
Virsh监控kvm虚拟机相关命令:
1、virsh domblklist:列出指定虚拟机磁盘信息
[root@node1 ~]# virsh help domblklist //列出指定虚拟机磁盘信息
NAME
domblklist - 列出所有域块
SYNOPSIS
domblklist <domain> [--inactive] [--details]
DESCRIPTION
获取域块设备小结
OPTIONS
[--domain] <string> domain name, id or uuid
--inactive 获取不活跃而不是运行的配置
--details type 和 device 值的附加显示
[root@node1 ~]#virsh domblklist centos7
Target Source
------------------------------------------------
vda /opt/images/centos7.qcow2
hda -
2、virsh domiflist:列出指定虚拟机上的所有网卡;
[root@node1 ~]# virsh help domiflist //列出指定虚拟机上的所有网卡
NAME
domiflist - 列出所有域虚拟接口
SYNOPSIS
domiflist <domain> [--inactive]
DESCRIPTION
获取域虚拟接口小结
OPTIONS
[--domain] <string> domain name, id or uuid
--inactive 获取不活跃而不是运行的配置
[root@node1 ~]# virsh domiflist centos7 //查看虚拟机的所有网卡
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 network default virtio 52:54:00:e9:18:34
vnet1 bridge br0 virtio 52:54:00:e9:18:34
提示:从上面的信息可以看到kvm虚拟机上的网卡都对应在宿主机上的一个虚拟网卡;
3、virsh domifaddr:获取指定虚拟机上的ip地址
[root@node1 ~]# virsh help domifaddr
NAME
domifaddr - Get network interfaces' addresses for a running domain
SYNOPSIS
domifaddr <domain> [--interface <string>] [--full] [--source <string>]
DESCRIPTION
Get network interfaces' addresses for a running domain
OPTIONS
[--domain] <string> domain name, id or uuid
--interface <string> network interface name
--full always display names and MACs of interfaces
--source <string> address source: 'lease', 'agent', or 'arp'
[root@node1 ~]# virsh domifaddr centos7 //查看虚拟机网卡ip
Name MAC address Protocol Address
-------------------------------------------------------------------------------
vnet0 52:54:00:e9:18:34 ipv4 192.168.122.187/24
4、virsh domifstat:统计指定虚拟机上的指定网卡状态
[root@node1 ~]# virsh help domifstat
NAME
domifstat - 获得域网络接口状态
SYNOPSIS
domifstat <domain> <interface>
DESCRIPTION
获得运行域的网络接口状态。
OPTIONS
[--domain] <string> domain name, id or uuid
[--interface] <string> interface device specified by name or MAC Address
[root@node1 ~]# virsh domiflist centos7 //查看指定虚拟机网卡
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 network default virtio 52:54:00:e9:18:34
vnet1 bridge br0 virtio 52:54:00:e9:18:34
[root@node1 ~]# virsh domifstat centos7 vnet1 //查看指定虚拟机指定网卡状态
vnet1 rx_bytes 749668
vnet1 rx_packets 6434
vnet1 rx_errs 0
vnet1 rx_drop 0
vnet1 tx_bytes 32820
vnet1 tx_packets 174
vnet1 tx_errs 0
vnet1 tx_drop 0
5、virsh dominfo:获取指定虚拟机的简要信息
[root@node1 ~]# virsh help dominfo
NAME
dominfo - 域信息
SYNOPSIS
dominfo <domain>
DESCRIPTION
返回这个域的基本信息。
OPTIONS
[--domain] <string> domain name, id or uuid
[root@node1 ~]# virsh dominfo centos7
Id: 1
Name: centos7 //名称
UUID: af3bb7e8-1009-4afb-9529-508303e62bbd
OS Type: hvm //OS类型
State: running
CPU(s): 1
CPU time: 304.0s
Max memory: 2097152 KiB
Used memory: 2097152 KiB
Persistent: yes //持久
Autostart: enable
Managed save: no
Security model: none
Security DOI: 0
6、virsh dommemstat:获取指定虚拟机内存相关状态信息
[root@node1 ~]# virsh help dommemstat
NAME
dommemstat - 获取域的内存统计
SYNOPSIS
dommemstat <domain> [--period <number>] [--config] [--live] [--current]
DESCRIPTION
获取运行域的内存统计
OPTIONS
[--domain] <string> domain name, id or uuid
--period <number> 以秒为单位设定集合期限
--config 影响下一次引导
--live 影响运行的域
--current 影响当前域
[root@node1 ~]# virsh dommemstat centos7
actual 2097152
swap_in 0
last_update 1600397773
rss 644792
7、virsh domstate:获取指定虚拟机的状态信息
[root@node1 ~]# virsh help domstate
NAME
domstate - 域状态
SYNOPSIS
domstate <domain> [--reason]
DESCRIPTION
返回某个域的状态。
OPTIONS
[--domain] <string> domain name, id or uuid
--reason 同时输出状态原因
[root@node1 ~]# virsh domstate centos7
running
[root@node1 ~]# virsh domstate centos7 --reason //查看具体状态原因(已引导)
running (booted)
8、virsh domstats:显示指定虚拟机的详细状态,如果不指定虚拟机名称表示显示当前宿主机上所有虚拟机的详细状态信息
[root@node1 ~]# virsh help domstats
NAME
domstats - get statistics about one or multiple domains
SYNOPSIS
domstats [--state] [--cpu-total] [--balloon] [--vcpu] [--interface] [--block] [--perf] [--list-active] [--list-inactive] [--list-persistent] [--list-transient] [--list-running] [--list-paused] [--list-shutoff] [--list-other] [--raw] [--enforce] [--backing] [--nowait] [<domain>]..
DESCRIPTION
Gets statistics about one or more (or all) domains
OPTIONS
--state report domain state
--cpu-total report domain physical cpu usage
--balloon report domain balloon statistics
--vcpu report domain virtual cpu information
--interface report domain network interface information
--block report domain block device statistics
--perf report domain perf event statistics
--list-active list only active domains
--list-inactive list only inactive domains
--list-persistent list only persistent domains
--list-transient list only transient domains
--list-running list only running domains
--list-paused list only paused domains
--list-shutoff list only shutoff domains
--list-other list only domains in other states
--raw do not pretty-print the fields
--enforce enforce requested stats parameters
--backing add backing chain information to block stats
--nowait report only stats that are accessible instantly
<domain> list of domains to get stats for
[root@node1 ~]#virsh domstats //查看本宿主机上所有虚机的详细信息
[root@node1 ~]#virsh domstats centos7 //查看centos7的详细信息
[root@node1 ~]# virsh domstats centos7.0 --interface --balloon
//如果想知获取某一对象的详细信息可以在后面跟对应的选项来做过滤
9、virsh domblkinfo:获取指定虚拟机的磁盘大小信息
[root@node1 ~]# virsh help domblkinfo
NAME
domblkinfo - 域块设备大小信息
SYNOPSIS
domblkinfo <domain> [--device <string>] [--human] [--all]
DESCRIPTION
获取域块设备大小信息
OPTIONS
[--domain] <string> domain name, id or uuid
--device <string> 阻止设备
--human Human readable output
--all display all block devices info
[root@node1 ~]#virsh domblklist centos7 //列出指定虚机磁盘信息
[root@node1 ~]#virsh domblkinfo centos7 vda //指定虚机指定磁盘的大小
Capacity: 21474836480
Allocation: 2400718848
Physical: 2400780288
[root@node1 ~]#virsh domblkinfo centos7 vda --human //人性化显示
Capacity: 20.000 GiB
Allocation: 2.236 GiB
Physical: 2.236 GiB