Echando código: ¿Monitoreando servicios RPC usando Java, ONC RPC y el protocolo Jabber? (I)
Publicado por josevnz 21 Junio 2006 en General, How To's, Humor, J2EE, Java, Software Libre / Abierto.
Un dialogo tipico en NYC, Times Square
Si la vida te da limones, entonces haz limonada. No siempre tenemos SNMP para monitorear nuestros servidores, pero por otro lado muchas veces nos dejan usar NFS y Rstatd. Por ejemplo, mire las pruebas de Junit que escribí para jugar con esos servicios:
JAVA:
-
package com.kodegeek.blog.monitoring.rpc;
-
-
import java.net.InetAddress;
-
import java.util.ResourceBundle;
-
-
import junit.framework.Assert;
-
import junit.framework.TestCase;
-
-
import org.acplt.oncrpc.OncRpcClientAuthUnix;
-
import org.acplt.oncrpc.OncRpcProtocols;
-
-
public class TestRpcStubs extends TestCase {
-
-
/**
-
* Default max timeout value, in miliseconds
-
*/
-
public static final int MAX_TIMEOUT = 1000*60;
-
-
-
{
-
}
-
-
super.setUp();
-
}
-
-
/**
-
* Simple test for the NFS client, using the generated RPC stubs directly
-
*
-
*/
-
public void testNfs() {
-
MountClient mount = null;
-
exports exportsList = null;
-
fhstatus fhStatus = null;
-
OncRpcClientAuthUnix authUnix = null;
-
try {
-
authUnix = new OncRpcClientAuthUnix(
-
);
-
Assert.assertNotNull("Auth Unix is null", authUnix);
-
// Get the list of exported directories
-
mount = new MountClient(
-
OncRpcProtocols.ONCRPC_TCP);
-
Assert.assertNotNull("Mount is null", mount);
-
exportsList = mount.MOUNTPROC_EXPORT_1();
-
Assert.assertNotNull("Export list is null", exportsList);
-
exportnode node = exportsList.value;
-
Assert.assertNotNull("No nodes are being exported", node);
-
while (node != null) {
-
nodeForm[0] = node.ex_dir.value;
-
NFS_BUNDLE.getString("NfsPing.msg.exportedFs"), nodeForm
-
);
-
-
mount.getClient().setAuth(authUnix);
-
mount.getClient().setTimeout(MAX_TIMEOUT);
-
-
if (fhStatus == null) {
-
}
-
// Get the next node
-
node = node.ex_next.value;
-
}
-
Assert.fail("Got an exception: " + throwbl.toString());
-
throwbl.printStackTrace();
-
} finally {
-
// Empty for now
-
}
-
}
-
-
/**
-
* Simple test for Rstat, using the generated RPC stubs directly
-
* Timestamps are separated into seconds (standard UNIX time) and
-
* microseconds. The availability of a current timestamp allows proper
-
* calculation of the interval between measurements without worrying
-
* about network latency.
-
*
-
* Most values are counters. To get the real numbers you have to
-
* fetch() samples regularly and divide the counter increments
-
* by the time interval between the samples.
-
*
-
* The cpu_time array holds the ticks spent in the various CPU states
-
* (averaged over all CPUs). If you know the regular tick rate of the target
-
* system you may calculate the number of CPUs from the sum of C<cpu_time>
-
* increments and the time interval between the samples. Most often you
-
* will be interested in the percentage of CPU states only.
-
*/
-
public void testRstat() {
-
OncRpcClientAuthUnix authUnix = null;
-
RstatClient rstat = null;
-
statstime stats = null;
-
statstime stats2 = null;
-
try {
-
authUnix = new OncRpcClientAuthUnix(
-
);
-
Assert.assertNotNull("Auth Unix is null", authUnix);
-
-
rstat = new RstatClient(
-
OncRpcProtocols.ONCRPC_UDP
-
);
-
Assert.assertNotNull("Rstat is null", rstat);
-
rstat.getClient().setAuth(authUnix);
-
rstat.getClient().setTimeout(MAX_TIMEOUT);
-
stats = rstat.RSTATPROC_STATS_3();
-
Assert.assertNotNull("statsswtch stats is null", stats);
-
-
// Now wait a little bit before taking the next snapshot
-
-
// Get another snapshot
-
stats2 = rstat.RSTATPROC_STATS_3();
-
-
long timeElaps = stats2.getCurtime().tv_sec - stats.getCurtime().tv_sec;
-
-
-
info.append("Rstat unit test\n");
-
info.append("Time elapsed between measures (seconds): " + timeElaps + "\n");
-
info.append("if_collisions=%s\n");
-
info.append("if_ierrors=%s\n");
-
info.append("if_ipackets=%s\n");
-
info.append("if_oerrors=%s\n");
-
info.append("if_opackets=%s\n");
-
info.append("v_intr=%s\n");
-
info.append("v_pgpgin=%s\n");
-
info.append("v_pgpgout=%s\n");
-
info.append("v_pswpin=%s\n");
-
info.append("v_pswpout=%s\n");
-
info.append("v_swtch=%s\n");
-
info.append("Avenrun (CPU load) 0=%s\n");
-
info.append("Avenrun (CPU load) 1=%s\n");
-
info.append("Avenrun (CPU load) 2=%s\n");
-
info.append("CP_time 0 Usr=%s\n");
-
info.append("CP_time 1 System=%s\n");
-
info.append("CP_time 2 Wio=%s\n");
-
info.append("CP_time 3 Idle=%s\n");
-
info.append("Dk_xfer 0=%s\n");
-
info.append("Dk_xfer 1=%s\n");
-
info.append("Dk_xfer 2=%s\n");
-
info.append("Dk_xfer 3=%s\n");
-
info.append("Raw uptime in seconds=%s\n");
-
-
// Spit the results out
-
info.toString(),
-
statColl
-
);
-
Assert.fail("Got an exception: " + throwbl.toString());
-
throwbl.printStackTrace();
-
} finally {
-
// Empty for now
-
}
-
}
-
}
Así que si la curiosidad le pica, lo invito a leer el resto de el articulo aquí
A veces basta con sólo decir: Gracias por el post.
gRACIAS FUE DE MUCHA AYUDA