How to measure system parameters using java?
Hi All,
I am having a client which is monitoring the system parameters as CPU,Memory, Disk using cscripts on windows and shell scripts on Linux.
These scripts are executed using exec().
Is it possible to possible using any java's built in classes?
Please help me.
Thanks in advance
Is it possible to possible using any java's built in
classes?There are no built-in Java classes to do low-level hardware/platform-specific things like inspecting the CPU, etc. Wrong tool for the job.
Similar Messages
-
How to read system eventlog using java program in windows?
How to read system eventlog using java program in windows?
is there any java class available to do this ? or any one having sample code for this?
Your friend ZoeHi,
There is no java class for reading event log in windows, so we can do one thing we can use windows system 32 VBS script to read the system log .
The output of this command can be read using java program....
we can use java exec for executing this system32 vbs script.
use the below program and pass the command "eventquery"
plz refer cscript,wscript
import java.io.*;
public class CmdExec {
public static void main(String argv[]) {
try {
String line;
Process p = Runtime.getRuntime().exec("Command");
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
input.close();
catch (Exception err) {
err.printStackTrace();
This sample program will list all the system log information....
Zoe -
How to read system evenlog using java program in windows
How to read system evenlog using java program in windows???
is there any java class available to do this ? or any one having sample code for this?
Your friend ZoeWelcome to the Sun forums.
>
How to read system evenlog using java program in windows???>
JNI. (No.)
>
is there any java class available to do this ? or any one having sample code for this?>You will generally get better help around here if you read the documentation, try some sample code and come back with a specific question (hopefully with an SSCCE included).
>
Your friend Zoe>(raised eyebrow) Thank you for sharing that with us.
Note also that one '?' denotes a question, while 2 or more generally denotes a dweeb. -
How to get system tasks using Java?
I have question about system tasks. I have to list all tasks which are working in the system. Is there any class which i useful to do that? I've tried to write shell script but it won't be working in system different than Linux. I will be grateful for any help.
In the standard Java classes, there are no such implementation. You are sort of answering the question youself, since you've made a script to do it. It is the same for all systems. To get the system information you need to talk to the system and to do that you need to know what system you are on...
Some system functions are more or less the same in all systems so they can be reached by the Systems-class. -
how to get system id using java ,also MAC address?
I think you have to use JNI and write the native calls on whatever platform(s) you need this.
-
How can i get system variable using java
Hi,
I just want to know how can i get system variables using java code.
for example i want to get the the date for today or i want to get the number of processes that's running.
Thanks alotHi,
I just want to know how can i get system variables
using java code.
for example i want to get the the date for today or i
want to get the number of processes that's running.
Thanks alotSome generic "system variables" are available though Java, usually through the System class.
Date today = new Date();
is instantiated with the current date and time.
Other system values, like environment values, should be passed to java through the command line (-D option) by setting system properties.
Finally, platform specific values like the number of processes running will have to be written in platform specific code and executed by JNI (java native interface).
Java is platform or system agnostic. Common system values, like time, are implemented. Hopefully you won't need platform specific values. -
How to invoke Default printer of my system by using java application
I need to invoke default printer of my system by using java application ? could u plz help me out with sample code?
VoodooMagic.getDefaultPrinter().print();
http://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html
Look for more at Google. -
How to change system time through java program
Hi
I want to know, how to change system time through java program.
give me a idia with example.
ThanksThere isn't any core Java API for this. Use JNI or call an external process with Runtime.exec().
~ -
How to set proxy authentication using java properties at run time
Hi All,
How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
=> Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
import java.io.*;
import java.net.*;
public class DnldURLWithoutUsingProxy {
public static void main (String[] args) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL("http://www.yahoo.com.au/index.html");
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
dis.close();
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}However, it generated the following message when run behind the firewall:
cd C:\Documents and Settings\abc\DnldURL\build\classes
java -cp . DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:315)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
I have also tried the command without much luck either:
java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
There is no problem pinging www.yahoo.com from this system.
I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
Java Control Panel - Use browser settings without success.
Thanks,
GeorgeHi All,
How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
=> Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
import java.io.*;
import java.net.*;
public class DnldURLWithoutUsingProxy {
public static void main (String[] args) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL("http://www.yahoo.com.au/index.html");
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
dis.close();
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}However, it generated the following message when run behind the firewall:
cd C:\Documents and Settings\abc\DnldURL\build\classes
java -cp . DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:315)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
I have also tried the command without much luck either:
java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
There is no problem pinging www.yahoo.com from this system.
I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
Java Control Panel - Use browser settings without success.
Thanks,
George -
Set system classpath using java program??
Hi,
I want to set the System classpath using java program. Can somebody please tell how to do this.
Prashantbut this will set the classpath for that particular JVM only.
Isn't it??? I want that of SYSTEM so that user can access that class path from any JVM instance.
Prashant -
System configuration using java
Hi friends
Can I get System configuration using java code.
If yes plz suggest how.
thanks in advance.. Anjanasome bits and pieces are available see the details in
System.getProperties():
Properties sysProps = System.getProperties();
meration en = sysProps.keys();
while ( en.hasMoreElements() )
//add the key=value pairs
Object keyObj = en.nextElement();
String key = ( String ) keyObj;
Object valueObj = sysProps.getProperty( key );
System.out.println( key + " : " +
+ valueObj.toString());
de]
just an idea??YES, and also you can do
System.getenv();but they also don't give all the info the OP was/is looking for. -
How to implement route cipher using java?
Hi guys,,,
I really got a headache solving how to implement route cipher using java lang,,i already got the concept but i really dont get how to implement it using java actually i want to make a presentation of how route cipher works using "adobe flash" but first i will implement it using java coz flash actionscripts are closer to java lang.
Hope you could post some examples or ideas...i would really appreciate it!
thank you so much...just add an action listener (either keypressed or keytyped) to the frame that you want to record. I did this in NetBeans in about 2 seconds. I can simplify it if you need. As for loging it just write the characters to a file output stream.
public class test extends javax.swing.JFrame {
/** Creates new form test */
public test() {
initComponents();
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
formKeyTyped(evt);
pack();
// </editor-fold>
private void formKeyTyped(java.awt.event.KeyEvent evt) {
System.out.println(evt.getKeyChar());
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new test().setVisible(true);
// Variables declaration - do not modify
// End of variables declaration
} -
Can i change system time using java
hi guys can i change system time using java iam doing one app in that i have to change the system time (my os is windowsXP) please tell me how to change the time
What does this have to do with Swing?
Well, there is no Java API that I'm aware of.
However you can execute any Windows command by using the Runtime class. So you should be able to invoke the Time command.
Search the Java Programming forum. There are plenty of examples on using the Runtime.exec(...) command. -
How to send mail attachments using java mail
can any one help how to create mails attachments using java mail
you can do it like this:
Message msg = new MimeMessage(session);
String fileAttachment = "c:/test.txt";
Multipart mp = new MimeMultipart();
BodyPart bp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(fileAttachment);
bp.setDataHandler(new DataHandler(fds));
bp.setFileName(fds.getName());
mp.addBodyPart(bp);
msg.setContent(mp);
... -
Stoping System Clock using Java code.
Is it possible to do so if yes then some code idea for
Stoping System Clock using Java code.
[email protected]The system clock is controlled from the BIOS, and as such, I don't think even windoze can stop it, though it can be continually reset. I don't believe that Java provides a sufficiently low level of control to set the system clock, although you could use a native method to accomplish the task.
Why would you want to do such a thing?
Maybe you are looking for
-
How can I play along with a MIDI sequence in Mainstage?
Hi folks, I have some live performances where I would like to play along with MIDI sequences. I've been using Mainstage and software instruments, but can't for the life of me figure out how do play along with MIDI sequences. There's a nice plugin (
-
Error : "Your purchase could not be complete" when gift app :(
Hello , can you fix this problem for my account . I'm gifting app for my friends but i can't complete . It show me error : "Your purchase could not be complete" .Thank for your support
-
New 13" MacBook Pro and FCP Express?
Is the new 13" MBP OK for light video editing with iMovie or FCP Express and little photo editing with Photoshop Elements? For video I use Panasonic AG-HMC40 AVCCAM HD. Thanks!
-
I just upgraded from iWeb 1.1.2 to 2.0 and when I try to publish my site - with no changes to the site from how it was before the upgrade - iWeb crashes. I've tried it multiple times, all with the same result. It seems I am not alone in experiencing
-
I am trying to update my software, but it seems to be hung up, I have tried shutting down and rebooting didn't help. I also cannot access Mail from my App tool,??