mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-02 09:47:00 +03:00
Initial commit for VMWare drivers: the Information Manager.
git-svn-id: http://svn.opennebula.org/one/trunk@444 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
1e63cb63c1
commit
866b2544a9
284
src/im_mad/vmware/GetProperty.java
Normal file
284
src/im_mad/vmware/GetProperty.java
Normal file
@ -0,0 +1,284 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad */
|
||||
/* Complutense de Madrid (dsa-research.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
import com.vmware.vim.*;
|
||||
import com.vmware.apputils.*;
|
||||
import com.vmware.apputils.vim.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
import java.lang.*;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
|
||||
/*
|
||||
* Used to obtain properties from Managed Object Reference from ESXi
|
||||
*/
|
||||
|
||||
public class GetProperty
|
||||
{
|
||||
// Helpers from VI samples
|
||||
private static ServiceContent content;
|
||||
private static AppUtil cb = null;
|
||||
private static VimPortType service;
|
||||
private ManagedObjectReference moRef;
|
||||
|
||||
// Measure of the property
|
||||
private double measure;
|
||||
|
||||
/*
|
||||
* Gets first property that matches propertyName
|
||||
* @param moRef, objet to get property from
|
||||
* @param propertyName, name of the property
|
||||
* @return representation of the property
|
||||
*/
|
||||
Object getObjectProperty(String propertyName)
|
||||
throws RuntimeFault, RemoteException
|
||||
{
|
||||
return getProperties(new String[] { propertyName })[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets properties that matches any of the strings
|
||||
* @param moRef, objet to get properties from
|
||||
* @param propertyName, name of the property
|
||||
* @return representation of the properties
|
||||
*/
|
||||
Object[] getProperties(String[] properties)
|
||||
throws RuntimeFault, RemoteException
|
||||
{
|
||||
// PropertySpec specifies what properties to
|
||||
// retrieve and from type of Managed Object
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType(moRef.getType());
|
||||
pSpec.setPathSet(properties);
|
||||
|
||||
// ObjectSpec specifies the starting object and
|
||||
// any TraversalSpecs used to specify other objects
|
||||
// for consideration
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(moRef);
|
||||
|
||||
// PropertyFilterSpec is used to hold the ObjectSpec and
|
||||
// PropertySpec for the call
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] {pSpec});
|
||||
pfSpec.setObjectSet(new ObjectSpec[] {oSpec});
|
||||
|
||||
// retrieveProperties() returns the properties
|
||||
// selected from the PropertyFilterSpec
|
||||
ObjectContent[] ocs = service.retrieveProperties(
|
||||
content.getPropertyCollector(),
|
||||
new PropertyFilterSpec[] {pfSpec});
|
||||
|
||||
// Return value, one object for each property specified
|
||||
Object[] ret = new Object[properties.length];
|
||||
|
||||
if(ocs != null)
|
||||
{
|
||||
for(int i=0; i<ocs.length; ++i)
|
||||
{
|
||||
ObjectContent oc = ocs[i];
|
||||
DynamicProperty[] dps = oc.getPropSet();
|
||||
if(dps != null)
|
||||
{
|
||||
for(int j=0; j<dps.length; ++j)
|
||||
{
|
||||
DynamicProperty dp = dps[j];
|
||||
// find property path index
|
||||
for(int p=0; p<ret.length; ++p)
|
||||
{
|
||||
if(properties[p].equals(dp.getName()))
|
||||
{
|
||||
ret[p] = dp.getVal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets performance counter from a MOB (ManagedObjectReference). Sets measure to
|
||||
* be retrieved using getMeasure
|
||||
* @param mor, ManagedObjectReference
|
||||
* @param counter, name of the performance counter
|
||||
* @return representation of the properties
|
||||
*/
|
||||
|
||||
public boolean getPerformanceCounter(String counter,
|
||||
int intervalInt) throws Exception
|
||||
{
|
||||
|
||||
int counterID;
|
||||
int key;
|
||||
String group;
|
||||
String name;
|
||||
String rollup;
|
||||
|
||||
// Get the Performance Manager
|
||||
ManagedObjectReference pmRef
|
||||
= cb.getConnection().getServiceContent().getPerfManager();
|
||||
// Get supported perf counters in the system
|
||||
PerfCounterInfo[] cInfo
|
||||
= (PerfCounterInfo[])cb.getServiceUtil().getDynamicProperty(pmRef,
|
||||
"perfCounter");
|
||||
// Create a hashmap for these counters
|
||||
TreeMap PerfByID = new TreeMap();
|
||||
TreeMap PerfByName = new TreeMap();
|
||||
|
||||
for (int i = 0; i < cInfo.length; i++)
|
||||
{
|
||||
key = cInfo[i].getKey();
|
||||
group = cInfo[i].getGroupInfo().getKey();
|
||||
name = cInfo[i].getNameInfo().getKey();
|
||||
rollup = cInfo[i].getRollupType().toString();
|
||||
|
||||
PerfByID.put (key, group + "." + name + "." + rollup);
|
||||
PerfByName.put(group + "." + name + "." + rollup, key);
|
||||
}
|
||||
|
||||
Integer origCounterId = (Integer)PerfByName.get(counter);
|
||||
PerfProviderSummary perfSum
|
||||
= cb.getConnection().getService().queryPerfProviderSummary(pmRef, moRef);
|
||||
|
||||
Integer interval = perfSum.getRefreshRate();
|
||||
|
||||
// Get available Performance metrics for the entity
|
||||
PerfMetricId[] Ids =
|
||||
cb.getConnection().getService().queryAvailablePerfMetric(pmRef,
|
||||
moRef, null, null, interval);
|
||||
boolean idExists = false;
|
||||
PerfMetricId[] metricId = null;
|
||||
if (Ids != null)
|
||||
{
|
||||
|
||||
for (int j = 0; j < Ids.length; j++)
|
||||
{
|
||||
// Check if the counter exists for the entity
|
||||
if (Ids[j].getCounterId() == origCounterId)
|
||||
{
|
||||
idExists = true;
|
||||
metricId = new PerfMetricId[]{Ids[j]};
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idExists)
|
||||
{
|
||||
Integer Intv = new Integer(intervalInt);
|
||||
|
||||
PerfQuerySpec qSpec = new PerfQuerySpec();
|
||||
qSpec.setEntity(moRef);
|
||||
qSpec.setMetricId(metricId);
|
||||
qSpec.setFormat("normal");
|
||||
qSpec.setIntervalId(interval);
|
||||
qSpec.setMaxSample(1);
|
||||
|
||||
PerfQuerySpec[] qSpecs = new PerfQuerySpec[] {qSpec};
|
||||
|
||||
if (moRef != null)
|
||||
{
|
||||
PerfEntityMetricBase[] pEntity = getPerfIdsAvailable(qSpecs, pmRef);
|
||||
|
||||
if (pEntity != null)
|
||||
{
|
||||
for (int i = 0; i < pEntity.length; i++)
|
||||
{
|
||||
|
||||
PerfMetricSeries[] vals = ((PerfEntityMetric)pEntity[i]).getValue();
|
||||
PerfSampleInfo[] infos = ((PerfEntityMetric)pEntity[i]).getSampleInfo();
|
||||
if (vals != null)
|
||||
{
|
||||
for (int vi=0; vi<vals.length; ++vi)
|
||||
{
|
||||
counterID = vals[vi].getId().getCounterId();
|
||||
|
||||
if(vals[vi] instanceof PerfMetricIntSeries)
|
||||
{
|
||||
PerfMetricIntSeries val = (PerfMetricIntSeries)vals[vi];
|
||||
long[] longs = val.getValue();
|
||||
if (longs !=null && longs.length>=1)
|
||||
{
|
||||
measure = longs[(longs.length-1)];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private PerfEntityMetricBase[] getPerfIdsAvailable(PerfQuerySpec[] querySpecs,
|
||||
ManagedObjectReference entityMoRef) throws Exception
|
||||
{
|
||||
PerfEntityMetricBase[] perfEntity = null;
|
||||
|
||||
if (entityMoRef != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
perfEntity
|
||||
= cb.getConnection().getService().queryPerf(entityMoRef, querySpecs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return perfEntity;
|
||||
}
|
||||
|
||||
public double getMeasure()
|
||||
{
|
||||
return measure;
|
||||
}
|
||||
|
||||
GetProperty(String[] args, String entity, String entityName) throws Exception
|
||||
{
|
||||
cb = AppUtil.initialize("GetProperty", null, args);
|
||||
cb.connect();
|
||||
|
||||
|
||||
moRef = cb.getServiceUtil().getDecendentMoRef(null,entity,
|
||||
entityName);
|
||||
|
||||
|
||||
com.vmware.apputils.vim.ServiceConnection sc = cb.getConnection();
|
||||
content = sc.getServiceContent();
|
||||
service = sc.getService();
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
cb.disConnect();
|
||||
}
|
||||
}
|
229
src/im_mad/vmware/OneImVmware.java
Normal file
229
src/im_mad/vmware/OneImVmware.java
Normal file
@ -0,0 +1,229 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad */
|
||||
/* Complutense de Madrid (dsa-research.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import com.vmware.vim.*;
|
||||
import com.vmware.apputils.*;
|
||||
import com.vmware.apputils.vim.*;
|
||||
|
||||
|
||||
|
||||
class OneImVmware extends Thread
|
||||
{
|
||||
|
||||
private String[] arguments;
|
||||
|
||||
// Entry point - main procedure
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// first, make redirection
|
||||
|
||||
PrintStream stdout = System.out;
|
||||
PrintStream stderr = System.err;
|
||||
|
||||
System.setOut(stderr);
|
||||
System.setErr(stdout);
|
||||
OneImVmware oiv = new OneImVmware(args);
|
||||
oiv.loop();
|
||||
}
|
||||
|
||||
// Constructor
|
||||
OneImVmware(String[] args)
|
||||
{
|
||||
arguments = args;
|
||||
}
|
||||
|
||||
|
||||
// Main loop, threaded
|
||||
void loop()
|
||||
{
|
||||
String str = null;
|
||||
String action = null;
|
||||
String host;
|
||||
String hid_str = null;
|
||||
String hostToMonitor;
|
||||
boolean fin = false;
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
while (!fin)
|
||||
{
|
||||
// Read a line a parse it
|
||||
try
|
||||
{
|
||||
str = in.readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
String message = e.getMessage().replace('\n', ' ');
|
||||
|
||||
synchronized (System.err)
|
||||
{
|
||||
System.err.println(action + " FAILURE " + hid_str + " " + message);
|
||||
}
|
||||
}
|
||||
|
||||
String str_split[] = str.split(" ", 4);
|
||||
|
||||
action = str_split[0].toUpperCase();
|
||||
|
||||
// Perform the action
|
||||
if (action.equals("INIT"))
|
||||
{
|
||||
init();
|
||||
}
|
||||
else if (action.equals("FINALIZE"))
|
||||
{
|
||||
finalize_mad();
|
||||
fin = true;
|
||||
} else if (str_split.length != 3)
|
||||
{
|
||||
synchronized (System.err)
|
||||
{
|
||||
System.err.println("FAILURE Unknown command");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
action = str_split[0].toUpperCase();
|
||||
hid_str = str_split[1];
|
||||
hostToMonitor = str_split[2];
|
||||
|
||||
// Perform the action
|
||||
if (action.equals("INIT"))
|
||||
init();
|
||||
else if (action.equals("FINALIZE"))
|
||||
{
|
||||
finalize_mad();
|
||||
fin = true;
|
||||
}
|
||||
else if (action.equals("MONITOR"))
|
||||
{
|
||||
// Let's gather data from the host
|
||||
|
||||
GetProperty gP;
|
||||
boolean rf;
|
||||
String response = "";
|
||||
|
||||
try
|
||||
{
|
||||
String[] argsWithHost = new String[arguments.length+2];
|
||||
|
||||
for(int i=0;i<arguments.length;i++)
|
||||
{
|
||||
argsWithHost[i] = arguments[i];
|
||||
}
|
||||
|
||||
argsWithHost[arguments.length] = "--url";
|
||||
argsWithHost[arguments.length + 1 ] = "https://" + hostToMonitor + ":443/sdk";
|
||||
gP = new GetProperty(argsWithHost, "HostSystem", hostToMonitor);
|
||||
|
||||
// Now it's time to build the response gathering the properties needed
|
||||
|
||||
// Static Information
|
||||
|
||||
int totalMemory =
|
||||
Integer.parseInt(gP.getObjectProperty("hardware.memorySize").toString().trim());
|
||||
totalMemory /= 1024;
|
||||
|
||||
response = response + "TOTALMEMORY=" + totalMemory;
|
||||
|
||||
int numCpus =
|
||||
Integer.parseInt(gP.getObjectProperty("hardware.cpuInfo.numCpuCores").
|
||||
toString().trim());
|
||||
numCpus *= 100;
|
||||
response = response + " TOTALCPU=" + numCpus;
|
||||
|
||||
response = response + " MODELNAME=\""
|
||||
+ gP.getObjectProperty("hardware.systemInfo.model")
|
||||
+ "\"";
|
||||
|
||||
double cpuSpeed =
|
||||
Double.parseDouble(gP.getObjectProperty("hardware.cpuInfo.hz").toString().trim());
|
||||
// From hz to Mhz
|
||||
cpuSpeed/=1000000;
|
||||
|
||||
response = response + " CPUSPEED=" + (int)cpuSpeed;
|
||||
|
||||
|
||||
// Dynamic Information
|
||||
// CPU
|
||||
rf = gP.getPerformanceCounter("cpu.usage.average", 60);
|
||||
if (!rf) throw new Exception();
|
||||
// Convert from 1/10000 to 1/100
|
||||
int usedCpu = (int)(gP.getMeasure()/100);
|
||||
response = response + " USEDCPU="+usedCpu;
|
||||
|
||||
response = response + " FREECPU="+(100-usedCpu);
|
||||
|
||||
// MEM
|
||||
rf = gP.getPerformanceCounter("mem.usage.average", 60);
|
||||
if (!rf) throw new Exception();
|
||||
// Convert from percentage to actual value
|
||||
int usedMemory = (int)(totalMemory * (gP.getMeasure()/100))/100;
|
||||
response = response + " USEDMEMORY=" + usedMemory;
|
||||
|
||||
response = response + " FREEMEMORY=" + (totalMemory-usedMemory);
|
||||
|
||||
// NET
|
||||
rf = gP.getPerformanceCounter("net.transmitted.average", 60);
|
||||
if (!rf) throw new Exception();
|
||||
response = response + " NETTX=" + (int)gP.getMeasure();
|
||||
|
||||
rf = gP.getPerformanceCounter("net.received.average", 60);
|
||||
if (!rf) throw new Exception();
|
||||
response = response + " NETRX=" + (int)gP.getMeasure();
|
||||
|
||||
// Send the actual response
|
||||
System.err.println("MONITOR SUCCESS " + hid_str + " " + response);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Failed monitoring host " + hostToMonitor);
|
||||
e.printStackTrace();
|
||||
|
||||
System.err.println("MONITOR FAILURE " + hid_str + " Failed monitoring host " +
|
||||
hostToMonitor + ". Please check the VM log.");
|
||||
} // catch
|
||||
} // if (action.equals("MONITOR"))
|
||||
} // else if (str_split.length != 4)
|
||||
} // while(!fin)
|
||||
} // loop
|
||||
|
||||
void init()
|
||||
{
|
||||
// Nothing to do here
|
||||
synchronized(System.err)
|
||||
{
|
||||
System.err.println("INIT SUCCESS");
|
||||
}
|
||||
}
|
||||
|
||||
void finalize_mad()
|
||||
{
|
||||
// Nothing to do here
|
||||
synchronized(System.err)
|
||||
{
|
||||
System.err.println("FINALIZE SUCCESS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
0
src/im_mad/vmware/im_vmware.conf
Normal file
0
src/im_mad/vmware/im_vmware.conf
Normal file
23
src/im_mad/vmware/im_vmwarerc
Normal file
23
src/im_mad/vmware/im_vmwarerc
Normal file
@ -0,0 +1,23 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#VMWARE_TRUSTORE=<path_to_keystore>
|
||||
|
||||
# Uncomment the following line to active MAD debug
|
||||
#ONE_MAD_DEBUG=1
|
||||
|
||||
VMWARE_TRUSTORE=/home/tinova/.vmware-certs/vmware.keystore
|
60
src/im_mad/vmware/one_im_vmware
Normal file
60
src/im_mad/vmware/one_im_vmware
Normal file
@ -0,0 +1,60 @@
|
||||
#!/bin/bash -xv
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
#Setup driver variables
|
||||
DRIVER_NAME="one_im_vmware"
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
DRIVERRC=/etc/one/${DRIVER_NAME}/${DRIVER_NAME}rc
|
||||
MADCOMMON=/usr/lib/one/mads/madcommon.sh
|
||||
else
|
||||
DRIVERRC=$ONE_LOCATION/etc/${DRIVER_NAME}/${DRIVER_NAME}rc
|
||||
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
|
||||
fi
|
||||
|
||||
. $MADCOMMON
|
||||
|
||||
echo $DRIVERRC
|
||||
|
||||
# Export the im_mad specific rc
|
||||
|
||||
export_rc_vars $DRIVERRC
|
||||
|
||||
echo $VMWARE_TRUSTORE
|
||||
|
||||
LOG_FILE=$DRIVER_NAME
|
||||
|
||||
MAD_FILE="OneImVmware"
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
MAD_LOG_PATH=/var/log/one/$LOG_FILE.log
|
||||
else
|
||||
MAD_LOG_PATH=$ONE_LOCATION/var/$LOG_FILE.log
|
||||
fi
|
||||
|
||||
# Execute the actual MAD
|
||||
if [ -n "${ONE_MAD_DEBUG}" ]; then
|
||||
exec nice -n $PRIORITY java -cp .:$CLASSPATH -Djavax.net.ssl.trustStore=$VMWARE_TRUSTORE -Xmx1024M $MAD_FILE $* 2>> $MAD_LOG_PATH
|
||||
else
|
||||
exec nice -n $PRIORITY java -cp .:$CLASSPATH -Djavax.net.ssl.trustStore=$VMWARE_TRUSTORE -Xmx1024M $MAD_FILE $* 2> /dev/null
|
||||
fi
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user