门户型网站建设,建设银行对公网站打不开,电脑版浏览器入口,中国会议营销网站一、简介
随着信息技术的不断发展#xff0c;作为基础平台,封闭架构带来不兼容性,无法支持异构虚拟机系统,也难以支撑开放合作的产业链需求。随着云计算时代的来临,虚拟化管理平台向开放平台架构转变,多种厂家的虚拟机可以在开放的平台架构下共存,不同的应用厂商可以基于开放…一、简介
随着信息技术的不断发展作为基础平台,封闭架构带来不兼容性,无法支持异构虚拟机系统,也难以支撑开放合作的产业链需求。随着云计算时代的来临,虚拟化管理平台向开放平台架构转变,多种厂家的虚拟机可以在开放的平台架构下共存,不同的应用厂商可以基于开放平台架构使其应用不断的丰富。它不仅可以提供更加高效的计算速度和存储空间还可以大大降低成本提高企业的竞争力。监控也随之兼容满足云平台的日常监控运维工作的手段。那么对于Openstack运维人员来说需要掌握Openstack云平台系统资源的整体运行情况包括域(AZ)的cpu/menmory等资源使用情况将介绍使用zabbix结合openstack python-api对openstack系统资源进行监控。
二、数据获取
1、使用控制台获取域(AZ)监控信息使用如下命令可以获取当前openstack的所有可用域。
nova availability-zone-list
---------------------------------------------------------------
| Name | Status |
---------------------------------------------------------------
| internal | available |
| |- computer03 | |
| | |- nova-storage | enabled :-) 2018-10-18T10:56:07.000000 |
| |- computer04 | |
| | |- nova-storage | enabled :-) 2018-10-18T10:56:08.000000 |
| |- computer05 | |
| | |- nova-storage | enabled :-) 2018-10-18T10:56:13.000000 |
| |- computer06 | |
| | |- nova-storage | enabled :-) 2018-10-18T10:56:05.000000 |
| |- computer07 | |
| | |- nova-storage | enabled :-) 2018-10-18T10:56:05.000000 |
| |- computer08 | |
| | |- nova-storage | enabled :-) 2018-10-18T10:56:07.000000 |
| |- controler02 | |
| | |- nova-conductor | enabled XXX 2017-10-09T09:46:27.000000 |
| | |- nova-consoleauth | enabled XXX 2017-10-09T09:46:37.000000 |
| | |- nova-monitor | enabled :-) 2018-10-18T10:56:11.000000 |
| | |- nova-scheduler | enabled XXX 2017-10-09T09:46:37.000000 |
| | |- nova-cert | enabled XXX 2017-10-09T09:46:37.000000 |
| |- controller01 | |
| | |- nova-conductor | enabled :-) 2018-10-18T10:56:11.000000 |
| | |- nova-consoleauth | enabled :-) 2018-10-18T10:56:04.000000 |
| | |- nova-monitor | enabled :-) 2018-10-18T10:56:07.000000 |
| | |- nova-scheduler | enabled :-) 2018-10-18T10:56:09.000000 |
| | |- nova-cert | enabled :-) 2018-10-18T10:56:12.000000 |
| IMS | available |
| |- computer03 | |
| | |- nova-compute | enabled :-) 2018-10-18T10:56:07.000000 |
| |- computer04 | |
| | |- nova-compute | enabled :-) 2018-10-18T10:56:05.000000 |
| |- computer08 | |
| | |- nova-compute | enabled :-) 2018-10-18T10:56:13.000000 |
| paas | available |
| |- computer05 | |
| | |- nova-compute | enabled :-) 2018-10-18T10:56:07.000000 |
| |- computer06 | |
| | |- nova-compute | enabled :-) 2018-10-18T10:56:13.000000 |
| |- computer07 | |
| | |- nova-compute | enabled :-) 2018-10-18T10:56:04.000000 |
---------------------------------------------------------------
由结果可以看出该系统含有两个域 IMS 和 paas ,但是该命令结果不太直观不容易提取我们也可以使用如下命令
nova aggregate-list
--------------------------------
| Id | Name | Availability Zone |
--------------------------------
| 1 | IMSRCS | IMS |
| 4 | paas | paas |
-------------------------------- 根据 aggregate-list 我们可以查看域对应的计算节点
nova aggregate-details paas
-------------------------------------------------------------------------------------------------
| Id | Name | Availability Zone | Hosts | Metadata |
-------------------------------------------------------------------------------------------------
| 4 | paas | paas | computer07, computer05, computer06 | availability_zonepaas |
-------------------------------------------------------------------------------------------------
由结果可知paas域一共包含三个computer节点对于每个节点的使用情况我们一样可以通过命令获取
nova hypervisor-show computer07
---------------------------------------
| Property | Value |
---------------------------------------
| free_disk_gb | 55 |
| free_ram_mb | 126156 |
| host_ip | 193.2.0.37 |
| hypervisor_hostname | computer07 |
| hypervisor_type | QEMU |
| id | 9 |
| local_gb | 445 |
| local_gb_used | 390 |
| memory_mb | 257740 |
| memory_mb_used | 131584 |
| npt_ept | ept |
| pci_pools | - |
| running_vms | 8 |
| service_disabled_reason | - |
| service_host | computer07 |
| service_id | 27 |
| state | up |
| status | enabled |
| vcpus | 48 |
| vcpus_used | 32 |
---------------------------------------
#部分信息
我们可以得知该节点的vcpu总数及其使用情况,memory_mb总数及其使用情况。
将每个节点的使用情况均获取后经过计算就可以得出域的资源整体使用情况。对于云平台的整体使用情况我们也可以通过命令行获取
nova hypervisor-stats
-------------------------------
| Property | Value |
-------------------------------
| count | 6 |
| current_workload | 0 |
| disk_available_least | 304 |
| free_disk_gb | 518 |
| free_ram_mb | 961736 |
| local_gb | 2670 |
| local_gb_used | 2152 |
| memory_mb | 1546440 |
| memory_mb_used | 584704 |
| running_vms | 42 |
| vcpus | 288 |
| vcpus_used | 172 |
-------------------------------
上面我们讨论了使用命令行进行相关信息的获取下面我们讨论使用python-api进行相关信息的获取与计算。
2、使用 openstack python-api 获取域监控信息
代码如下
#!/usr/bin/python
# -*- coding: utf-8 -*-
#imports
import json
from optparse import OptionParser
from novaclient import client as noclient
from novaclient import utils
#登录及授权
keystone {}
keystone[os_username]admin
keystone[os_password]keystone
keystone[os_auth_url]http://lb-vip:5000/v2.0/
keystone[os_tenant_name]admin
nova_client noclient.Client(2, keystone[os_username], keystone[os_password], keystone[os_tenant_name], keystone[os_auth_url])
def main():#获取云平台整体信息并打印total_info nova_client.hypervisor_stats.statistics()._info.copy()print total_info_vcpus:, total_info[vcpus]print total_info_vcpus_used:, total_info[vcpus_used]print total_info_memory_mb:, total_info[memory_mb]print total_info_memory_mb_used:, total_info[memory_mb_used]print total_info_running_vms:, total_info[running_vms]#获取域列表信息aggregates nova_client.aggregates.list()for aggregate in aggregates:#初始化每个域的资源统计变量vcpus 0vcpus_used 0memory_mb 0memory_mb_used 0running_vms 0#获取每个aggregate信息并保存对应的hostscomputer节点列表aggregate_info aggregate._info.copy()print aggregate_info[id], aggregate_info[name], aggregate_info[availability_zone], aggregate_info[hosts]aggregate_hosts aggregate_info[hosts]#循环计算节点保存相关资源信息for aggregate_host in aggregate_hosts:hypervisor_info utils.find_resource(nova_client.hypervisors, aggregate_host)._infovcpus vcpus hypervisor_info[vcpus]vcpus_used vcpus_used hypervisor_info[vcpus_used]memory_mb memory_mb hypervisor_info[memory_mb]memory_mb_used memory_mb_used hypervisor_info[memory_mb_used]running_vms running_vms hypervisor_info[running_vms]#打印域资源信息print vcpus:, vcpusprint vcpus_used:, vcpus_usedprint memory_mb:, memory_mbprint memory_mb_used:, memory_mb_usedprint running_vms:, running_vms
if __name__ __main__:main()
执行该程序后可以获取各个域节点的信息
total_info_vcpus: 288
total_info_vcpus_used: 172
total_info_memory_mb: 1546440
total_info_memory_mb_used: 584704
total_info_running_vms: 42
1 IMSRCS IMS [ucomputer04, ucomputer03, ucomputer08]
vcpus: 144
vcpus_used: 84
memory_mb: 773220
memory_mb_used: 243200
running_vms: 20
4 paas paas [ucomputer07, ucomputer05, ucomputer06]
vcpus: 144
vcpus_used: 88
memory_mb: 773220
memory_mb_used: 341504
running_vms: 22
经过适当的计算我们就可以获取各个域分配及使用比例等信息。
上面我们就使用 python-api 打印出了所有需要的信息但是对于监控来说我们需要提取的是各个监控项的信息这样才能方便的搜索和做图表展示下面我们讨论结合zabbix进行相关信息的监控。
三、Zabbix获取监控信息
1、获取可用域信息列表
上面我们已经获取了所有的可用域信息但对于zabbix来说我们还需要返回固定格式的数据供zabbix进行解析
#!/usr/bin/python
# -*- coding: utf-8 -*-
#imports
import json
from optparse import OptionParser
from novaclient import client as noclient
from novaclient import utils
#登录及授权
keystone {}
keystone[os_username]admin
keystone[os_password]keystone
keystone[os_auth_url]http://lb-vip:5000/v2.0/
keystone[os_tenant_name]admin
nova_client noclient.Client(2, keystone[os_username], keystone[os_password], keystone[os_tenant_name], keystone[os_auth_url])
def main():r {data:[]}aggregates nova_client.aggregates.list()for aggregate in aggregates:aggregate_info aggregate._info.copy()r[data].append( {{#NAME}:aggregate_info[name]} )print(json.dumps(r, indent2, sort_keysTrue, encodingutf-8))
if __name__ __main__:main()
执行后返回的结果如下,可以通过供zabbix自动发现模版使用
{data: [{{#AVAILABLE_ZONE}: IMS,{#NAME}: IMSRCS},{{#AVAILABLE_ZONE}: paas,{#NAME}: paas}]
}
2、Item及LLD自动发配置 云平台整体信息Item设置如下
openstack.total[vcpus]
openstack.total[vcpus_used]
openstack.total[memory_mb]
openstack.total[memory_mb_used]
openstack.total[running_vms]
获取{#NAME}后就可以根据监控项获取对应的监控内容了zabbix自动发现自动发现key设置如下
openstack.system.discovery
discovery下设置监控Item,key设置如下
openstack.zone[hosts,{#NAME}]
openstack.zone[vcpus,{#NAME}]
openstack.zone[vcpus_used,{#NAME}]
openstack.zone[memory_mb,{#NAME}]
openstack.zone[memory_mb_used,{#NAME}]
openstack.zone[running_vms,{#NAME}]
其中{#NAME}为第一步的脚本中返回的可用域对应的aggregate相关信息。
3、Agent自定义配置
对应的zabbix-agent.conf配置如下
# /etc/zabbix/zabbix_agentd.d/userparameter_openstack-system.conf
UserParameteropenstack.system.discovery,python /etc/zabbix/zabbix_agentd.d/openstack-system.py --item discovery
UserParameteropenstack.total[*],python /etc/zabbix/zabbix_agentd.d/openstack-system.py --item total --moniter $1
UserParameteropenstack.zone[*],python /etc/zabbix/zabbix_agentd.d/openstack-system.py --item $1 --aggregate $2
对应的zabbix自动发现的监控脚本如下
# /etc/zabbix/zabbix_agentd.d/openstack-system.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
#imports
import json
from optparse import OptionParser
from novaclient import client as noclient
from novaclient import utils
#登录及授权
keystone {}
keystone[os_username]admin
keystone[os_password]keystone
keystone[os_auth_url]http://lb-vip:5000/v2.0/
keystone[os_tenant_name]admin
nova_client noclient.Client(2, keystone[os_username], keystone[os_password], keystone[os_tenant_name], keystone[os_auth_url])
def main():options parse_args()if options.itemdiscovery:zone_list()elif options.itemtotal:total_moniter(options)else:zone_moniter(options)
#判断入参合法性
def parse_args():parser OptionParser()valid_item [discovery, total, hosts, vcpus, vcpus_used, memory_mb, memory_mb_used, running_vms]parser.add_option(, --item, destitem, help, actionstore, typestring, defaultNone)parser.add_option(, --moniter, destmoniter, help, actionstore, typestring, defaultNone)parser.add_option(, --aggregate, destaggregate, help, actionstore, typestring, defaultNone)(options, args) parser.parse_args()if options.item not in valid_item:parser.error(Item has to be one of: , .join(valid_item))return options
#获取可用域列表
def zone_list():r {data:[]}aggregates nova_client.aggregates.list()for aggregate in aggregates:aggregate_info aggregate._info.copy()r[data].append( {{#NAME}:aggregate_info[name], {#AVAILABLE_ZONE}:aggregate_info[availability_zone]} )print(json.dumps(r, indent2, sort_keysTrue, encodingutf-8))
#获取云平台整体监控信息
def total_moniter(options):total_info nova_client.hypervisor_stats.statistics()._info.copy()print (total_info[options.moniter])
#获取可用域对应的监控信息
def zone_moniter(options):aggregate utils.find_resource(nova_client.aggregates, options.aggregate)aggregate_info aggregate._info.copy()aggregate_hosts aggregate_info[hosts]if options.itemhosts:print (aggregate_hosts)else:monitor_data 0for aggregate_host in aggregate_hosts:hypervisor_info utils.find_resource(nova_client.hypervisors, aggregate_host)._infomonitor_data monitor_data hypervisor_info[options.item]print (monitor_data)
if __name__ __main__:main()
在zabbix上进行对应的配置后重启将模版应用于主机此时应当监控获取所有的可用域并监控对应的信息。
4、参考资料
Openstack 中zone ,aggregates和host及其应用https://blog.csdn.net/ztejiagn/article/details/8948688nova 命令汇总四 ——计算相关命令http://blog.51cto.com/13788458/2129157The novaclient Python APIhttps://docs.openstack.org/python-novaclient/latest/reference/api/index.htmlGitHub - larsks/openstack-api-sampleshttps://github.com/larsks/openstack-api-samples 探索技术无限可能博主具有丰富监控模板资源及开发能力和项目管理经验欢迎添加交流一起探讨解决你的技术难题
微信号:king_songax