From: jrallen9 <jus...@te...> - 2010-01-01 17:31:39
|
I have a problem with how sigar is calling its native methods. I built a simple java test program which made method calls to gather stats on a Windows XP x86 computer. Using a Sigar object I was able to make method calls to CpuPerc, Mem, Filesystem and DiskUsage and display these results to a console. Since I'm using eclipse to develop this program all I had to do was add the sigar.jar to my class path and both java was able to load the jar, and sigar was able to load the sigar-winnt-x86.dll (which was in its default lib directory as sigar.jar). Fast Forward to integrating this code into a production project. Since adding this sigar code to a production project I'm building, I'm faced with a problem where the program calls native methods for CpuPerc.gather(), Mem.gather(), and FileSystem.gather(), just fine with out exceptions, but when calling DiskUsage.gather(), I get a SigarFileNotFoundException indicating the program can't find the native method for the DiskUsage.gather() to return with valid data. This error really confuses me, because when I don't include the path to the lib directory where sigar-winnt-x86.dll resides, every method which uses the sigar API will fail at the point it requires the native code. However when I do include the lib directory for sigar-winnt-x86.dll, all of the above objects are able to find the native code except for the DiskUsage object. The reason I mentioned the test program is because both the test program and the production program reference the same sigar.jar, and the sigar-winnt-x86.dll locations and files. The production program uses multiple threads, but only one thread is responsible for executing code using sigar API objects. In trying to troubleshoot this problem I've been sifting through the source distro of the sigar download and found win32_sigar.c and a C function : SIGAR_DECLARE(int) sigar_disk_usage_get(sigar_t *sigar, const char *dirname, sigar_disk_usage_t *disk) Is this function the native function which DiskUsage.fetch() calls into? Is win32_sigar.c included in the sigar-winnt-x86.dll? Any help trying to resolve this problem would be very much appreciated. Feel free to email me if you need additional stack trace, configuration questions, or have other probative questions. My email is justin (dot) allen (at) teradata (dot) com |
From: Doug M. <do...@hy...> - 2010-01-05 01:02:50
|
Hi Justin, This doesn't sound like a linkage issue, SigarFileNotFoundException will be thrown by this method if the disk name is invalid. For example: java -jar sigar.jar iostat g:\ g:\ No such file or directory dir g:\ The system cannot find the path specified. |
From: jrallen9 <jus...@te...> - 2010-01-08 18:57:54
|
I was able to correct the problem I described in this thread. I should have added a try/catch block for SigarFileNotFoundException as this code shows: FileSystem[] devices = session.getFileSystemList(); for (FileSystem dev : devices){ try{ switch(dev.getType()){ case FileSystem.TYPE_LOCAL_DISK: DiskUsage disk = session.getDiskUsage(dev.getDirName()); log.debug("DiskUsage for " + dev.getDirName() + " = " + disk.toString()); // do more stuff with the disk object break; case FileSystem.TYPE_CDROM: //Do nothing with CD-ROMS and Removable Disks break; case FileSystem.TYPE_NETWORK: //Ignore Network Shares at this time. break; default: break; } }catch(SigarFileNotFoundException e) { log.debug(dev.getDirName() + "...\n " + e.getMessage()); } As this code shows, getting a FileSystem list of mapped drive letter devices available on the system is useful for accessing DiskUsage information, but has the a problem in that not all devices are accessible even though its mapped by NTFS to a drive letter. To correct this I moved the problematic code under a case statement where the FileSystem type is a local disk (this was the only type I cared about). I also added the try/catch to log the error and continue on with execution. @Doug - I think the documentation under Sigar.getDiskUsage( String name) should be clarified to provide better descriptions on when SigarFileNotFoundExceptions are thrown. There must be a better way to indicate when a mapped drive letter is accessible for statistic collections. Perhaps at least the documentation should specify an approach to testing for stats accessibility prior to making calls to stats collections. I just want to add a thank you for the hard work which has gone into developing SIGAR. It's a great utility tool and has made Windows performance monitoring accessible for developers. I've looked at the WindowsAPI and its a beast, but the dlls provided have made a great interface for Java program development. |
From: Doug M. <do...@hy...> - 2010-01-13 19:44:33
|
Hi Justin, Glad you were able to sort out the problem. I've opened a ticket to document the exceptions: http://jira.hyperic.com/browse/SIGAR-197 and should get that done before the next release. Great to hear you've found sigar useful and easy to use. Keep the feedback coming, helps us continue to improve! |
From: Dave <sig...@hy...> - 2010-01-27 05:11:56
|
Justin, Any chance you could upload your test program? This would be a great resource for those of us getting started with SIGAR. Dave |
From: Doug M. <do...@hy...> - 2010-02-02 22:53:47
|
The shell command sources should also be helpful: http://github.com/hyperic/sigar/tree/master/bindings/java/src/org/hyperic/sigar/cmd/ |
From: Dave <sig...@hy...> - 2010-02-03 22:35:26
|
Doug - thanks for this great resource. It goes a long way to explaining the 'guts'. Dave |