You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by ds...@apache.org on 2011/09/28 13:14:21 UTC
svn commit: r1176822 - in
/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring: ./
src/main/java/org/apache/clerezza/rdf/cris/monitoring/
src/main/resources/org/apache/clerezza/rdf/cris/monitoring/
src/main/resources/org/apache/clerezza/rdf/cris...
Author: dspicar
Date: Wed Sep 28 11:14:20 2011
New Revision: 1176822
URL: http://svn.apache.org/viewvc?rev=1176822&view=rev
Log:
CLEREZZA-606: changed data store to rrdtool (rrd4j)
Added:
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FDStatisticsContainer.java (with props)
Removed:
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/resources/org/apache/clerezza/rdf/cris/monitoring/staticweb/scripts/
Modified:
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/pom.xml
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/CRISFileDescriptorMonitor.java
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FileDescriptorCountTask.java
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/MONITORING.java
incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/resources/org/apache/clerezza/rdf/cris/monitoring/statistics.ssp
Modified: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/pom.xml?rev=1176822&r1=1176821&r2=1176822&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/pom.xml (original)
+++ incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/pom.xml Wed Sep 28 11:14:20 2011
@@ -24,7 +24,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.apache.clerezza</groupId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>0.3-incubating-SNAPSHOT</version>
</parent>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.cris.monitoring</artifactId>
@@ -34,6 +34,15 @@
<description>
A Tool that monitors file descriptor usage of CRIS and of the platform.
</description>
+
+ <repositories>
+ <repository>
+ <id>fusesource.release</id>
+ <name>FuseSource Releases</name>
+ <url>http://repo.fusesource.com/nexus/content/groups/public/</url>
+ </repository>
+ </repositories>
+
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -61,12 +70,50 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.typerendering.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
<artifactId>platform.dashboard.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>web.fileserver</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.fusesource.rrd4j</groupId>
+ <artifactId>rrd4j</artifactId>
+ <version>2.0.7</version>
+ </dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Embed-Transitive>true</Embed-Transitive>
+ <Embed-Dependency>
+ rrd4j
+ </Embed-Dependency>
+ <Export-Package>
+ org.apache.clerezza.rdf.cris.monitoring
+ </Export-Package>
+ <Import-Package>
+ com.mongodb;resolution:=optional,
+ com.sleepycat.je;resolution:=optional,
+ com.sun.image.codec.jpeg;resolution:=optional,
+ sun.misc;resolution:=optional,
+ sun.nio.ch;resolution:=optional,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/CRISFileDescriptorMonitor.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/CRISFileDescriptorMonitor.java?rev=1176822&r1=1176821&r2=1176822&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/CRISFileDescriptorMonitor.java (original)
+++ incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/CRISFileDescriptorMonitor.java Wed Sep 28 11:14:20 2011
@@ -19,42 +19,44 @@
package org.apache.clerezza.rdf.cris.monitoring;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
-import java.util.List;
import java.util.Timer;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
+import org.apache.clerezza.platform.typerendering.WebRenderingService;
import org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesService;
import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.apache.clerezza.rdf.core.TypedLiteral;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.cris.monitoring.OSDetector.OS;
import org.apache.clerezza.rdf.ontologies.PLATFORM;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.clerezza.rdf.utils.GraphNode;
-import org.apache.clerezza.rdf.utils.RdfList;
-import org.apache.clerezza.utils.osgi.BundlePathNode;
-import org.apache.clerezza.web.fileserver.FileServer;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
+import org.rrd4j.ConsolFun;
+import org.rrd4j.DsType;
+import org.rrd4j.core.FetchData;
+import org.rrd4j.core.FetchRequest;
+import org.rrd4j.core.RrdDb;
+import org.rrd4j.core.RrdDef;
+import org.rrd4j.core.RrdFileBackendFactory;
+import org.rrd4j.core.Sample;
+import org.rrd4j.core.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.wymiwyg.commons.util.dirbrowser.PathNode;
/**
* Monitors file descriptor usage by CRIS and offers a web resource displaying the data.
@@ -62,12 +64,15 @@ import org.wymiwyg.commons.util.dirbrows
* @author daniel
*/
@Component(metatype=true)
-@Service(Object.class)
+@Service({
+ Object.class,
+ CRISFileDescriptorMonitor.class})
+@WebRenderingService
@Property(name="javax.ws.rs", boolValue=true)
@Path("/admin/monitoring/cris")
public class CRISFileDescriptorMonitor {
- @Property(description="Interval between measurements in milliseconds (min. 1000 ms).",
- intValue=10000)
+ @Property(description="Interval between measurements in seconds (min. 1 s, max. 86400 s (1 day)).",
+ intValue=10)
public static final String PROBING_RATE = "probing_rate";
@Property(description="The Bundle ID of the monitored bundle (must be positive).", intValue=-1)
@@ -77,9 +82,6 @@ public class CRISFileDescriptorMonitor {
+ "the lucene index folder.", value="")
public static final String DIRECTORY_PATH = "index_path";
- @Property(description="How many datapoints are stored. (min. 10)", intValue=10000)
- public static final String STORE_SIZE = "store_size";
-
@Property(description="When to trigger the treshold action (in terms of open files of the platform). (min. 700)", intValue=1000)
public static final String ACTION_THRESHOLD = "action_threshold";
@@ -89,99 +91,157 @@ public class CRISFileDescriptorMonitor {
@Property(description="How long to wait before performing threshold action after last time it has been performed (in minutes).", intValue=30)
public static final String THRESHOLD_TIMEOUT = "threshold_timeout";
+ public static final String JVM_COUNT = "jvmCount";
+
+ public static final String CRIS_COUNT = "crisCount";
+
+ /**
+ * RRDTool data source for CRIS file descriptor counts.
+ */
+ static final String CRISFILES_DS = "crisFiles";
+
+ /**
+ * RRDTool data source for JVM file descriptor counts.
+ */
+ static final String JVMFILES_DS = "jvmFiles";
+
@Reference
private ScalaServerPagesService scalaServerPagesService;
- private int viewLimit = 100;
- private int storeSize;
- private int bundleId;
- private int probingRate;
- private long userFileDescriptorLimit = -1;
- private String directory;
- private String thresholdUrl = "";
- private long threshold = -1l;
- private int thresholdTimeout;
- private Date lastThreshHoldAction = new Date(0l);
+ int viewLimit = 100;
+ int bundleId;
+ int probingRate;
+ long userFileDescriptorLimit = -1;
+ String directory;
+ String thresholdUrl = "";
+ long threshold = -1l;
+ int thresholdTimeout;
+ Date lastThreshHoldAction = new Date(0l);
- private FileServer fileServer;
+ private BundleContext bundleContext;
- List<long[]> crisData, jvmData;
+ private RrdDb rrdDb;
private final Logger logger = LoggerFactory.getLogger(getClass());
private Timer timer = new Timer();
private FileDescriptorCountTask fileDescriptorCountTask = null;
- private int lastIndex = -1;
+ private int day = 86400;
+ private ServiceRegistration sspServiceRegistration;
@GET
- public GraphNode getStatistics() {
+ public GraphNode getStatisticsPage() throws IOException {
+
SimpleMGraph graph = new SimpleMGraph();
GraphNode statisticsPageNode = new GraphNode(new BNode(), graph);
statisticsPageNode.addProperty(RDF.type, PLATFORM.HeadedPage);
statisticsPageNode.addProperty(RDF.type, MONITORING.STATISTICS_PAGE);
+ // statisticsPageNode.addProperty(MONITORING.PROBINGRATE,
+ // new PlainLiteralImpl(String.valueOf(probingRate)));
+ // statisticsPageNode.addProperty(MONITORING.VIEWLIMIT,
+ // new PlainLiteralImpl(String.valueOf(viewLimit)));
+ // statisticsPageNode.addProperty(MONITORING.BUNDLE,
+ // new PlainLiteralImpl(String.valueOf(bundleId)));
+ // statisticsPageNode.addProperty(MONITORING.INDEXDIRECTORY,
+ // new PlainLiteralImpl(String.valueOf(directory)));
+ // statisticsPageNode.addProperty(MONITORING.OPENFILELIMIT,
+ // new PlainLiteralImpl(String.valueOf(userFileDescriptorLimit)));
+ // statisticsPageNode.addProperty(MONITORING.THRESHOLD,
+ // new PlainLiteralImpl(String.valueOf(threshold)));
+ // statisticsPageNode.addProperty(MONITORING.THRESHOLDURL,
+ // new PlainLiteralImpl(String.valueOf(thresholdUrl)));
+ // statisticsPageNode.addProperty(MONITORING.THRESHOLDTIMEOUT,
+ // new PlainLiteralImpl(String.valueOf(thresholdTimeout)));
+
+ // FDStatisticsContainer statisticsContainer = getStatistics();
+ // long[] timeStamps = statisticsContainer.get(FDStatisticsContainer.TIMESTAMPS);
+ // long[] jvmEntries = statisticsContainer.get(JVM_COUNT);
+ // long[] crisEntries = statisticsContainer.get(CRIS_COUNT);
+ //
+ // GraphNode dataNode = new GraphNode(new BNode(), graph);
+ // RdfList list = new RdfList(dataNode);
+ // SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy");
+ // for (int i = timeStamps.length - 1; i > 0; --i) {
+ // if((int) jvmEntries[i] == 0) {
+ // continue;
+ // }
+ //
+ // LiteralFactory lf = LiteralFactory.getInstance();
+ // GraphNode entryNode = new GraphNode(new BNode(), graph);
+ // String timeString = df.format(Util.getDate(timeStamps[i]));
+ // TypedLiteral timestamp = lf.createTypedLiteral(timeString);
+ // TypedLiteral jvm = lf.createTypedLiteral((int) jvmEntries[i]);
+ // TypedLiteral cris = lf.createTypedLiteral((int) crisEntries[i]);
+ // entryNode.addProperty(MONITORING.TIMESTAMP, timestamp);
+ // entryNode.addProperty(MONITORING.JVMDATA, jvm);
+ // entryNode.addProperty(MONITORING.CRISDATA, cris);
+ //
+ // list.add(entryNode.getNode());
+ // }
+ //
+ // statisticsPageNode.addProperty(MONITORING.DATA, dataNode.getNode());
+
+ return statisticsPageNode;
+ }
+
+ @GET
+ @Path("services")
+ public String pop() {
+ String str = "RegisteredServices: " + Arrays.toString(bundleContext.getBundle().getRegisteredServices());
+ str += "\n";
+ str += "ServicesInUse: " + Arrays.toString(bundleContext.getBundle().getServicesInUse());
- statisticsPageNode.addProperty(MONITORING.PROBINGRATE,
- new PlainLiteralImpl(String.valueOf(probingRate)));
- statisticsPageNode.addProperty(MONITORING.STORESIZE,
- new PlainLiteralImpl(String.valueOf(storeSize)));
- statisticsPageNode.addProperty(MONITORING.VIEWLIMIT,
- new PlainLiteralImpl(String.valueOf(viewLimit)));
- statisticsPageNode.addProperty(MONITORING.BUNDLE,
- new PlainLiteralImpl(String.valueOf(bundleId)));
- statisticsPageNode.addProperty(MONITORING.INDEXDIRECTORY,
- new PlainLiteralImpl(String.valueOf(directory)));
- statisticsPageNode.addProperty(MONITORING.OPENFILELIMIT,
- new PlainLiteralImpl(String.valueOf(userFileDescriptorLimit)));
- statisticsPageNode.addProperty(MONITORING.THRESHOLD,
- new PlainLiteralImpl(String.valueOf(threshold)));
- statisticsPageNode.addProperty(MONITORING.THRESHOLDURL,
- new PlainLiteralImpl(String.valueOf(thresholdUrl)));
- statisticsPageNode.addProperty(MONITORING.THRESHOLDTIMEOUT,
- new PlainLiteralImpl(String.valueOf(thresholdTimeout)));
+ return str;
- GraphNode dataNode = new GraphNode(new BNode(), graph);
- RdfList list = new RdfList(dataNode);
- int index = lastIndex;
- for (int i = 0; i < viewLimit; ++i) {
- if(index < 0) {
- index = storeSize - 1;
- }
-
- LiteralFactory lf = LiteralFactory.getInstance();
- GraphNode entryNode = new GraphNode(new BNode(), graph);
- long[] jvmEntry = jvmData.get(index);
- Date date = new Date(jvmEntry[0]);
- String timeString = "-";
- if(date.getTime() > 0l) {
- SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy");
- timeString = df.format(date);
- }
- TypedLiteral timestamp = lf.createTypedLiteral(timeString);
- TypedLiteral jvm = lf.createTypedLiteral(jvmEntry[1]);
- TypedLiteral cris = lf.createTypedLiteral(crisData.get(index)[1]);
- entryNode.addProperty(MONITORING.TIMESTAMP, timestamp);
- entryNode.addProperty(MONITORING.JVMDATA, jvm);
- entryNode.addProperty(MONITORING.CRISDATA, cris);
-
- list.add(entryNode.getNode());
-
- --index;
- }
+ }
+
+ public FDStatisticsContainer getStatistics() throws IOException {
+ long now = Util.getTime();
+ long start = now - viewLimit*probingRate;
+ FetchRequest fr = rrdDb.createFetchRequest(ConsolFun.LAST, start, now, probingRate);
+ FetchData fd = fr.fetchData();
+ long[] timeStamps = fd.getTimestamps();
+ long[] jvmEntries = toLongArray(fd.getValues(JVMFILES_DS));
+ long[] crisEntries = toLongArray(fd.getValues(CRISFILES_DS));
- statisticsPageNode.addProperty(MONITORING.DATA, dataNode.getNode());
+ FDStatisticsContainer result = new FDStatisticsContainer(3);
+ result.set(FDStatisticsContainer.TIMESTAMPS, timeStamps);
+ result.set(JVM_COUNT, jvmEntries);
+ result.set(CRIS_COUNT, crisEntries);
- return statisticsPageNode;
- }
-
- /**
- * Returns a PathNode of a static file from the staticweb folder.
- *
- * @return {@link PathNode}
- */
- @GET
- @Path("{path:.+}")
- public PathNode getStaticFile(@PathParam("path") String path) {
- final PathNode node = fileServer.getNode(path);
- return node;
+ return result;
+
+ }
+
+ public int getBundleId() {
+ return bundleId;
+ }
+
+ public String getDirectory() {
+ return directory;
+ }
+
+ public int getProbingRate() {
+ return probingRate;
+ }
+
+ public long getThreshold() {
+ return threshold;
+ }
+
+ public int getThresholdTimeout() {
+ return thresholdTimeout;
+ }
+
+ public String getThresholdUrl() {
+ return thresholdUrl;
+ }
+
+ public long getUserFileDescriptorLimit() {
+ return userFileDescriptorLimit;
+ }
+
+ public int getViewLimit() {
+ return viewLimit;
}
protected void activate(ComponentContext context) throws IOException {
@@ -196,9 +256,8 @@ public class CRISFileDescriptorMonitor {
pid = getPID();
bundleId = getIntegerValue(context, BUNDLE_ID, 0, Integer.MAX_VALUE);
directory = getStringValue(context, DIRECTORY_PATH);
- getUserFileDescriptorLimit();
- probingRate = getIntegerValue(context, PROBING_RATE, 1000, Integer.MAX_VALUE);
- storeSize = getIntegerValue(context, STORE_SIZE, 10, Integer.MAX_VALUE);
+ extractUserFileDescriptorLimit();
+ probingRate = getIntegerValue(context, PROBING_RATE, 1, day);
threshold = getIntegerValue(context, ACTION_THRESHOLD, 700, Integer.MAX_VALUE);
thresholdTimeout = getIntegerValue(context, THRESHOLD_TIMEOUT, 0, Integer.MAX_VALUE);
thresholdUrl = (String) context.getProperties().get(THRESHOLD_URL);
@@ -212,17 +271,22 @@ public class CRISFileDescriptorMonitor {
return;
}
- BundleContext bundleContext = context.getBundleContext();
-
- Bundle bundle = bundleContext.getBundle();
- URL resourceDir = getClass().getResource("staticweb");
- PathNode pathNode = new BundlePathNode(bundle, resourceDir.getPath());
- fileServer = new FileServer(pathNode);
-
- crisData = new ArrayList<long[]>(storeSize);
- jvmData = new ArrayList<long[]>(storeSize);
- initStore(crisData);
- initStore(jvmData);
+ bundleContext = context.getBundleContext();
+ File file = bundleContext.getDataFile("statistics.rrd");
+ if(file.exists()) {
+ file.delete();
+ }
+ RrdDef rrdDef = new RrdDef(file.getAbsolutePath());
+ rrdDef.setStartTime(Util.getTime());
+ rrdDef.setStep(probingRate);
+ long heartbeat = 2*probingRate;
+ rrdDef.addDatasource(CRISFILES_DS, DsType.GAUGE, heartbeat, 0.0, Double.NaN);
+ rrdDef.addDatasource(JVMFILES_DS, DsType.GAUGE, heartbeat, 0.0, Double.NaN);
+ int dayRatio = Math.max(1, (int) Math.floor(day / probingRate));
+ rrdDef.addArchive(ConsolFun.LAST, 0.5, 1, day); //1 day
+ rrdDef.addArchive(ConsolFun.LAST, 0.5, dayRatio, 30); //1 month
+ rrdDef.addArchive(ConsolFun.LAST, 0.5, dayRatio*30, 12); //1 year
+ rrdDb = new RrdDb(rrdDef, new RrdFileBackendFactory());
if(fileDescriptorCountTask == null) {
fileDescriptorCountTask =
@@ -233,49 +297,37 @@ public class CRISFileDescriptorMonitor {
timer.cancel();
}
timer = new Timer();
- timer.scheduleAtFixedRate(fileDescriptorCountTask, 0l, probingRate);
+ timer.scheduleAtFixedRate(fileDescriptorCountTask, probingRate * 1000, probingRate * 1000);
URL template = getClass().getResource("statistics.ssp");
- scalaServerPagesService.registerScalaServerPage(template,
- MONITORING.STATISTICS_PAGE, "naked", MediaType.APPLICATION_XHTML_XML_TYPE);
+ sspServiceRegistration = scalaServerPagesService.registerScalaServerPage(template,
+ MONITORING.STATISTICS_PAGE, "naked", MediaType.APPLICATION_XHTML_XML_TYPE, bundleContext);
+
}
}
- protected void deactivate(ComponentContext context) {
+ protected void deactivate(ComponentContext context) throws IOException {
if(timer != null) {
logger.info("Stopping monitoring thread.");
timer.cancel();
timer = null;
}
- }
-
- synchronized void addCRISEntry(long time, long data) {
- long[] entry = new long[2];
- entry[0] = time;
- entry[1] = data;
- int index = lastIndex + 1;
- if(index >= storeSize) {
- index = 0;
- }
- crisData.set(index, entry);
- lastIndex = index;
- }
-
- synchronized void addJVMentry(long time, long data) {
- long[] entry = new long[2];
- entry[0] = time;
- entry[1] = data;
- int index = lastIndex;
- if(index >= storeSize) {
- index = 0;
+ if(rrdDb != null) {
+ rrdDb.close();
}
- jvmData.set(index, entry);
-
- if(data >= threshold) {
- performAction();
+ if(sspServiceRegistration != null) {
+ sspServiceRegistration.unregister();
+ sspServiceRegistration = null;
}
}
+ void setSample(int... counts) throws IOException {
+ Sample sample = rrdDb.createSample(Util.getTime());
+ sample.setValue(CRISFileDescriptorMonitor.JVMFILES_DS, counts[0]);
+ sample.setValue(CRISFileDescriptorMonitor.CRISFILES_DS, counts[1]);
+ sample.update();
+ }
+
synchronized void performAction() {
if(thresholdUrl == null || thresholdUrl.equals("")) {
logger.info("Will not perform threshold action because no threshold URL is set.");
@@ -325,7 +377,7 @@ public class CRISFileDescriptorMonitor {
return pid;
}
- private void getUserFileDescriptorLimit() {
+ private void extractUserFileDescriptorLimit() {
userFileDescriptorLimit = -1l;
try {
String[] cmd = {"bash", "-c", "ulimit -Hn"};
@@ -341,15 +393,6 @@ public class CRISFileDescriptorMonitor {
}
}
- private void initStore(List<long[]> store) {
- for(int i = 0; i < storeSize; ++i) {
- long[] entry = new long[2];
- entry[0] = -1l;
- entry[1] = -1l;
- store.add(entry);
- }
- }
-
private String getStringValue(ComponentContext context, String property) {
String tmp = (String) context.getProperties().get(property);
tmp = tmp.trim();
@@ -371,4 +414,13 @@ public class CRISFileDescriptorMonitor {
return tmp;
}
+
+ private long[] toLongArray(double[] array) {
+ long[] result = new long[array.length];
+ for (int i = 0; i < array.length; i++) {
+ result[i] = (long) array[i];
+ }
+
+ return result;
+ }
}
\ No newline at end of file
Added: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FDStatisticsContainer.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FDStatisticsContainer.java?rev=1176822&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FDStatisticsContainer.java (added)
+++ incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FDStatisticsContainer.java Wed Sep 28 11:14:20 2011
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.cris.monitoring;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author daniel
+ */
+public class FDStatisticsContainer {
+ public static final String TIMESTAMPS = "timestamps";
+
+ Map<String, long[]> statistics;
+
+ public FDStatisticsContainer(int initalCapacity) {
+ statistics = new HashMap<String, long[]>(initalCapacity);
+ }
+
+ public void set(String key, long[] value) {
+ statistics.put(key, value);
+ }
+
+ public long[] get(String key) {
+ return statistics.get(key);
+ }
+}
Propchange: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FDStatisticsContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FileDescriptorCountTask.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FileDescriptorCountTask.java?rev=1176822&r1=1176821&r2=1176822&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FileDescriptorCountTask.java (original)
+++ incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/FileDescriptorCountTask.java Wed Sep 28 11:14:20 2011
@@ -19,7 +19,6 @@
package org.apache.clerezza.rdf.cris.monitoring;
import java.io.IOException;
-import java.util.Date;
import java.util.TimerTask;
/**
@@ -29,20 +28,12 @@ import java.util.TimerTask;
* @author daniel
*/
class FileDescriptorCountTask extends TimerTask {
- long crisFiles = -1;
- long totalFDs = -1;
-
- long pid = -1;
int bundleId = -1;
- String directory = null;
String[] crisOpenFilesCountCommand, jvmOpenFileDescriptorsCountCommand;
private CRISFileDescriptorMonitor monitorInstance;
public FileDescriptorCountTask(long pid, int bundleId, String directory,
CRISFileDescriptorMonitor monitorInstance) {
- this.pid = pid;
- this.bundleId = bundleId;
- this.directory = directory;
this.monitorInstance = monitorInstance;
String pidString = String.valueOf(pid);
@@ -57,15 +48,6 @@ class FileDescriptorCountTask extends Ti
subCommand.append("/data/");
subCommand.append(directory);
subCommand.append(" | wc -l");
-// StringBuilder subCommand = new StringBuilder("lsof -a -p");
-// subCommand.append(pidString);
-// subCommand.append(" +d ");
-// subCommand.append(System.getProperty("user.dir"));
-// subCommand.append("/felix-cache/bundle");
-// subCommand.append(String.valueOf(bundleId));
-// subCommand.append("/data/");
-// subCommand.append(directory);
-// subCommand.append(" | wc -l");
crisOpenFilesCountCommand =
new String[] {"bash", "-c", subCommand.toString()};
@@ -83,27 +65,19 @@ class FileDescriptorCountTask extends Ti
Thread.currentThread().setName("CRIS File Descriptor Count Thread ["
+ Thread.currentThread().getId() + "]");
- long time = new Date().getTime();
-
Process p = Runtime.getRuntime().exec(crisOpenFilesCountCommand);
byte[] output = new byte[32];
p.getInputStream().read(output);
p.destroy();
-// crisFiles = Integer.parseInt(new String(output).trim()) - 1;
- crisFiles = Integer.parseInt(new String(output).trim());
-
- monitorInstance.addCRISEntry(time, crisFiles);
+ int crisFiles = Integer.parseInt(new String(output).trim());
p = Runtime.getRuntime().exec(jvmOpenFileDescriptorsCountCommand);
output = new byte[32];
p.getInputStream().read(output);
p.destroy();
- totalFDs = Integer.parseInt(new String(output).trim());
-
- monitorInstance.addJVMentry(time, totalFDs);
+ int totalFDs = Integer.parseInt(new String(output).trim());
-// System.out.println("CRIS: " + crisFiles);
-// System.out.println("Total: " + totalFDs);
+ monitorInstance.setSample(totalFDs, crisFiles);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
Modified: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/MONITORING.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/MONITORING.java?rev=1176822&r1=1176821&r2=1176822&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/MONITORING.java (original)
+++ incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/java/org/apache/clerezza/rdf/cris/monitoring/MONITORING.java Wed Sep 28 11:14:20 2011
@@ -47,9 +47,6 @@ public class MONITORING {
public static final UriRef PROBINGRATE =
new UriRef("http://org.apache.clerezza/2011/07/monitoring#probingrate");
- public static final UriRef STORESIZE =
- new UriRef("http://org.apache.clerezza/2011/07/monitoring#storesize");
-
public static final UriRef VIEWLIMIT =
new UriRef("http://org.apache.clerezza/2011/07/monitoring#viewlimit");
Modified: incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/resources/org/apache/clerezza/rdf/cris/monitoring/statistics.ssp
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/resources/org/apache/clerezza/rdf/cris/monitoring/statistics.ssp?rev=1176822&r1=1176821&r2=1176822&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/resources/org/apache/clerezza/rdf/cris/monitoring/statistics.ssp (original)
+++ incubator/clerezza/issues/CLEREZZA-606/rdf.cris.monitoring/src/main/resources/org/apache/clerezza/rdf/cris/monitoring/statistics.ssp Wed Sep 28 11:14:20 2011
@@ -1,7 +1,13 @@
-import java.util.Date
+import org.apache.clerezza.rdf.cris.monitoring.FDStatisticsContainer
+import org.apache.clerezza.rdf.cris.monitoring.CRISFileDescriptorMonitor
+import java.text.SimpleDateFormat
def monitoring(s: Any) = new UriRef("http://org.apache.clerezza/2011/07/monitoring#"+s)
+val fdMonitor = $[org.apache.clerezza.rdf.cris.monitoring.CRISFileDescriptorMonitor]
+
+val df = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy");
+
resultDocModifier.setTitle("CRIS Monitoring Statistics");
resultDocModifier.addNodes2Elem("tx-module", <h1>CRIS Monitoring Statistics</h1>);
@@ -20,27 +26,33 @@ resultDocModifier.addNodes2Elem("tx-modu
</div>
<div>
<ul>
- <li>Monitored Bundle ID: {(res/monitoring("bundle"))*}</li>
- <li>Probing Rate: {(res/monitoring("probingrate"))*} ms</li>
- <li>Index Directory: {(res/monitoring("indexdirectory"))*}</li>
- <li>Store Size: {(res/monitoring("storesize"))*}</li>
- <li>View Limit: {(res/monitoring("viewlimit"))*}</li>
- <li>Open File Limit: {(res/monitoring("openfilelimit"))*}</li>
- <li>Threshold: {(res/monitoring("threshold"))*}</li>
- <li>Threshold Action URL: {(res/monitoring("thresholdurl"))*}</li>
- <li>Threshold Action Timeout: {(res/monitoring("thresholdtimeout"))*} min</li>
+ <li>Monitored Bundle ID: {fdMonitor.getBundleId}</li>
+ <li>Probing Rate: {fdMonitor.getProbingRate} s</li>
+ <li>Index Directory: {fdMonitor.getDirectory}</li>
+ <li>View Limit: {fdMonitor.getViewLimit}</li>
+ <li>Open File Limit: {fdMonitor.getUserFileDescriptorLimit}</li>
+ <li>Threshold: {fdMonitor.getThreshold}</li>
+ <li>Threshold Action URL: {fdMonitor.getThresholdUrl}</li>
+ <li>Threshold Action Timeout: {fdMonitor.getThresholdTimeout} min</li>
</ul>
</div>
<table>
<caption>Number of open files</caption>
<tr><th>Time</th><th>CRIS</th><th>Platform</th></tr>
{
- val list = res/monitoring("data");
- for(entry <- list!!) yield {
+ val statistics = fdMonitor.getStatistics
+ val timestamps = statistics.get(FDStatisticsContainer.TIMESTAMPS)
+ val jvmEntries = statistics.get(CRISFileDescriptorMonitor.JVM_COUNT)
+ val crisEntries = statistics.get(CRISFileDescriptorMonitor.CRIS_COUNT)
+
+ for {
+ (timestamp, (jvmCount, crisCount)) <- (timestamps zip (jvmEntries zip crisEntries)).reverse
+ if(jvmCount > 0)
+ } yield {
<tr>
- <td>{(entry/monitoring("timestamp"))*}</td>
- <td>{(entry/monitoring("cris"))*}</td>
- <td>{(entry/monitoring("jvm"))*}</td>
+ <td>{df format (timestamp*1000)}</td>
+ <td>{crisCount}</td>
+ <td>{jvmCount}</td>
</tr>
}
}
@@ -51,4 +63,4 @@ resultDocModifier.addNodes2Elem("tx-modu
<div class="hd"></div>
<div class="bd"></div>
<div class="ft"></div>
-</div>
\ No newline at end of file
+</div>