Vmware Vsphere WebService之vijava 开发(二)一性能信息的采集(实时监控)
最近一直没有更新这部分的内容,会利用五一时间完成vcenter这一个系列。
这里先给大家一本关于vijava开发的书,比较实用。
地址:http://pan.baidu.com/s/1gfkl9mj。密码:t1y3
有网友评论要数据存储读写速度及延迟之后时间的实现。今天就先介绍关于java实现实时监控vcenter状态的内容,包括CPU、内存、网络、存储等。
在看这篇前如果还是新手,建议先看下我的第一篇 http://www.cnblogs.com/xiaodige/p/6721517.html(vijava基本连接和数据中心信息获取)
先说一下我之前是怎么发现,CPU、内存、网络、存储等可以监控的内容。我用vsphere client连接vcenter查看客户端所能监控的属性.
建议大家在实现功能前,先看下官方文档关于性能监控的知识。贴上连接vcenter6.0的官方文档连接。http://pubs.vmware.com/vsphere-60/index.jsp
比如要监控虚拟机的性能信息:首先得保证虚拟机开机,选择“性能选项”,点击“图标选项”,这样就能看到它所支持的性能监控信息。下面贴图:

下图左边就是该对象具体能监控的信息,右边就是具体性能,使用率啊等等。

做性能监控这块,如果不知道具体能监控对象的哪些属性就打开客户端看看。下面就贴上具体的java实现代码。
package com.iking.vmware.performance; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.iking.vmware.bean.PerformanceManage;
import com.iking.vmware.bean.VsphereConst;
import com.iking.vmware.connection.ConnectedVimServiceBase;
import com.iking.vmware.vim25.PerfCounterInfo;
import com.iking.vmware.vim25.PerfEntityMetric;
import com.iking.vmware.vim25.PerfEntityMetricBase;
import com.iking.vmware.vim25.PerfMetricId;
import com.iking.vmware.vim25.PerfMetricIntSeries;
import com.iking.vmware.vim25.PerfMetricSeries;
import com.iking.vmware.vim25.PerfQuerySpec;
import com.iking.vmware.vim25.PerfSampleInfo;
import com.iking.vmware.vim25.mo.Folder;
import com.iking.vmware.vim25.mo.HostSystem;
import com.iking.vmware.vim25.mo.InventoryNavigator;
import com.iking.vmware.vim25.mo.ManagedEntity;
import com.iking.vmware.vim25.mo.PerformanceManager; /**
* @description 监控统计vcenter所有对象性能数据
* @date 2017年2月9日11:46:35
* @version 1.1
* @author DiWk
*/
public class PerformanceCounter {
private ConnectedVimServiceBase cs = null; public ConnectedVimServiceBase getCs() {
return cs;
} public void setCs(ConnectedVimServiceBase cs) {
this.cs = cs;
} /**
* @description 根据属性名称、类型、对象、采集间隔获取所有的性能数据
* @date 2017年2月8日14:37:58
* @return PerformanceMap 性能数据map对象
* @version 1.1
* @author DiWk
*/
public Map<String, PerformanceManage> getPerfData(String nameInfo, List<String> groupInfo, ManagedEntity mo,
Integer interval) {
Map<String, PerformanceManage> PerformanceMap = null; Date date = new Date();
Date sTime = new Date(date.getTime() - 24 * 60 * 60 * 1000); Calendar calBegin = Calendar.getInstance();
calBegin.setTime(sTime); Calendar calEnd = Calendar.getInstance();
calEnd.setTime(date); try {
PerformanceMap = new HashMap<String, PerformanceManage>();
if (mo != null) {
PerformanceManager performanceManager = cs.si.getPerformanceManager();
PerfCounterInfo[] cInfo = performanceManager.getPerfCounter(); Map<Integer, PerfCounterInfo> counters = new HashMap<Integer, PerfCounterInfo>(); for (PerfCounterInfo pcInfo : cInfo) {
counters.put(new Integer(pcInfo.getKey()), pcInfo);
} PerfMetricId[] listpermeid = performanceManager.queryAvailablePerfMetric(mo, null, null, interval); ArrayList<PerfMetricId> mMetrics = new ArrayList<PerfMetricId>();
if (listpermeid != null) {
for (int index = 0; index < listpermeid.length; ++index) {
if (counters.containsKey(new Integer(listpermeid[index].getCounterId()))) {
mMetrics.add(listpermeid[index]);
}
}
} PerfQuerySpec qSpec = new PerfQuerySpec();
qSpec.setEntity(mo.getMOR());
qSpec.setMetricId(listpermeid);
qSpec.setStartTime(calBegin);
qSpec.setEndTime(calEnd);
qSpec.setIntervalId(interval);
qSpec.setFormat("normal"); PerfQuerySpec[] arryQuery = { qSpec }; PerfEntityMetricBase[] pValues = performanceManager.queryPerf(arryQuery); if (pValues == null || pValues.length <= 0) {
return null;
}
PerfSampleInfo[] listperfsinfo = ((PerfEntityMetric) pValues[0]).getSampleInfo();
for (int i = 0; i < pValues.length; i++) {
PerfMetricSeries[] listpems = ((PerfEntityMetric) pValues[i]).getValue(); for (int vi = 0; vi < listpems.length; ++vi) {
PerfCounterInfo pci = (PerfCounterInfo) counters
.get(new Integer(listpems[vi].getId().getCounterId())); if (pci != null) {
for (String Info : groupInfo) {
PerformanceManage performanceManage = new PerformanceManage();
performanceManage.setStartTime(listperfsinfo[0].getTimestamp().getTime());
performanceManage
.setEndTime((listperfsinfo[listperfsinfo.length - 1]).getTimestamp().getTime());
if (pci.getNameInfo().getKey().equalsIgnoreCase(nameInfo)
&& pci.getGroupInfo().getKey().equalsIgnoreCase(Info)) {
if (listpems[vi] instanceof PerfMetricIntSeries) {
PerfMetricIntSeries val = (PerfMetricIntSeries) listpems[vi];
long[] lislon = val.getValue(); List<Long> asList = new ArrayList<Long>();
for (Long k : lislon) {
asList.add(k);
}
performanceManage.setPerformanceValues(asList);
PerformanceMap.put(Info, performanceManage);
}
}
}
}
}
} }
} catch (Exception e) {
e.printStackTrace();
}
return PerformanceMap;
} /** main测试方法 */
public static void main(String[] args) throws Exception {
PerformanceCounter performanceCounter2 = new PerformanceCounter();
ConnectedVimServiceBase cs = new ConnectedVimServiceBase();
cs.connect("192.168.1.253", "administrator@vsphere.local", "Iking!@#456");
performanceCounter2.setCs(cs);
Folder rootFolder = cs.si.getRootFolder();
HostSystem dataCenter = (HostSystem) new InventoryNavigator(rootFolder)
.searchManagedEntity(VsphereConst.HOSTSYSTEM, "192.168.1.254");
List<String> listNm = new ArrayList<String>();
listNm.add("datastore");
Map<String, PerformanceManage> perfData = performanceCounter2.getPerfData("write", listNm, dataCenter, 20);
PerformanceManage performanceManage = perfData.get("datastore");
List<Long> performanceValues = performanceManage.getPerformanceValues();
System.out.println(performanceValues.toString());
}
}
上面就是通过Java代码实现对vcenter性能的实时监控,相信大家结合官方文档和我分享的电子书一定能实现自己想要的效果。
关于数据存储并没有历史信息的监控,只有实时信息的监控。所以当我统计数据存储的历史信息时,我是累加了所有的虚拟机、主机关于数据存储的数据。我知道这不是一个很好的方法,但是目前没想到更好的。希望和网友分享学习。
Vmware Vsphere WebService之vijava 开发(二)一性能信息的采集(实时监控)的更多相关文章
- Vmware Vsphere WebService之vijava 开发一-vcenter连接、及集群信息获取
开始是通过java代码调用vsphere提供的原始接口,从而控制vcenter的操作.当第一个版本做完之后发现代码执行的速度特别慢,后来在网上看到有人用vijava(对vsphere原始接口封装)编程 ...
- Vmware Vsphere WebService SDK开发(第一讲)-基本知识学习
刚开始这方面开发的时候,不知道如何下手,能够查到的资料特别少,而且看到很多网友和我一样也在找这方面的资料.接下来的一段时间我就结合自己所参与的项目,完成关于Vmware Vsphere WebServ ...
- Vmware vsphere webservice sdk 连接打开慢的问题
还在为VimService实例化速度慢的问题烦恼吗?这有一篇文章可以帮你解决问题,英文水平所限,就不翻译了,原文地址http://kb.vmware.com/selfservice/microsite ...
- 二十九、rsync+inotity实时监控同步工具
一.场景应用: 客户通过url访问资源(查询,下载等),并发量是非常高的,所以运用负载均衡分担web服务器的压力,在后端连接不同的 ...
- VMware vSphere 服务器虚拟化之二十五 桌面虚拟化之终端服务池
VMware vSphere 服务器虚拟化之二十五 桌面虚拟化之终端服务池 终端服务池是指由一台或多台微软终端服务器提供服务的桌面源组成的池.终端服务器桌面源可交付多个桌面.它具有以下特征: 1.终端 ...
- VMware vSphere 服务器虚拟化之二十二桌面虚拟化之创建View Composer链接克隆的虚拟桌面池
VMware vSphere 服务器虚拟化之二十二桌面虚拟化之创建View Composer链接克隆的虚拟桌面池 在上一节我们创建了完整克隆的自动专有桌面池,在创建过程比较缓慢,这次我们将学习创建Vi ...
- VMware vSphere 服务器虚拟化之二十八 桌面虚拟化之安装View传输服务器
VMware vSphere 服务器虚拟化之二十八 桌面虚拟化之安装View传输服务器 View 传输服务器用于管理和简化数据中心与在最终用户本地系统上检出使用的 View 桌面之间的数据传输.必须安 ...
- VMware vSphere 服务器虚拟化之二十七桌面虚拟化之View中使用Thinapp软件虚拟化
VMware vSphere 服务器虚拟化之二十七桌面虚拟化之View中使用Thinapp软件虚拟化 VMware ThinApp 应用程序虚拟化软件是无代理解决方案,通过将应用程序隔离并封装为EXE ...
- VMware vSphere 服务器虚拟化之二十六 桌面虚拟化之View Persona Management
VMware vSphere 服务器虚拟化之二十六 桌面虚拟化之View Persona Management 实验失败告终,启动VMware View Persona Management服务报10 ...
随机推荐
- 关于nodeJS多线程的支持,目前看来无法实现,讲解v8的一些东西
关于这个,我这几天一直在研究,国内关于v8的资料很少,stackoverflow上也不多. 说起来我得说声抱歉,虽然并没有承诺什么.这个功能大概是无法实现.下面我来解释一下为什么. 首先我们要了解一下 ...
- Servlet 3.0/3.1 中的异步处理
在Servlet 3.0之前,Servlet采用Thread-Per-Request的方式处理请求,即每一次Http请求都由某一个线程从头到尾负责处理.如果一个请求需要进行IO操作,比如访问数据库.调 ...
- IOS本地日志记录方案
我们在项目中日志记录这块也算是比较重要的,有时候用户程序出什么问题,光靠服务器的日志还不能准确的找到问题. 现在一般记录日志有几种方式: 1.使用第三方工具来记录日志,如腾讯的Bugly,它是只把程序 ...
- 【阿里聚安全技术公开课】移动APP漏洞风险与解决方案
阿里云·云栖社区携手阿里聚安全打造阿里安全技术公开课,带你一探互联网安全的风采 关于移动APP安全 移动App是大家使用手机每天接触最多的东西,然而在移动APP开发中,由于一些开发工程师对安全的不重视 ...
- Unity中溶解shader的总结
在实际的游戏工程中,经常美术和策划会提出溶解的表现要求.比如子弹在飞行的时候,弹道不断的消融:角色受到大型炮弹的攻击,在击飞的时候不断的消融等等诸如此类的表现.一般的消融都是结合粒子系统来实现,通过给 ...
- Python中参数是传值,还是传引用?
在 C/C++ 中,传值和传引用是函数参数传递的两种方式,在Python中参数是如何传递的?回答这个问题前,不如先来看两段代码. 代码段1: def foo(arg): arg = 2 print(a ...
- Knockoutjs:Component and Custom Elements(翻译文章)
Knockoutjs 的Components 是一种自定义的组件,它以一种强大.简介的方式将你自己的ui代码组织成一种单独的.可重用的模块,自定义的组件(Component)有以下特点: 1.可以替代 ...
- 使用jQuery监听扫码枪输入并禁止手动输入的实现方法
@(知识点总结)[jquery|扫码抢] 基于jQuery的扫码枪监听.如果只是想实现监听获取条码扫码信息,可以直接拿来使用,如果有更多的条码判断处理逻辑需要自己扩展. 一.功能需求 使用扫码枪扫描条 ...
- .Net轻量级ORM-NPoco的使用方法-摘自NPoco国外官方Wiki
文章引用自NPoco官方Wiki,地址:https://github.com/schotime/NPoco/wiki,因公司网络不稳定,有时无法访问,特将其摘抄. Home Adam Schroder ...
- 求一个int型整数的两种递减数之和(java)--2015华为机试题
题目描述: 给出一个整数(负数使用其绝对值),输出这个整数中的两种递减数(1.最大递减数:2.递减数中各位数之和最大的数)之和. 递减数:一个数字的递减数是指相邻的数位从大到小排列的数字,不包含相邻的 ...