(German) support for getting a set of formatted metrics
This commit is contained in:
parent
797d8a9edf
commit
9c931654d7
|
@ -172,6 +172,34 @@ JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhRemoveCounter)
|
|||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhCollectQueryDataOverSecond)
|
||||
(JNIEnv *env, jclass cur, jlong query)
|
||||
{
|
||||
HQUERY h_query = (HQUERY)query;
|
||||
PdhCollectQueryData(h_query);
|
||||
Sleep(1000);
|
||||
PdhCollectQueryData(h_query);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetFormattedValue)
|
||||
(JNIEnv *env, jclass cur, jlong counter)
|
||||
{
|
||||
HCOUNTER h_counter = (HCOUNTER)counter;
|
||||
PDH_STATUS status;
|
||||
PDH_FMT_COUNTERVALUE fmt_value;
|
||||
status = PdhGetFormattedCounterValue(h_counter,
|
||||
PDH_FMT_DOUBLE,
|
||||
(LPDWORD)NULL,
|
||||
&fmt_value);
|
||||
if (status != ERROR_SUCCESS) {
|
||||
win32_throw_exception(env, get_error_message(status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return fmt_value.doubleValue;
|
||||
}
|
||||
|
||||
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue)
|
||||
(JNIEnv *env, jclass cur, jlong query, jlong counter, jboolean fmt)
|
||||
{
|
||||
|
@ -353,6 +381,7 @@ JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetInstances)
|
|||
return array;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetKeys)
|
||||
(JNIEnv *env, jclass cur, jstring cp)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.hyperic.sigar.win32;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
@ -353,6 +355,60 @@ public class Pdh extends Win32 {
|
|||
return pdhGetObjects();
|
||||
}
|
||||
|
||||
/**
|
||||
sigar is compatible with java 1.4 (no generics there)
|
||||
**/
|
||||
public Map getFormattedValues(Collection paths) throws Win32Exception {
|
||||
if (this.hostname != null) {
|
||||
pdhConnectMachine(this.hostname);
|
||||
}
|
||||
Map res = new HashMap();
|
||||
|
||||
Map counters = new HashMap();
|
||||
/*
|
||||
* no for each loop either
|
||||
*/
|
||||
Iterator pathsIt = paths.iterator();
|
||||
while (pathsIt.hasNext()) {
|
||||
String path = (String)pathsIt.next();
|
||||
try {
|
||||
counters.put(path, new Long(pdhAddCounter(this.query, translate(path))));
|
||||
} catch ( Win32Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
if (counters.size() > 0) {
|
||||
try {
|
||||
pdhCollectQueryDataOverSecond(this.query);
|
||||
pathsIt = paths.iterator();
|
||||
while (pathsIt.hasNext()) {
|
||||
try {
|
||||
String path = (String)pathsIt.next();
|
||||
Long c = (Long)counters.get(path);
|
||||
if (c != null) {
|
||||
double val = pdhGetFormattedValue(c.longValue());
|
||||
res.put(path, new Double(val));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Iterator countersIt = counters.values().iterator();
|
||||
while (countersIt.hasNext()) {
|
||||
try {
|
||||
Long counter = (Long)countersIt.next();
|
||||
pdhRemoveCounter(counter.longValue());
|
||||
} catch (Win32Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static final native int validate(String path);
|
||||
|
||||
private static final native void pdhConnectMachine(String host)
|
||||
|
@ -383,6 +439,13 @@ public class Pdh extends Win32 {
|
|||
private static final native int pdhLookupPerfIndex(String name)
|
||||
throws Win32Exception;
|
||||
|
||||
private static final native void pdhCollectQueryDataOverSecond(long query)
|
||||
throws Win32Exception;
|
||||
|
||||
private static final native double pdhGetFormattedValue(long counter)
|
||||
throws Win32Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Main method for dumping the entire PDH
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue