Solved

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

Posted on 2002-03-19
4
163 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now