Some metrics are missing the '/sec' suffix. This fix first tries to add
the counter without the '/sec' and if fails, try again with it. If the second 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 to support i18n native OS locals. Please also note, the C code (at Pdh.c), tries to do the same, but at this level we cannot use the translation mechanism the Java level offers, hence this fix won't handle non-English i18n locals.
This commit is contained in:
		
							parent
							
								
									f12b8e32d3
								
							
						
					
					
						commit
						494ed4ed3e
					
				@ -286,6 +286,24 @@ public class Pdh extends Win32 {
 | 
				
			|||||||
        return trans.toString();
 | 
					        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)
 | 
					    private double getValue(String path, boolean format)
 | 
				
			||||||
        throws Win32Exception {
 | 
					        throws Win32Exception {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -293,8 +311,8 @@ public class Pdh extends Win32 {
 | 
				
			|||||||
            pdhConnectMachine(this.hostname);
 | 
					            pdhConnectMachine(this.hostname);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        long counter =
 | 
					        long counter = addPdhCounter(path, format);
 | 
				
			||||||
            pdhAddCounter(this.query, translate(path));
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return pdhGetValue(this.query, counter, format);
 | 
					            return pdhGetValue(this.query, counter, format);
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user