Solved

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

Posted on 2002-03-19
4
166 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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
HashTable highest marks enumeration alternative 9 42
servlet example issue 6 46
type mismatch (Object[] to double[] 4 33
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…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

789 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