001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: // Later this will move elsewhere...
028: package org.cougaar.core.qos.rss;
029:
030: import java.util.StringTokenizer;
031:
032: import org.cougaar.core.component.ServiceBroker;
033: import org.cougaar.core.qos.metrics.Metric;
034: import org.cougaar.core.qos.metrics.MetricsUpdateService;
035: import org.cougaar.core.qos.metrics.QosComponent;
036: import org.cougaar.qos.qrs.sysstat.DirectSysStatSupplier;
037:
038: /**
039: * This Component is an implementation of MetricsUpdateService that uses the
040: * RSS. Instantiated by and as child component of the {@link
041: * RSSMetricsServiceProvider}.
042: *
043: * @property org.cougaar.metrics.probes If provided, this should be a
044: * comma-separated list of host probes, as understood by the QuO
045: * StatusTEC; or 'all'; or 'none'. The list of possible probes is as
046: * follows: Bogomips, Cache, Clock, FreeMemory, TotalMemory,
047: * LoadAverage, TCPInUse, UDPInUse, Jips, and CPUCount. If the
048: * property is not provided, or is provided with the value 'all', all
049: * probes are run. If the property is provided with the value 'none',
050: * the probe task will not be started. Note that some probes are only
051: * available in Linux.
052: *
053: *
054: */
055: public class RSSMetricsUpdateServiceImpl extends QosComponent implements
056: MetricsUpdateService {
057: private static final String SYSSTAT_KINDS_PROPERTY = "org.cougaar.metrics.probes";
058: private static final int SYSTAT_PERIOD = 15000;
059:
060: private TrivialDataFeed dataFeed;
061: private MetricInterpreter interpreter;
062:
063: public RSSMetricsUpdateServiceImpl() {
064: }
065:
066: public void load() {
067: super .load();
068:
069: ServiceBroker sb = getServiceBroker();
070:
071: String kinds_string = System
072: .getProperty(SYSSTAT_KINDS_PROPERTY);
073: // kinds_string absent or 'all' for all probes
074: // kinds_string empty or 'none' for no probes
075: // Otherwise it should be a comma-separated list
076:
077: String[] kinds = { "Jips", "Memory", "CPU", "LoadAverage",
078: "Sockets", "CPUCount" };
079: ;
080: // kinds == null for all probes
081: // kinds == zero-length array for no probes
082: // kinds == true array of strings for specified probes
083:
084: if (kinds_string != null) {
085: if (kinds_string.equalsIgnoreCase("none")) {
086: kinds = new String[0];
087: } else if (!kinds_string.equalsIgnoreCase("all")) {
088: StringTokenizer tokenizer = new StringTokenizer(
089: kinds_string, ",");
090: kinds = new String[tokenizer.countTokens()];
091: int i = 0;
092: while (tokenizer.hasMoreElements()) {
093: kinds[i] = tokenizer.nextToken();
094: }
095: }
096: }
097:
098: dataFeed = new TrivialDataFeed(sb);
099: interpreter = new MetricInterpreter();
100: if (kinds.length > 0) {
101: DirectSysStatSupplier supplier = new DirectSysStatSupplier(
102: kinds, dataFeed);
103: supplier.schedule(SYSTAT_PERIOD);
104: }
105:
106: }
107:
108: TrivialDataFeed getMetricsFeed() {
109: return dataFeed;
110: }
111:
112: public void updateValue(String key, Metric value) {
113: dataFeed.newData(key, value, interpreter);
114: }
115:
116: }
|