// Implementierung der Klasse FileSystemMonitor
// enthaelt eigene Klasse fsEventPusher
// last modified 29.10.97
import org.omg.CosEventComm.*;
import org.omg.CosEventChannelAdmin.*;
import org.omg.CORBA.SystemException;
import java.util.Calendar;
import java.util.TimeZone;
import java.text.DateFormat;
import java.util.Locale;
import mytools.hostinfo;
public class FilesystemMonitorImpl extends sysagent._FilesystemMonitorImplBase
implements Runnable {
private FilesystemImpl fs;
private float fsFullThreshold;
private int monInterval;
private Thread thread;
private ProxyPushConsumer pushConsumer =null;
private fsEventPusher pusher;
org.omg.CORBA.ORB orb;
org.omg.CORBA.BOA boa;
public FilesystemMonitorImpl ( FilesystemImpl _fs )
{
fsFullThreshold = (float)0.9; // default 90%
monInterval = 60; // default 60 sec
fs = _fs;
thread = new Thread(this);
thread.setDaemon(true);
thread.start();
try {
orb = org.omg.CORBA.ORB.init();
boa = orb.BOA_init();
EventChannel channel = null;
channel = EventChannelHelper.bind(orb, "sysagent_channel");
pushConsumer = channel.for_suppliers().obtain_push_consumer();
pusher = new fsEventPusher();
boa.obj_is_ready(pusher);
try {
pushConsumer.connect_push_supplier(pusher);
}
catch (AlreadyConnected e) {
e.printStackTrace();
}
}
catch (SystemException e) {
e.printStackTrace();
}
}
public float fsFullThreshold()
{
return fsFullThreshold;
}
public void fsFullThreshold (float threshold)
{
fsFullThreshold = threshold;
}
public int monInterval()
{
return monInterval;
}
public void monInterval(int interval)
{
monInterval = interval;
}
public void run() // periodische Abfrage als eigener thread
{
while (true) {
try {
thread.sleep(1000*monInterval);
}
catch (InterruptedException e) {
e.printStackTrace();
}
float usage =((float) (fs.BlockCount()-fs.BlocksAvailable()))/fs.BlockCount();
if (usage > fsFullThreshold) {
try {
org.omg.CORBA.Any message = orb.create_any();
// create time info for event
TimeZone tz = TimeZone.getDefault();
Calendar calendar = Calendar.getInstance(tz);
String ts = DateFormat.getTimeInstance(DateFormat.MEDIUM,
Locale.GERMANY).format(calendar.getTime());
// fetch hostname for event
String host = (new hostinfo()).getLocalHostname();
message.insert_string(host + ": " + ts + ": Filesystem " + fs.Name()
+ " " + java.lang.Math.round(100*usage)
+ "% voll !!");
pushConsumer.push(message); // push event
}
catch (Disconnected e) {
e.printStackTrace();
pusher.disconnect_push_supplier();
thread.stop();
}
}
}
}
}
// Eventpusher fsEventPusher
class fsEventPusher extends _sk_PushSupplier {
fsEventPusher ()
{
super();
}
public void disconnect_push_supplier()
{
try {
_boa().deactivate_obj(this);
}
catch (SystemException e) {
e.printStackTrace();
}
}
}