I'm using vijava (5.1) to fetch data from a vCenter about virtual machines.
For that matter I'm using a filter with some properties (for example, guest.hostName, runtime.powerState etc.).
I need to get the creation time for these virtual machines and from what I saw, this info is available in the event logs of the vCenter.
Is there a way to get this info part of the virtual machine's properties?
I searched this info using the vSphere-Client and I didn't - so I guess the only place is from the event logs - but just to be sure, is that the only way?
Thanks
It is hard to get creation time of virtual machine using vijava api. However you can get other below informations from VirtualMachineConfigInfo.
changeVersion : The changeVersion is a unique identifier for a given version of the configuration. Each change to the configuration updates this value. This is typically implemented as an ever increasing count or a time-stamp. However, a client should always treat this as an opaque string.
modified : Last time a virtual machine's configuration was modified.
Folder rootFolder = serviceInstance.getRootFolder();
InventoryNavigator inventoryNavigator = new InventoryNavigator(rootFolder);
vm = (VirtualMachine) inventoryNavigator.searchManagedEntity(VirtualMachine.class.getSimpleName(), vmName);
VirtualMachineConfigInfo vmConfig = vm.getConfig();
System.out.println(vmConfig.getChangeVersion);
image for information in virtualMachineConfigInfo object
Unless you set the creation time as an extra config property then the event log is the only way I know of. If you want to go the extra config route I created a sample that shows how to use them that is part of the pyvmomi-community-samples project.
Related
I'm trying to access a GigE camera using the Genicam reference implementation by trying to look at the online resources and existing existing resources (aravis, harvesters) and follow the GenTL standard using the SNFC which every Genicam compatible camera supports. The producer I'm currently using is from Basler since the camera I have here is from them.
/* I wrapped the Genicam classes with my own. Here are the relevant parts */
tl = new GenicamTransportlayer("/opt/pylon/lib/gentlproducer/gtl/ProducerGEV.cti");
if0 = tl.getFirstInterface();
dev0 = if0.getFirstDevice();
ds = dev0.getFirstDataStream();
I'm able to connect to the System, Interface, Device, DataStream, connect the nodemaps and am now trying to set up the buffers for acquisition. To do so I need to get the maximum payload size from the camera. The GenTL standard document standard says, I need to query it from the DataStream module using
boolean definesPayloadSize = ds.getInfoBool8(StreamInfoCommand.STREAM_INFO_DEFINES_PAYLOADSIZE);
which gives me 0 or false. The producer MAY provide a PayloadSize feature which can be queried using
ds.getInfoSizet(StreamInfoCommand.STREAM_INFO_PAYLOAD_SIZE);
which is obviously also 0 and with being a may I cannot rely on it. The standard further tells me if both fail, I need to inquire via the remote devices NodeMap to read the PayloadSize:
long payloadSizeFromRemoteMap = dev0.remoteMap.getIntegerNode("PayloadSize").getValue();
This gives me 0 too. The standard goes on that if the producer does not implement an interface standard (whatever this means?), the required payload size has to be queried via the producer using the StreamInfo Commands which also fails (GenTL maps the constant STREAM_INFO_PAYLOAD_SIZE to 7 which produces a BufferTooSmallException on the System port).
At this point I'm confused on what to do. Most of my nodes are locked (I can overwrite TLParamsLocked but still cannot change parameters, eg, execute a load of the default parameter set) so I cannot set Width/Height/ImageFormat to infer the PayloadSize:
/* Trying to set a default configuration fails */
IEnumeration userSetSelector = dev0.remoteMap.getEnumerationNode("UserSetSelector");
log.debug("Loading Feature set: " + userSetSelector.getEntries().get(0).getName());
// Prints: Loading Feature set: EnumEntry_UserSetSelector_Default
userSetSelector.setValue("Default");
dev0.remoteMap.getCommandNode("UserSetLoad").execute();
// AccessException: Node is not writable. : AccessException thrown in node 'UserSetLoad' while calling 'UserSetLoad.Execute()' - Node is not writable.
Without knowing the size of the buffers I cannot continue. How can I infer the PayloadSize to set them up?
I have a JMeter test that insert an input via an HTTP call to an asynchronous java-service and then collects an exposed metric on another java-service via a groovy script.
The script then saves the collected metric as a JMeter variable to be reviewed as a performance metric.
I would like to publish this value inside the JMeter -generated dashboard but I can't find a way to save this variable as a JMeter output.
Is there a way? seems JMeter is primarily aimed to test HTTP synchronous services but it's capable of doing such collection of data.
You can use variable(s) in custom graph definitions:
You can graph any sample_variable in CSV over time, you can customize your graphs by settings their properties in the user.properties file.
They must use the id prefix custom_:
jmeter.reportgenerator.graph.custom_<your_graph_name_id>.property.<your_option_name>
To specify that this graph is a customized one :
jmeter.reportgenerator.graph.custom_<your_graph_name_id>.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
Here is an example of a custom graph configuration that graphs the variable ts-hit:
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Chunk Hit
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Number of Hits
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=ts-hit
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Number of Hits :
Declare the JMeter Variable you're saving in the JSR223 script as a Sample Variable, in order to do this add the next line to user.properties file:
sample_variables=foo
Then you can configure your custom chart like:
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Your custom chart title
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Your Y axis name
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=foo
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Your custom content message
replace foo with the actual JMeter Variable name of your choice and next time you generate HTML reporting dashboard you should see your variable values plotted over time
More information:
Reporting configuration
Apache JMeter Properties Customization Guide
I want to change the logging level depending if I'm debbugging or not, but I can't find a code snippet to check if the application is running in debug mode.
I'm using eclipse to debug the application, so if the solution only works within Eclipse it will be fine.
Found the answer on how-to-find-out-if-debug-mode-is-enabled
boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().
getInputArguments().toString().contains("-agentlib:jdwp");
This will check if the Java Debug Wire Protocol agent is used.
You could modify the Debug Configuration. For example add a special VM argument only in the Debug Configuration. You can use System.getProperties() to read the supplied arguments.
Even better, modify the configurations (Run and Debug) to load a different logging configuration file. It isn't good if you need to write code to determine the logging level. This should only be a matter of configuration.
There is not an officially sanctioned way to reliably determine if any given JVM is in debug mode from inside the JVM itself, and relying on artifacts will just break your code some time in the future.
You will therefore need to introduce a methology yourself. Suggestions:
A system property.
An environment variable (shell variable like $HOME or %HOME%)
Ask the JVM about the physical location of a given resource - http://www.exampledepot.com/egs/java.lang/ClassOrigin.html - and based on it, make your decision (does the path contain the word "debug"? is it inside a jar or an unpacked class file? etc).
JNDI
The existance or content of a particular resource.
Have you tried add a vm argument in the eclipse run config?
Pass this as a VM Argument
-Ddebug=true
then you can do Boolean.getBoolean("debug") to check this.
If you are setting the debug level from your own program, may be a line like:
public static final boolean DEBUG_MODE = System.getProperty("java.vm.info", "").contains("sharing");
would do the trick.
Just tested it in eclipse3.5:
package test;
public class Test
{
/**
* #param args
*/
public static void main(String[] args)
{
System.out.println(System.getProperty("java.vm.info", ""));
}
}
will display:
mixed mode, sharing
if launched without debug
mixed mode
if executed with debug launcher
Joachim Sauer comments:
This is highly system depending.
I assume the "sharing" indicates that cross-VM class-sharing is active.
This is a very new feature and is only available on some platforms.
Furthermore there can be many possible reasons to en- or disable it, so I wouldn't use this for debug-mode detection.
(Note: I tested it with the latest jdk1.6b14. I leave this as a CW answer.)
Have a look here:
http://wiki.eclipse.org/FAQ_How_do_I_use_the_platform_debug_tracing_facility%3F
Moreover, I think you can't know if your app is run in debug mode. The only thing you can do is to pass an argument to your JVM when you debug.
Manu
If using socket (e.g. 9999) you can call netstat to check if connection was established:
Process p = new ProcessBuilder("netstat", "-n").start();
String stdout = IOUtils.toString(p.getInputStream(), Charset.defaultCharset());
Then scan in stdout for 127.0.0.1:9999.*ESTABLISHED
I have an application which uses neo4j embedded database. Now, I want to migrate to neo4j server as I need to integrate this application with a web app (using servlets, tomcat).
I want to change the code minimally, So I thought of using java-rest-binding api of neo4j. But I am stuck at getting the auto node index. The method getAutoNodeIndexer doesn't return. In messages.log of the database, It shows
[o.n.k.EmbeddedGraphDatabase]: GC Monitor: Application threads blocked for an additional 254ms [total block time: 2.678s]
I have no idea how to solve this.
I have set the appropriate properties in the neo4j.properties, which are
node_auto_indexing=true
node_keys_indexable=primaryKey
relationship_auto_indexing=true
relationship_keys_indexable=X-->Y
And this is what my code looks like:
graphDb = new RestGraphDatabase("http://localhost:7474/db/data/");
ReadableIndex<Node> autoNodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex();
ReadableRelationshipIndex autoRelIndex = graphDb.index().getRelationshipAutoIndexer().getAutoIndex();
It seems that there's a lot of garbage collection going on. Run your app with a bigger heap (e.g. -Xmx1g) and see what happens.
EDIT:
Also, relationship_keys_indexable=X-->Y seems strange. I'd expect a property name there. What happens if you remove this property or enter a valid value?
To state the official documentation:
The node_keys_indexable key allows you to specify a comma-separated
list of node property keys to be indexed. The
relationship_keys_indexable does the same for relationship property
keys.
I've seen plenty of examples of how to prevent Java applications, such as locking a file or creating a socket.
How do I allow multiple instances to run, but check if another one is running?
The reason I need to do this is that I want to clean a temporary folder on exit, but not if there is another process running.
You can use attach API and check for running virtual machines like explained in this blog entry
The other manner of acquiring a VirtualMachine is to ask for the list of virtual machines known to the system, and then pick the specific one you are interested in, typically by name:
String name = ...
List vms = VirtualMachine.list();
for (VirtualMachineDescriptor vmd: vms) {
if (vmd.displayName().equals(name)) {
VirtualMachine vm = VirtualMachine.attach(vmd.id());
String agent = ...
vm.loadAgent(agent);
// ...
}
}
You can use any IPC you like. For example, create /tmp/you_app_name_flag.$$ files ( $$ means pid ) and verify existance of /tmp/you_app_name_flag.* on your app's start.