Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-03-19
4
Medium Priority
?
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 75 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

670 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