SystemMonitor.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* ident "%Z%%M% %I% %E% SMI"
*/
/**
* Regularly samples the objective-related utilization statistics of
* the resource in the pool with the given configuration.
*/
class SystemMonitor implements Monitor
{
/**
* The pool configuration with resources to be monitored.
*/
private Configuration conf;
/**
* The map of monitored resources.The map is keyed by
* resource, with the values being the monitorable instances.
*/
/**
* Default sample interval (milliseconds).
*/
public static final int DEF_SAMPLE_INT = 15000;
/**
* Sample interval (milliseconds, default 15000).
*/
private int interval;
/**
* Sample interval property name.
*/
static final String SAMPLE_INTERVAL_PROP_NAME =
"system.poold.monitor-interval";
/**
* Kstat interface for raw data
*/
/**
* Raw statistics which are sampled each interval.
*/
/**
* Timer regulating sampling frequency.
*/
private RecurringEventTimer timer;
/**
* The number of samples taken.
*/
private int sampleCount = 0;
/**
* Time the last sample was taken.
*/
/**
* Constructs a new monitor which is not associated with a
* specific configuration.
*/
public SystemMonitor()
{
this(null);
}
/**
* Constructs a new Monitor for monitoring the resources in the
* given configuration using the given statistic source.
*
* @param conf The configuration which is monitored.
*/
{
}
/**
* Initialize the monitor with the configuration which is to
* be monitored.
*
* @param conf The configuration which is monitored.
*
* @throws PoolsException if manipulating the configuration
* fails.
* @throws StaleMonitorException if the resource monitors
* cannot be set.
*/
{
try {
kc.chainUpdate();
} catch (KstatChainUpdateException kcue) {
}
try {
} catch (PoolsException pe) {
}
setResourceMonitors("pset");
}
/**
* Add all resources of the supplied type in the monitored
* configuration to the set of monitored resources. Remove
* redundant monitors for resources which no longer exist.
* Don't monitor resource sets which are empty.
*
* @param type The type of the resources to be added
*/
{
boolean activeComponents = false;
"cpu.status");
activeComponents = true;
break;
}
}
if (activeComponents == false)
continue;
} else {
stats[i], 2);
}
true));
}
mon.initialize();
}
}
/**
* Get the next sample. Before obtaining the sample, the call
* will block for the interval which was specified when this
* monitor was initialized.
*
* @throws StaleMonitorException if a statistic cannot be obtained.
* @throws PoolsException if there is an error manipulating the
* pools configuration.
* @throws InterruptedException if the thread is interrupted
* while waiting for the sampling time to arrive. The caller
* may wish to check other conditions before possibly
* reinitiating the sample.
*/
{
"sys");
throw new StaleMonitorException();
try {
getValue("cpu_ticks_" +
stats[i]);
throw new
else
}
} catch (KstatException ke) {
new StaleMonitorException();
"configuration necessary due to "
+ ke);
throw(sme);
}
}
new UnsignedInt64(statsv[i].
divide(new BigInteger(
}
}
mon.updateDerived();
}
sampleCount++;
}
/**
* Return the number of samples taken. This is the number of
* successful calls to <code>getNext()</code>.
*/
public int getSampleCount()
{
return (sampleCount);
}
/**
* Return the utilization of the supplied resource. The
* utilization is represented as a percentage between 0
* and 100.
*
* @param res A reference to a configuration resource.
*/
{
try {
"utilization");
} catch (NoSuchElementException nsee) {
}
}
/**
* Return true if the system contains enough sampled data for
* monitoring to be worthwhile.
*/
public boolean isValid()
{
0) {
return (false);
}
}
}
return (true);
}
/**
* Return the ResourceMonitor for the supplied Resource
*
* @throws StaleMonitorException if the ResourceMonitor cannot be found.
*/
{
throw new StaleMonitorException();
return (rm);
}
}