Problems with SVN in Eclipse on Mac OS X Mountain Lion (10.8)

I’m working on a new PHP project. Until now I’ve mainly been working on a Windows machine but today I wanted to move to my MacBook. So I just created a working copy and created a PHP project in Eclipse referencing the working copy. Unfortunately I got the following error message:

Failed to load JavaHL Library.
These are the errors that were encountered:
no libsvnjavahl-1 in java.library.path
/usr/local/Cellar/subversion/1.7.8/lib/libsvnjavahl-1.0.dylib:  Library not loaded: /usr/local/lib/libsqlite3.0.8.6.dylib   Referenced from: /usr/local/Cellar/subversion/1.7.8/lib/libsvnjavahl-1.0.dylib   Reason: image not found
no svnjavahl in java.library.path
java.library.path = .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

I already had some issues with SVN on Mountain Lion some time ago. But I thought I was done with it. After carefully reading the error message, I remember I had just upgraded my Home Brew package and saw the following while upgrading sqllite:

==> Upgrading sqlite
==> Downloading http://sqlite.org/sqlite-autoconf-3071502.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sqlite/3.7.15.2 --enable-dynamic-extensions
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

OS X already provides (an older) sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include

OK, so now what ? First check whether the library missed by Eclipse is really missing:

$ ls -l /usr/local/lib/libsqlite3.0.8.6.dylib
ls: /usr/local/lib/libsqlite3.0.8.6.dylib: No such file or directory

Ok, then try to find it:

$ find /usr -name "libsqlite3.0.8.6.dylib"
/usr/local/Cellar/sqlite/3.7.10/lib/libsqlite3.0.8.6.dylib
/usr/local/Cellar/sqlite/3.7.13/lib/libsqlite3.0.8.6.dylib
/usr/local/Cellar/sqlite/3.7.14.1/lib/libsqlite3.0.8.6.dylib
/usr/local/Cellar/sqlite/3.7.15/lib/libsqlite3.0.8.6.dylib
/usr/local/Cellar/sqlite/3.7.15.2/lib/libsqlite3.0.8.6.dylib
find: /usr/sbin/authserver: Permission denied

Ok so I have the choice. Now let’s just create a soft link to one of them:

$ ln -s /usr/local/Cellar/sqlite/3.7.15.2/lib/libsqlite3.0.8.6.dylib /usr/local/lib/libsqlite3.0.8.6.dylib

Now, deleting the project and recreating again isn’t enough since it will not try again to get the whole subversion thing working. You need to restart eclipse and recreate the project.
This time the subversion binding did work and after converting the working copy (it looks like I created it with svn 1.6 instead of 1.7), everything was working fine !

Eclipse: No entries available when choosing PHP file for debugging

I have Eclipse Juno installed. I created a PHP project for a new application I’m working on (you’ll hear more about this project in the next weeks), imported the code. Then I wanted to debug it. But run into a few problems…

First I couldn’t create a “PHP Web Application” debug configuration because of the following error:

 No tab group defined for launch configuration type org.eclipse.php.debug.core.launching.webPageLaunch

After spending some time on Google I found out it is because Eclipse Juno comes with an older version of PDT and I needed to install 3.1.1 or newer. Some how it also took me a while to find out that the right update site was http://download.eclipse.org/tools/pdt/updates/3.2/release/. Well everybody is allowed to have a slow brain once in a while…

While installing got another error with some missing dependencies… The PDT Core Unit Tests was missing bundle org.eclipse.dltk.core.tests 0.0.0. The package name ending with 0.0.0 doesn’t seem right but it was solved by just installing PDT and not the Unit Tests package. I wasn’t really planning to use this package but it’s always nice to know I couldn’t even if I wanted to :-).

Then I checked the debug configuration again. Now I was able to create a PHP Web Application debug configuration but when I clicked on Browse to select the file to debug, I just got a disabled UI saying that no files were available. Searching in Google confirmed that I’m not the only one with the problem but I didn’t find a documented solution except some hints that it might mean that I didn’t have a PHP project. But I actually did have one (had the nice PHP icon next to my project name in the project explorer). Since googling wasn’t looking very promising, I started looking all context menu entries when right clicking on the project. And I found a menu entry:

Configure > Add PHP Support...

Well it actually didn’t make much sense to me. Why would I need to add PHP support to a PHP project. If anything should already have PHP support, it should be a PHP project. But I didn’t have any other lead so I just did it. It updated the project file. And there it was, I was then able to select a PHP file to debug !!

Summary:

  • Update the PDT installation in Eclipse to the newest one
  • Only install the PDT package and not the PDT Core Unit Tests package
  • Add PHP support to your PHP project

JBoss: Get data using JMX

First in order to get data from JBoss using JMX, you need to add jboss-client.jar to your classpath. You can find this JAR file in the client directory of your JBoss installation.

In order to open a connection, you first need to create a URL:

String host = "localhost";
String port = "9010";
String urlString = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";

You can then use this URL to get a connection to the MBean server:

JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

With this MBean server connection, you can now for example get the number of MBeans:

int count = connection.getMBeanCount();
System.out.println("MBean count = " + count);

Now to get some more useful information, you’ll need to get an Object Name and can then use it to query some attributes of an MBean e.g.:

ObjectName objectName = new ObjectName("jboss.system:type=ServerInfo");
Integer activeThreadCount = (Integer) connection.getAttribute(objectName, "ActiveThreadCount");
System.out.println("activeThreadCount = " + activeThreadCount);

Similarly, you can also call a function of an MBean:

objectName = new ObjectName("org.hornetq:address=\"jms.queue.DLQ\",module=Core,name=\"jms.queue.DLQ\",type=Queue");
Object obj = connection.invoke(objectName, "listMessages", new Object[] {""}, new String[] { "java.lang.String" });
System.out.println("messages = "+obj.toString());

The parameters to the invoke method of the connection are:

  1. The object name specifying which MBean you want to work with.
  2. The name of the MBean method you want to call.
  3. An array containing the parameters of the method (in our case an empty String).
  4. The signature of the method (in our case, the method takes a String as parameter).

Once you are done, you just need to close the JMX connection:

jmxConnector.close();

MySQLBuddy 1.0 released

Since I’m not only using Sybase at work but also MySQL, I finally took the time to create a clone of SybaseBuddy for MySQL.

This new tool is called MySQLBuddy. Since both tools mainly provide the same functionality, they share most of their code. Of course at some point in time, I’ll put my software architect hat back on and will refactor the tools so that I have one tool supporting multiple databases. Unfortunately, I currently lack the time for this and will thus for the time being maintain both tools separately.

Apple Releases Java 2012-005

After Oracle releasing security updates for Java version 6 and 7, now Apple is following and distributes Java for Mac OS X 2012-005 moving to version 1.6.0_35, and thus the necessary corrections to its own OS X implementation. Moreover, the Safari plugin is configured so that it is automatically disabled when no applets are run a long time. If you want to re-enable Java, you have to do this via the plugin settings.

The update “Java for Mac OS X 2012-005” requires Mac OS X 10.7.4 or Mac OS X 10.8.1 while “Java for Mac OS X 10.6 Update 10” requires Mac OS X 10.6.8. Both updates improve the security, reliability and compatibility of Java SE 6 (by updating it to version 1.6.0_35).

Before installing the update, all web browsers and Java programs that are running must be closed.

Starting with version 7.0, Oracle will take care of the deployment of Java for Mac OS X. The latest Java 7 version for the Mac (a developer version) is available on this web page for download.

Eclipse: Setting the proxy configuration

I wanted to install the EGit plugin in eclipse and couldn’t connect to the marketplace. So I checked the proxy settings in Window / Preferences / General / Network Connections.
Proxy settings in Eclipse
It was set by default to Native. My understanding is that Native means to use the settings of the OS. I’m running Windows 7 64 bits. Somehow no connection was possible. So I changed it to Manual and manually entered the proxy hostname and port in all three entries. This didn’t work either.

Then I noticed that the third one wasn’t FTP but SOCKS (I’ve somehow looked at the dialog X times and each time read FTP instead of SOCKS). Since there are checkboxes in front of the entries I tried unchecking the one in front of SOCKS but it didn’t seem to be an editable check box. So I selected SOCKS and pressed Clear. And there it was, I could now connect to the marketplace! I somehow really hate this dialog. From a usability point of view it’s a real mess. But of course if I first had thought and then entered something in the SOCKS entry, I would have saved quite some time… Stupid me…

Getting info from your ESX server using the VMware Infrastructure (vSphere) Java API (Part 3)

In the first part, we’ve seen how to get general information about the ESX hosts.

In the second part, we’ve read some information about the virtual machines running on a given host.

In this part, we’ll get started with performance counters. Your ESX system collects data at runtime about performance for all aspects of the system—CPU, disk, memory, network, and so on. The data in the counters is accessible through the PerformanceManager class.

You can get an instance of the PerformanceMangager like this:

ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true);
PerformanceManager perfMgr = si.getPerformanceManager();

The performance manager has a getPerfCounters method which will return a list of all available counters:

PerfCounterInfo[] perfCounters = perfMgr.getPerfCounter();
for (int i = 0; i < perfCounters.length; i++) {
	PerfCounterInfo perfCounterInfo = perfCounters[i];
	String perfCounterString = perfCounterInfo.getNameInfo().getLabel() + " (" + perfCounterInfo.getGroupInfo().getKey() + ") in "
			+ perfCounterInfo.getUnitInfo().getLabel() + " (" + perfCounterInfo.getStatsType().toString() + ")";
		System.out.println(perfCounterInfo.getKey() + " : " + perfCounterString);
}

This will return a list like this:

1 : Usage (cpu) in Percent (rate)
...
336 : Queue write latency (disk) in Millisecond (absolute)
337 : Physical device command latency (disk) in Millisecond (absolute)
338 : Kernel command latency (disk) in Millisecond (absolute)

perfCounterInfo.getKey() returns the key with which you can identify the counter to get some information about the performance of the system.

Here the whole code for this example:

package com.benohead.esx;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.PerfCounterInfo;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.mo.PerformanceManager;
import com.vmware.vim25.mo.ServiceInstance;

public class ListCounters {

	static final String SERVER_NAME = "192.168.190.87";
	static final String USER_NAME = "Administrator";
	static final String PASSWORD = "xxxxxx";

	public static void main(String[] args) {
		String url = "https://" + SERVER_NAME + "/sdk/vimService";
		// List counters
		try {
			ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true);
			PerformanceManager perfMgr = si.getPerformanceManager();

			PerfCounterInfo[] perfCounters = perfMgr.getPerfCounter();
			for (int i = 0; i < perfCounters.length; i++) {
				PerfCounterInfo perfCounterInfo = perfCounters[i];
				String perfCounterString = perfCounterInfo.getNameInfo().getLabel() + " (" + perfCounterInfo.getGroupInfo().getKey() + ") in "
						+ perfCounterInfo.getUnitInfo().getLabel() + " (" + perfCounterInfo.getStatsType().toString() + ")";
				System.out.println(perfCounterInfo.getKey() + " : " + perfCounterString);
			}
			si.getServerConnection().logout();
		} catch (InvalidProperty e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RuntimeFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

A query for performance counter is done using the PerformanceManager. In order to query for counters you need to create an instance of PerfQuerySpec which defines what we’ll be querying. You need to define the following:

  • which entity should be queried (in our case the host)
  • which metrics should be queried (e.g. the counter number 25 (active memory in KB)
  • the query interval: The interval (sampling period) in seconds for which performance statistics are queried. There is a set of intervals for historical statistics. To retrieve the greatest available level of detail, the provider’s refreshRate may be used for this property

First let’s get the metric ID we want to use to filter the results:

PerfMetricId[] queryAvailablePerfMetric = perfMgr.queryAvailablePerfMetric(host, null, null, perfInterval);
ArrayList<PerfMetricId> list = new ArrayList<PerfMetricId>();
for (int i2 = 0; i2 < queryAvailablePerfMetric.length; i2++) {
	PerfMetricId perfMetricId = queryAvailablePerfMetric[i2];
	if (SELECTED_COUNTER_ID == perfMetricId.getCounterId()) {
		list.add(perfMetricId);
	}
}
PerfMetricId[] pmis = list.toArray(new PerfMetricId[list.size()]);

where SELECTED_COUNTER_ID is a constant we’ve define containing the counter ID we want to retrieve (e.g. 25).

Then let’s get the interval ID:

PerfProviderSummary summary = perfMgr.queryPerfProviderSummary(host);
int perfInterval = summary.getRefreshRate();

This will return the greatest available level of detail (i.e. 20 seconds).

Now we can create a PerfQuerySpec:

PerfQuerySpec qSpec = new PerfQuerySpec();
qSpec.setEntity(host.getMOR());
qSpec.setMetricId(pmis);
qSpec.intervalId = perfInterval;

Running the query is just a call to the queryPerf method of the performance manager:

PerfEntityMetricBase[] pembs = perfMgr.queryPerf(new PerfQuerySpec[] { qSpec });

Now we can iterate through the results and print the counter values:

for (int i = 0; pembs != null && i < pembs.length; i++) {
	PerfEntityMetricBase val = pembs[i];
	PerfEntityMetric pem = (PerfEntityMetric) val;
	PerfMetricSeries[] vals = pem.getValue();
	PerfSampleInfo[] infos = pem.getSampleInfo();

	for (int j = 0; vals != null && j < vals.length; ++j) {
		PerfMetricIntSeries val1 = (PerfMetricIntSeries) vals[j];
		long[] longs = val1.getValue();
		for (int k = 0; k < longs.length; k++) {
			System.out.println(infos[k].getTimestamp().getTime() + " : " + longs[k]);
		}
		System.out.println();
	}
}

This will return something like:

Tue Jul 31 12:30:15 CEST 2012 : 1165824
Tue Jul 31 12:30:35 CEST 2012 : 1333596
Tue Jul 31 12:30:55 CEST 2012 : 1165824
Tue Jul 31 12:31:15 CEST 2012 : 1244900
Tue Jul 31 12:31:35 CEST 2012 : 1244900
Tue Jul 31 12:31:55 CEST 2012 : 1244900
Tue Jul 31 12:32:15 CEST 2012 : 1256692
Tue Jul 31 12:32:35 CEST 2012 : 1256692
Tue Jul 31 12:32:55 CEST 2012 : 1592236
Tue Jul 31 12:33:15 CEST 2012 : 1639196
Tue Jul 31 12:33:35 CEST 2012 : 1982884
Tue Jul 31 12:33:55 CEST 2012 : 1647340
Tue Jul 31 12:34:15 CEST 2012 : 1652860
Tue Jul 31 12:34:35 CEST 2012 : 1023712
Tue Jul 31 12:34:55 CEST 2012 : 1023712
Tue Jul 31 12:35:15 CEST 2012 : 949708
Tue Jul 31 12:35:35 CEST 2012 : 1201368
Tue Jul 31 12:35:55 CEST 2012 : 1209508
Tue Jul 31 12:36:15 CEST 2012 : 1209508
Tue Jul 31 12:36:35 CEST 2012 : 957852
Tue Jul 31 12:36:55 CEST 2012 : 974136
Tue Jul 31 12:37:15 CEST 2012 : 1009320
Tue Jul 31 12:37:35 CEST 2012 : 1040628
Tue Jul 31 12:37:55 CEST 2012 : 1040628
Tue Jul 31 12:38:15 CEST 2012 : 997300
Tue Jul 31 12:38:35 CEST 2012 : 1123128
Tue Jul 31 12:38:55 CEST 2012 : 1123128
Tue Jul 31 12:39:15 CEST 2012 : 1107476
Tue Jul 31 12:39:35 CEST 2012 : 1652732
Tue Jul 31 12:39:55 CEST 2012 : 1652732
Tue Jul 31 12:40:15 CEST 2012 : 1647840
Tue Jul 31 12:40:35 CEST 2012 : 1621556
Tue Jul 31 12:40:55 CEST 2012 : 1286012
Tue Jul 31 12:41:15 CEST 2012 : 1301032
Tue Jul 31 12:41:35 CEST 2012 : 1091316
Tue Jul 31 12:41:55 CEST 2012 : 1091316
Tue Jul 31 12:42:15 CEST 2012 : 1076296
Tue Jul 31 12:42:35 CEST 2012 : 1411840
Tue Jul 31 12:42:55 CEST 2012 : 1747384
Tue Jul 31 12:43:15 CEST 2012 : 1720340
Tue Jul 31 12:43:35 CEST 2012 : 1468684
Tue Jul 31 12:43:55 CEST 2012 : 1141280
Tue Jul 31 12:44:15 CEST 2012 : 1170316
Tue Jul 31 12:44:35 CEST 2012 : 1002540
Tue Jul 31 12:44:55 CEST 2012 : 1002540
Tue Jul 31 12:45:15 CEST 2012 : 1003172
Tue Jul 31 12:45:35 CEST 2012 : 919288
Tue Jul 31 12:45:55 CEST 2012 : 1087060
Tue Jul 31 12:46:15 CEST 2012 : 1057116
Tue Jul 31 12:46:35 CEST 2012 : 1308772
Tue Jul 31 12:46:55 CEST 2012 : 1141000
Tue Jul 31 12:47:15 CEST 2012 : 1133760
Tue Jul 31 12:47:35 CEST 2012 : 1133760
Tue Jul 31 12:47:55 CEST 2012 : 1133760
Tue Jul 31 12:48:15 CEST 2012 : 1292764
Tue Jul 31 12:48:35 CEST 2012 : 1208880
Tue Jul 31 12:48:55 CEST 2012 : 1208880
Tue Jul 31 12:49:15 CEST 2012 : 1264212
Tue Jul 31 12:49:35 CEST 2012 : 1515868
Tue Jul 31 12:49:55 CEST 2012 : 1524008
Tue Jul 31 12:50:15 CEST 2012 : 1340856
Tue Jul 31 12:50:35 CEST 2012 : 1718344
Tue Jul 31 12:50:55 CEST 2012 : 1550572
Tue Jul 31 12:51:15 CEST 2012 : 1513116
Tue Jul 31 12:51:35 CEST 2012 : 1515736
Tue Jul 31 12:51:55 CEST 2012 : 1431848
Tue Jul 31 12:52:15 CEST 2012 : 1662864
Tue Jul 31 12:52:35 CEST 2012 : 1411208
Tue Jul 31 12:52:55 CEST 2012 : 1662868
Tue Jul 31 12:53:15 CEST 2012 : 1480704
Tue Jul 31 12:53:35 CEST 2012 : 1564588
Tue Jul 31 12:53:55 CEST 2012 : 1483324
Tue Jul 31 12:54:15 CEST 2012 : 1426964
Tue Jul 31 12:54:35 CEST 2012 : 1343080
Tue Jul 31 12:54:55 CEST 2012 : 1190960
Tue Jul 31 12:55:15 CEST 2012 : 1182816
Tue Jul 31 12:55:35 CEST 2012 : 1098928
Tue Jul 31 12:55:55 CEST 2012 : 1157156
Tue Jul 31 12:56:15 CEST 2012 : 1165296
Tue Jul 31 12:56:35 CEST 2012 : 1416956
Tue Jul 31 12:56:55 CEST 2012 : 1291128
Tue Jul 31 12:57:15 CEST 2012 : 1282712
Tue Jul 31 12:57:35 CEST 2012 : 1114940
Tue Jul 31 12:57:55 CEST 2012 : 1031052
Tue Jul 31 12:58:15 CEST 2012 : 1039468
Tue Jul 31 12:58:35 CEST 2012 : 1139004
Tue Jul 31 12:58:55 CEST 2012 : 1139004
Tue Jul 31 12:59:15 CEST 2012 : 1196276
Tue Jul 31 12:59:35 CEST 2012 : 1206760
Tue Jul 31 12:59:55 CEST 2012 : 1332588
Tue Jul 31 13:00:15 CEST 2012 : 1291880
Tue Jul 31 13:00:35 CEST 2012 : 1291880
Tue Jul 31 13:00:55 CEST 2012 : 1585484
Tue Jul 31 13:01:15 CEST 2012 : 1534920
Tue Jul 31 13:01:35 CEST 2012 : 1534920
Tue Jul 31 13:01:55 CEST 2012 : 1660748
Tue Jul 31 13:02:15 CEST 2012 : 1694676
Tue Jul 31 13:02:35 CEST 2012 : 1789048
Tue Jul 31 13:02:55 CEST 2012 : 2040704
Tue Jul 31 13:03:15 CEST 2012 : 2040704
Tue Jul 31 13:03:35 CEST 2012 : 2292360
Tue Jul 31 13:03:55 CEST 2012 : 2124588
Tue Jul 31 13:04:15 CEST 2012 : 1836664
Tue Jul 31 13:04:35 CEST 2012 : 1532428
Tue Jul 31 13:04:55 CEST 2012 : 1532428
Tue Jul 31 13:05:15 CEST 2012 : 1406600
Tue Jul 31 13:05:35 CEST 2012 : 1409220
Tue Jul 31 13:05:55 CEST 2012 : 1414464
Tue Jul 31 13:06:15 CEST 2012 : 1307132
Tue Jul 31 13:06:35 CEST 2012 : 1223248
Tue Jul 31 13:06:55 CEST 2012 : 1055476
Tue Jul 31 13:07:15 CEST 2012 : 907644
Tue Jul 31 13:07:35 CEST 2012 : 991528
Tue Jul 31 13:07:55 CEST 2012 : 1007180
Tue Jul 31 13:08:15 CEST 2012 : 1071056
Tue Jul 31 13:08:35 CEST 2012 : 1322716
Tue Jul 31 13:08:55 CEST 2012 : 1322716
Tue Jul 31 13:09:15 CEST 2012 : 1293120
Tue Jul 31 13:09:35 CEST 2012 : 1377004
Tue Jul 31 13:09:55 CEST 2012 : 1379624
Tue Jul 31 13:10:15 CEST 2012 : 1481656
Tue Jul 31 13:10:35 CEST 2012 : 1649428
Tue Jul 31 13:10:55 CEST 2012 : 1649428
Tue Jul 31 13:11:15 CEST 2012 : 1665988
Tue Jul 31 13:11:35 CEST 2012 : 1414332
Tue Jul 31 13:11:55 CEST 2012 : 1414332
Tue Jul 31 13:12:15 CEST 2012 : 1325204
Tue Jul 31 13:12:35 CEST 2012 : 1249460
Tue Jul 31 13:12:55 CEST 2012 : 1417232
Tue Jul 31 13:13:15 CEST 2012 : 1362736
Tue Jul 31 13:13:35 CEST 2012 : 1619412
Tue Jul 31 13:13:55 CEST 2012 : 1619412
Tue Jul 31 13:14:15 CEST 2012 : 2476068
Tue Jul 31 13:14:35 CEST 2012 : 2476068
Tue Jul 31 13:14:55 CEST 2012 : 2308296
Tue Jul 31 13:15:15 CEST 2012 : 2867220
Tue Jul 31 13:15:35 CEST 2012 : 2752024
Tue Jul 31 13:15:55 CEST 2012 : 2754644
Tue Jul 31 13:16:15 CEST 2012 : 3030724
Tue Jul 31 13:16:35 CEST 2012 : 2870816
Tue Jul 31 13:16:55 CEST 2012 : 3208984
Tue Jul 31 13:17:15 CEST 2012 : 3033068
Tue Jul 31 13:17:35 CEST 2012 : 3316036
Tue Jul 31 13:17:55 CEST 2012 : 3148264
Tue Jul 31 13:18:15 CEST 2012 : 2873848
Tue Jul 31 13:18:35 CEST 2012 : 3109852
Tue Jul 31 13:18:55 CEST 2012 : 3109852
Tue Jul 31 13:19:15 CEST 2012 : 3065288
Tue Jul 31 13:19:35 CEST 2012 : 2394200
Tue Jul 31 13:19:55 CEST 2012 : 2394200
Tue Jul 31 13:20:15 CEST 2012 : 2360120
Tue Jul 31 13:20:35 CEST 2012 : 2527892
Tue Jul 31 13:20:55 CEST 2012 : 2527892
Tue Jul 31 13:21:15 CEST 2012 : 2684896
Tue Jul 31 13:21:35 CEST 2012 : 2113348
Tue Jul 31 13:21:55 CEST 2012 : 1945576
Tue Jul 31 13:22:15 CEST 2012 : 1910668
Tue Jul 31 13:22:35 CEST 2012 : 1826780
Tue Jul 31 13:22:55 CEST 2012 : 1826780
Tue Jul 31 13:23:15 CEST 2012 : 1807876
Tue Jul 31 13:23:35 CEST 2012 : 2117132
Tue Jul 31 13:23:55 CEST 2012 : 2452676
Tue Jul 31 13:24:15 CEST 2012 : 2447156
Tue Jul 31 13:24:35 CEST 2012 : 2442140
Tue Jul 31 13:24:55 CEST 2012 : 2190480
Tue Jul 31 13:25:15 CEST 2012 : 2182336
Tue Jul 31 13:25:35 CEST 2012 : 2271240
Tue Jul 31 13:25:55 CEST 2012 : 2271240
Tue Jul 31 13:26:15 CEST 2012 : 2260480
Tue Jul 31 13:26:35 CEST 2012 : 2092708
Tue Jul 31 13:26:55 CEST 2012 : 1715224
Tue Jul 31 13:27:15 CEST 2012 : 1712324
Tue Jul 31 13:27:35 CEST 2012 : 1681020
Tue Jul 31 13:27:55 CEST 2012 : 1848792
Tue Jul 31 13:28:15 CEST 2012 : 1867976
Tue Jul 31 13:28:35 CEST 2012 : 2043612
Tue Jul 31 13:28:55 CEST 2012 : 1917780
Tue Jul 31 13:29:15 CEST 2012 : 1917780
Tue Jul 31 13:29:35 CEST 2012 : 1781312
Tue Jul 31 13:29:55 CEST 2012 : 1781312

Here the complete code for the counter query:

package com.benohead.esx;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList;

import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.PerfEntityMetric;
import com.vmware.vim25.PerfEntityMetricBase;
import com.vmware.vim25.PerfMetricId;
import com.vmware.vim25.PerfMetricIntSeries;
import com.vmware.vim25.PerfMetricSeries;
import com.vmware.vim25.PerfProviderSummary;
import com.vmware.vim25.PerfQuerySpec;
import com.vmware.vim25.PerfSampleInfo;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.PerformanceManager;
import com.vmware.vim25.mo.ServiceInstance;

public class DiplayHostCounter {

	static final String SERVER_NAME = "192.168.190.87";
	static final String USER_NAME = "Administrator";
	static final String PASSWORD = "xxxxxx";
	private static final String HOSTNAME = "192.168.190.34";
	private static final int SELECTED_COUNTER_ID = 25; // Active (mem) in KB (absolute)

	public static void main(String[] args) {
		String url = "https://" + SERVER_NAME + "/sdk/vimService";
		try {
			ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true);
			HostSystem host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("HostSystem", HOSTNAME);
			PerformanceManager perfMgr = si.getPerformanceManager();
			System.out.println("Counter ID = " + SELECTED_COUNTER_ID);

			PerfProviderSummary summary = perfMgr.queryPerfProviderSummary(host);
			int perfInterval = summary.getRefreshRate();
			System.out.println("Refresh rate = " + perfInterval);

			PerfMetricId[] queryAvailablePerfMetric = perfMgr.queryAvailablePerfMetric(host, null, null, perfInterval);
			ArrayList<PerfMetricId> list = new ArrayList<PerfMetricId>();
			for (int i2 = 0; i2 < queryAvailablePerfMetric.length; i2++) {
				PerfMetricId perfMetricId = queryAvailablePerfMetric[i2];
				if (SELECTED_COUNTER_ID == perfMetricId.getCounterId()) {
					list.add(perfMetricId);
				}
			}
			PerfMetricId[] pmis = list.toArray(new PerfMetricId[list.size()]);

			PerfQuerySpec qSpec = new PerfQuerySpec();
			qSpec.setEntity(host.getMOR());
			qSpec.setMetricId(pmis);
			qSpec.intervalId = perfInterval;

			PerfEntityMetricBase[] pembs = perfMgr.queryPerf(new PerfQuerySpec[] { qSpec });
			for (int i = 0; pembs != null && i < pembs.length; i++) {
				PerfEntityMetricBase val = pembs[i];
				PerfEntityMetric pem = (PerfEntityMetric) val;
				PerfMetricSeries[] vals = pem.getValue();
				PerfSampleInfo[] infos = pem.getSampleInfo();

				for (int j = 0; vals != null && j < vals.length; ++j) {
					PerfMetricIntSeries val1 = (PerfMetricIntSeries) vals[j];
					long[] longs = val1.getValue();
					for (int k = 0; k < longs.length; k++) {
						System.out.println(infos[k].getTimestamp().getTime() + " : " + longs[k]);
					}
					System.out.println();
				}
			}
			si.getServerConnection().logout();
		} catch (InvalidProperty e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RuntimeFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

In the vShpere client, it looks like this:

Getting info from your ESX server using the VMware Infrastructure (vSphere) Java API (Part 2)

In the first part, we’ve seen how to get general information about the ESX hosts.

In this part, we’ll read some information about the virtual machines running on a given host.

VirtualMachines like almost everything in ESX are managed entities. So you can query them using InventoryNavigator.searchManagedEntities:

ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true);
HostSystem host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("HostSystem", HOSTNAME);
ManagedEntity[] managedEntities = new InventoryNavigator(host).searchManagedEntities("VirtualMachine");

Note: if you use si.getRootFolder() instead of host you will get all VMs running on all hosts managed by your ESX infrastructure.

Once you have a virtual machine, you can get the virtual machine configuration information using:

VirtualMachineConfigInfo config = vm.getConfig();

And from this VirtualMachineConfigInfo you can get data related to the configured virtual hardware:

private static void writeVmInfo(VirtualMachine vm) {
	System.out.println("Virtual Machine:" + vm.getName());
	VirtualMachineConfigInfo config = vm.getConfig();
	VirtualHardware hw = config.getHardware();
	System.out.println("Memory in MB: " + hw.getMemoryMB());
	System.out.println("# of CPUs: " + hw.getNumCPU());
	VirtualDevice[] devices = hw.getDevice();
	for (int i = 0; i < devices.length; i++) {
		VirtualDevice device = devices[i];
		Description deviceInfo = device.getDeviceInfo();
		System.out.println("Device (" + device.getKey() + "): " + deviceInfo.getLabel() + " : " + deviceInfo.getSummary());
	}
}

The virtual machine configuration information contains more than just the virtual hardware configuration:

  • Affinity settings for CPU and memory
  • Resource limits for CPU and memory
  • Datastores
  • And more…

Here the full code of our example class:

package com.benohead.esx;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import com.vmware.vim25.Description;
import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.VirtualDevice;
import com.vmware.vim25.VirtualHardware;
import com.vmware.vim25.VirtualMachineConfigInfo;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;

public class ListVms {
	static final String SERVER_NAME = "192.168.190.87";
	static final String USER_NAME = "Administrator";
	static final String PASSWORD = "xxxxxx";
	private static final String HOSTNAME = "192.168.190.34";

	public static void main(String[] args) {
		String url = "https://" + SERVER_NAME + "/sdk/vimService";
		// List host systems
		try {
			ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true);
			HostSystem host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("HostSystem", HOSTNAME);
			ManagedEntity[] managedEntities = new InventoryNavigator(host).searchManagedEntities("VirtualMachine");
			for (int i = 0; i < managedEntities.length; i++) {
				VirtualMachine vm = (VirtualMachine) managedEntities[i];
				writeVmInfo(vm);
				System.out.println();
			}
			si.getServerConnection().logout();
		} catch (InvalidProperty e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RuntimeFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void writeVmInfo(VirtualMachine vm) {
		System.out.println("Virtual Machine:" + vm.getName());
		VirtualMachineConfigInfo config = vm.getConfig();
		VirtualHardware hw = config.getHardware();
		System.out.println("Memory in MB: " + hw.getMemoryMB());
		System.out.println("# of CPUs: " + hw.getNumCPU());
		VirtualDevice[] devices = hw.getDevice();
		for (int i = 0; i < devices.length; i++) {
			VirtualDevice device = devices[i];
			Description deviceInfo = device.getDeviceInfo();
			System.out.println("Device (" + device.getKey() + "): " + deviceInfo.getLabel() + " : " + deviceInfo.getSummary());
		}
	}
}

SybaseBuddy: Version 1.3 available

The version 1.3 of SybaseBuddy can be downloaded here.

Change log:

  • Added tab Segments
  • Added tab Devices
  • Fixed sorting of columns containing integer values
  • Fixed an error in context menu for column names with capital letters
  • Stop auto-refresh on error

Please note that the new tabs (like multiple other already available tabs use columns of system tables only available in Sybase 15 and above). If run against Sybase 12.5 and lower, they will fail.