Skip to content

Commit

Permalink
Merge pull request hyperic#46 from hyperic/i18n
Browse files Browse the repository at this point in the history
Some metrics are missing the '/sec' suffix. This fix first tries to add
  • Loading branch information
hananaharonof committed Sep 3, 2014
2 parents 1898438 + 4fcaa22 commit b89060c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions bindings/java/src/org/hyperic/sigar/win32/Pdh.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,33 @@ public static String translate(String path)
return trans.toString();
}

private long addPdhCounter(String path, boolean format) throws Win32Exception {
long counter;
/*
* Some metrics are missing the '/sec' suffix. This flow,
* first tries to add the counter without the '/sec' and
* if fails, try again with it. If the seconds call fails,
* throw an exception.This issue must be addressed
* at the java level (and not C code), since the counter
* names must be translated before.
*/
try {
counter = pdhAddCounter(this.query, translate(path));
} catch (Win32Exception e) {
counter = pdhAddCounter(this.query, translate(path + "/sec"));
}
return counter;
}

private double getValue(String path, boolean format)
throws Win32Exception {

if (this.hostname != null) {
pdhConnectMachine(this.hostname);
}

long counter =
pdhAddCounter(this.query, translate(path));
long counter = addPdhCounter(path, format);

try {
return pdhGetValue(this.query, counter, format);
} finally {
Expand Down

0 comments on commit b89060c

Please sign in to comment.