Solved

Getting System Information of server machine.... disk info. etc.

Posted on 2002-03-19
4
167 Views
Last Modified: 2010-03-31
Hi

I have a JSP utility which runs on tomcat and also has a backend Java process which utilises a MySQL DB. Now I am building some pretty large tables of data. And I want to be able to check via the web server the space available on disk, I'd also like to check other things like memory usage and system start time etc.

Now the memory usage one I can get from the system class (along with OS etc. ) however I cannot find a way to get disk info.

Any help would be grrreeaaattt

cheers

LK--<

[ I have looked at jconfig and a few others but they are not what I want/need :(  ]
0
Comment
Question by:LizardKing
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6879782
There is no standard way to get it. On windows you can use something like this:
Process p = Runtime.getRuntime().exec("cmd /c dir c:");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
String freeSpace = "";
while ((line = br.readLine()) != null) {
  if (line.indexOf("bytes free") > -1) {
    int start = line.indexOf("dir(s)") + 7;
    int end = line.indexOf("bytes free", start);
    freeSpace = line.substring(start, end).trim();
    break;
  }
}
System.out.println("Free space: " + freeSpace);
0
 

Author Comment

by:LizardKing
ID: 6882249
That is a nice way of getting the info. however theres a few flaws in that this will only work on windows and what if there are multiple hard disks or the disk is not c: it is g: etc.

Cheers

LK--<
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 25 total points
ID: 6882259
You can check the value of the system property "os.name" in order to determine the operating system:
System.getProperty("os.name");      

For unix you can use
Process p = Runtime.getRuntime().exec("df -k");
and process the command output in a different way.

I know - it is very incovenient - but unfortunately - there is no standard way to do this :(
0
 

Author Comment

by:LizardKing
ID: 6883089
I'm having a look at JConfig which I believe lets u do what I want its only $99 so its not too expensive , only thing is I cannot get it to work in my JSP :( , oh well I'll keep plugging at it

Oh you can have the points for your helpful comments

Cheers

LK--<
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 57
ejb entity bean example 2 31
Crystal Reports Licensing Questions 4 58
Setup GlassFish 4 34
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question