VMware¶
VMware는 클러스터 상태, 호스트 상태, VM 상태 등의 지표를 보여줍니다
구성¶
준비 사항¶
- VMware에 접근할 수 있는 내부망 머신 1대에
Datakit과 Python 3+ 환경이 설치되어 있어야 합니다 - 다음 의존성 라이브러리가 필요합니다:
- requests
- pyvmomi == 7.0
- openssl == 1.1.1w
주의: 서로 다른 패키지 버전을 사용하면 패키지 충돌 문제가 발생할 수 있습니다
배포 절차¶
-
Datakit의python.d수집기를 활성화하고, DataKit 설치 디렉터리의 conf.d/pythond 디렉터리로 들어가서 pythond.conf.sample을 복사한 뒤 pythond.conf로 이름을 변경합니다. 예시는 다음과 같습니다:# {"version": "1.16.0", "desc": "do NOT edit this line"} [[inputs.pythond]] # Python input name name = 'some-python-inputs' # required # Python 실행용 시스템 환경 변수 #envs = ['LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH',] # Python path(recomment abstract Python path) cmd = "/root/anaconda3/envs/py3.9/bin/python" # required. python3 is recommended. # Python scripts relative path dirs = ["vm"]주의: 여기서 cmd는 Python 스크립트를 실행할 자신의 Python 환경 경로로 변경해야 하며,
dirs는 스크립트가 저장된 디렉터리입니다 -
datakit/python.d디렉터리 아래에 "Python 패키지명"으로 된 디렉터리를 만들고, 그 디렉터리 아래에 Python 스크립트(.py)를 생성합니다. 패키지명vm을 예로 들면 경로 구조는 다음과 같습니다. 여기서demo.py는 Python 스크립트이며, Python 스크립트 파일명은 임의로 지정할 수 있습니다: -
vm.py스크립트를 작성하고, 아래 예제 스크립트를 넣은 뒤vcenter_host,vcenter_port,vcenter_user,vcenter_password에 VMware를 수집할 호스트, 포트 및 사용자 정보를 입력합니다.Python 스크립트 예제
from datakit_framework import DataKitFramework from pyVim.connect import SmartConnect, Disconnect import requests from pyVmomi import vim import ssl import datetime import time class vm(DataKitFramework): name = "vm" interval = 10 def run(self): print("vm") s = ssl.SSLContext(ssl.PROTOCOL_TLSv1) s.verify_mode = ssl.CERT_NONE datakit_url_object = 'http://0.0.0.0:9529/v1/write/custom_object' datakit_url_metric = 'http://0.0.0.0:9529/v1/write/metric' vcenter_host = "10.200.14.20" vcenter_port = 443 vcenter_user = "reader@zy.ops" vcenter_password = "Zhuyun@0906" # 데이터는 JSON 방식으로 Datakit에 보고되므로 POST 요청에 헤더를 추가해야 합니다 header = { "Content-Type": "application/json" } # 데이터 보고 dk_object = [] dk_metric = [] # vCenter Server에 연결 c = SmartConnect(host=vcenter_host, user=vcenter_user, pwd=vcenter_password, port=vcenter_port, sslContext=s) content = c.RetrieveContent() container = content.rootFolder # 탐색 시작 지점 viewType = [vim.HostSystem, vim.VirtualMachine] # 찾을 객체 유형 recursive = True # 재귀적으로 탐색할지 여부 # vCenter 수 및 상세 정보 가져오기 vcenter_data = content.rootFolder.childEntity print("vCenter 수: ", len(vcenter_data)) for i in vcenter_data: dk_metric.append({ "measurement": "vmware", "tags": { "vcenter_name": str(i) }, "fields": { "vcenter_total": int(len(vcenter_data)) }, "time": int(time.time()) }) # datastore 수 및 상세 정보 가져오기 datastores = content.rootFolder.childEntity[0].datastore for ds in datastores: dk_metric.append({ "measurement": "vmware", "tags": { "vcenter_datastore_name": str(ds.name) }, "fields": { "vcenter_datastore_total_capacity": int(ds.summary.capacity), "vcenter_datastore_total_free_space": int(ds.summary.freeSpace), "vcenter_datastore_utilization_rate": int((ds.summary.capacity - ds.summary.freeSpace) / ds.summary.capacity), "vcenter_datastore_total": int(len(datastores)) }, "time": int(time.time()) }) containerView = content.viewManager.CreateContainerView(container, viewType, recursive) children = containerView.view print("클러스터 수: ", len(children)) for child in children: if isinstance(child, vim.HostSystem): boot_time = child.runtime.bootTime print("datae", datetime.datetime.now(boot_time.tzinfo) - boot_time) print("date2", int((datetime.datetime.now(boot_time.tzinfo) - boot_time).total_seconds())) dk_object.append({ "measurement": "vmware_esxi", "tags": { "name": str(child.name), "model": str(child.hardware.systemInfo.model), "vendor": str(child.hardware.systemInfo.vendor), "uptime": str((datetime.datetime.now(boot_time.tzinfo) - boot_time)) }, "fields": { "cpu_cores": str(child.hardware.cpuInfo.numCpuCores), "memory": str(child.hardware.memorySize) }, "time": int(time.time()) }) dk_metric.append({ "measurement": "vmware", "tags": { "esxi_name": str(child.name), "esxi_model": str(child.hardware.systemInfo.model), "esxi_vendor": str(child.hardware.systemInfo.vendor) }, "fields": { "cpu_cores": int(child.hardware.cpuInfo.numCpuCores), "memory": int(child.hardware.memorySize), "cpu_usage": int(child.summary.quickStats.overallCpuUsage), "mem_usage": int(child.summary.quickStats.overallMemoryUsage), "mem_utilization_rate": int(child.summary.quickStats.overallMemoryUsage / child.hardware.memorySize), "uptime": int((datetime.datetime.now(boot_time.tzinfo) - boot_time).total_seconds()) }, "time": int(time.time()) }) elif isinstance(child, vim.VirtualMachine): if child.runtime.powerState == 'poweredOn': # 켜진 VM만 출력 boot_time = child.runtime.bootTime dk_object.append({ "measurement": "vmware_vm", "tags": { "name": str(child.name), "host_name": str(child.guest.hostName), "guest_os": str(child.config.guestFullName), "ip_address": str(child.guest.ipAddress), "uptime": str((datetime.datetime.now(boot_time.tzinfo) - boot_time)) }, "fields": { "cpu_cores": str(child.config.hardware.numCPU), "memory": str(child.config.hardware.memoryMB) }, "time": int(time.time()) }) dk_metric.append({ "measurement": "vmware", "tags": { "vm_name": str(child.name), "vm_host_name": str(child.guest.hostName), "vm_ip_address": str(child.guest.ipAddress) }, "fields": { "cpu_cores": int(child.config.hardware.numCPU), "memory": int(child.config.hardware.memoryMB), "cpu_usage": int(child.summary.quickStats.overallCpuUsage), "mem_usage": int(child.summary.quickStats.guestMemoryUsage), "mem_utilization_rate": int(child.summary.quickStats.guestMemoryUsage / child.config.hardware.memoryMB), "disk_usage": int(child.summary.storage.committed), "uptime": int((datetime.datetime.now(boot_time.tzinfo) - boot_time).total_seconds()) }, "time": int(time.time()) }) containerView.Destroy() # response_object = requests.post(datakit_url_object, headers=header, json=dk_object) # response_metric = requests.post(datakit_url_metric, headers=header, json=dk_metric) in_data = { 'CO': dk_object, 'input': 'vmware_esxi,vmware_vm' } self.report(in_data) in_data2 = { 'M': dk_metric, 'input': 'vmware' } self.report(in_data2) Disconnect(c) print("--------------성공---------------") -
DataKit을 재시작합니다:
지표¶
VMware 모니터링을 구성하면 기본 지표 집합은 다음과 같습니다
| 지표 | 지표명 | 단위 |
|---|---|---|
vcenter_total |
센터 수 | 개 |
vcenter_datastore_total_capacity |
센터 디스크 총 용량 | B |
vcenter_datastore_total_free_space |
센터 디스크 남은 용량 | B |
vcenter_datastore_total |
센터 디스크 개수 | 개 |
cpu_cores |
CPU 코어 수 | 개 |
memory |
메모리 크기 | MB |
cpu_usage |
CPU 사용량 | MHz |
mem_usage |
메모리 사용량 | MB |
uptime |
가동 시간 | 초 |
disk_usage |
디스크 사용량 | B |
객체¶
"measurement": "vmware_esxi",
"tags": {
"name": "10.200.14.10",
"model": "PowerEdge R740",
"vendor": "Dell Inc.",
"uptime": "120 days, 6:04:50.399418"
},
"fields": {
"cpu_cores": "20",
"memory": "410686889984"
}
"measurement": "vmware_vm",
"tags": {
"name": "fanjun-test",
"host_name": "zy-infra-sh-vm-fanjun",
"guest_os": "CentOS 7 (64-bit)",
"ip_address": "10.200.14.178",
"uptime": "104 days, 5:02:26.586303"
},
"fields": {
"cpu_cores": "2",
"memory": "4096"
}
일부 필드 설명은 다음과 같습니다:
| 필드 | 타입 | 설명 |
|---|---|---|
name |
String | 호스트명 |
model |
String | 하드웨어 모델. |
vendor |
String | 하드웨어 공급업체 |
uptime |
String | 가동 시간 |
guest_os |
String | 가상 머신 버전. |
ip_address |
String | 가상 머신의 IP 주소. |
cpu_cores |
String | CPU 코어 수. |
memory |
String | 메모리 크기( Byte)。 |