Skip to content

Commit

Permalink
Merge pull request #17 from voiceip/metrics
Browse files Browse the repository at this point in the history
orkweb: JMX Metrics
  • Loading branch information
kingster authored Mar 2, 2020
2 parents 0302d8b + c416072 commit f36927f
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 64 deletions.
69 changes: 69 additions & 0 deletions orktrack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>

Expand All @@ -39,6 +40,51 @@
<path>/</path>
</configuration>
</plugin>

<plugin>
<!--
<groupId>org.codehaus.mojo</groupId>
Using snapshot build instead: https://github.com/mojohaus/aspectj-maven-plugin/issues/24#issuecomment-419077658
-->
<groupId>com.github.m50d</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11.1</version>

<configuration>

<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>

<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>

<forceAjcCompile>true</forceAjcCompile>
<sources/><!-- this is important!-->

<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>

<aspectLibraries>
<aspectLibrary>
<groupId>io.astefanutti.metrics.aspectj</groupId>
<artifactId>metrics-aspectj</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>

</build>
Expand All @@ -64,6 +110,29 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-annotation</artifactId>
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>io.astefanutti.metrics.aspectj</groupId>
<artifactId>metrics-aspectj</artifactId>
<version>1.2.0</version>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.1</version>
</dependency>

</dependencies>
</project>
8 changes: 8 additions & 0 deletions orktrack/src/main/java/net/sf/oreka/orktrack/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.sf.oreka.orktrack;

public class Constants {
public static final String APP_NAME = "OrkTrack";
public static final String DEFAULT_REGISTRY_NAME = "metrics-registry";


}
58 changes: 29 additions & 29 deletions orktrack/src/main/java/net/sf/oreka/orktrack/OrkTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,38 @@
*/
package net.sf.oreka.orktrack;

import java.util.Date;

import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.SharedMetricRegistries;
import net.sf.oreka.HibernateManager;
import net.sf.oreka.OrkObjectFactory;
import net.sf.oreka.orktrack.messages.ConfigureLogMessage;
import net.sf.oreka.orktrack.messages.InitMessage;
import net.sf.oreka.orktrack.messages.MetadataMessage;
import net.sf.oreka.orktrack.messages.PingMessage;
import net.sf.oreka.orktrack.messages.TapeMessage;
import net.sf.oreka.orktrack.messages.UserStateMessage;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import net.sf.oreka.orktrack.messages.*;
import org.apache.logging.log4j.Logger;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import static net.sf.oreka.orktrack.Constants.*;

public class OrkTrack {

public static final String APP_NAME = "OrkTrack";

public static HibernateManager hibernateManager = HibernateManager.instance();
private static Date lastInMemoryObjectsSync = new Date(0);
public static MetricRegistry METRIC_REGISTRY;
private static JmxReporter reporter;

static Logger logger = Logger.getLogger(OrkTrack.class);
private static Logger log = LogManager.getInstance().getRootLogger();

public OrkTrack() {

LogManager.getInstance().getConfigLogger().info("Entering OrkTrack");
}

public static void initialize(String log4jConfigFile, String hibernateConfigFile, String configFile) {
public static void initialize(String log4jConfigFile, String hibernateConfigFile, String configFile) throws Exception {
try {
LogManager.getInstance().configure(log4jConfigFile);

logger.info("========================================");
logger.info(OrkTrack.APP_NAME + " starting ...");
log.info("========================================");
log.info(APP_NAME + " starting ...");

// Register all OrkObjects
OrkObjectFactory.instance().registerOrkObject(new OrkTrackConfig());
Expand All @@ -64,9 +60,20 @@ public static void initialize(String log4jConfigFile, String hibernateConfigFile
ConfigManager.getInstance().load(configFile);

hibernateManager.configure(hibernateConfigFile);

METRIC_REGISTRY = SharedMetricRegistries.getOrCreate(DEFAULT_REGISTRY_NAME);

reporter = JmxReporter.forRegistry(METRIC_REGISTRY)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.convertRatesTo(TimeUnit.SECONDS)
.inDomain("orktrack")
.build();
reporter.start();

}
catch (Exception e) {
logger.error("OrkTrack.initialize: Error configuring Hibernate:" + e.getMessage());
log.error("OrkTrack.initialize: Error configuring Hibernate:" + e.getMessage());
throw e ;
}

/*
Expand All @@ -81,9 +88,10 @@ public static void initialize(String log4jConfigFile, String hibernateConfigFile
*/
refreshInMemoryObjects();

logger.info(OrkTrack.APP_NAME + " started successfully.");
logger.info("----------------------------------------");
log.info(APP_NAME + " started successfully.");
log.info("----------------------------------------");

METRIC_REGISTRY.counter(APP_NAME).inc();
}

public static void refreshInMemoryObjects() {
Expand All @@ -97,12 +105,4 @@ public static void refreshInMemoryObjects() {
}
}

public static void main(String[] args)
{
//System.out.println("hello");
//RecSegment seg = new RecSegment();
//System.out.println(seg.getDuration());
//OrkTrack orkTrack = new OrkTrack();
}

}
13 changes: 4 additions & 9 deletions orktrack/src/main/java/net/sf/oreka/orktrack/OrkTrackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@

package net.sf.oreka.orktrack;

import lombok.Getter;
import lombok.Setter;
import net.sf.oreka.OrkException;
import net.sf.oreka.OrkObject;
import net.sf.oreka.serializers.OrkSerializer;

@Getter
@Setter
public class OrkTrackConfig implements OrkObject {

boolean ctiDriven = false;
Expand All @@ -33,14 +37,5 @@ public String getOrkClassName() {
public void validate() {

}

public boolean isCtiDriven() {
return ctiDriven;
}

public void setCtiDriven(boolean ctiDriven) {
this.ctiDriven = ctiDriven;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@
import net.sf.oreka.orktrack.LogManager;
import net.sf.oreka.serializers.OrkSerializer;

import org.apache.log4j.Logger;

public class ConfigureLogMessage extends SyncMessage {

static Logger logger = Logger.getLogger(ConfigureLogMessage.class);


public ConfigureLogMessage() {
}

@Override
public AsyncMessage process() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@

package net.sf.oreka.orktrack.messages;

import com.codahale.metrics.annotation.Timed;
import io.astefanutti.metrics.aspectj.Metrics;
import net.sf.oreka.OrkException;
import net.sf.oreka.messages.AsyncMessage;
import net.sf.oreka.messages.SimpleResponseMessage;
import net.sf.oreka.messages.SyncMessage;
import net.sf.oreka.serializers.OrkSerializer;

@Metrics(registry = "appMetrics")
public class PingMessage extends SyncMessage {

public PingMessage() {
}

@Override
@Timed(name = "process")
public AsyncMessage process() {

SimpleResponseMessage response = new SimpleResponseMessage();
response.setSuccess(true);
response.setComment("pong");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

package net.sf.oreka.orktrack.messages;

import com.codahale.metrics.SharedMetricRegistries;
import com.codahale.metrics.annotation.Timed;
import io.astefanutti.metrics.aspectj.Metrics;
import lombok.Getter;
import lombok.Setter;
import net.sf.oreka.Direction;
import net.sf.oreka.OrkException;
import net.sf.oreka.messages.AsyncMessage;
import net.sf.oreka.messages.SyncMessage;
import net.sf.oreka.orktrack.Constants;
import net.sf.oreka.orktrack.OrkTrack;
import net.sf.oreka.orktrack.ServiceManager;
import net.sf.oreka.orktrack.TapeManager;
Expand All @@ -32,11 +36,12 @@

@Getter
@Setter
@Metrics
public class TapeMessage extends SyncMessage {

public enum CaptureStage {START , STOP, READY, COMPLETE, UNKN};

static Logger logger = Logger.getLogger(TapeMessage.class);
static Logger log = Logger.getLogger(TapeMessage.class);

CaptureStage stage = CaptureStage.UNKN;
int timestamp = 0;
Expand All @@ -63,33 +68,36 @@ public TapeMessage() {
}

@Override
@Timed(name = "process")
public AsyncMessage process() {

TapeResponse response = new TapeResponse();
SharedMetricRegistries.getOrCreate(Constants.DEFAULT_REGISTRY_NAME)
.meter(getClass().getName()+".processing."+stage).mark();

TapeResponse response = new TapeResponse();
Session session = null;
Transaction tx = null;


try {
session = OrkTrack.hibernateManager.getSession();
tx = session.beginTransaction();
Transaction tx = session.beginTransaction();

SingleLineSerializer ser = new SingleLineSerializer();
logger.info("Message: " + ser.serialize(this));
log.info("Message: " + ser.serialize(this));

OrkService service = ServiceManager.retrieveOrCreate(this.service, this.getHostname(), session);

//Port port = PortManager.instance().getAndCreatePort(this.getCapturePort(), session, service);
//port.notifyTapeMessage(this, session, service);
if (TapeManager.instance().notifyTapeMessage(this, session, service) == false) {
response.setDeleteTape(true);
logger.debug("Tape deletion requested:" + this.getFilename());
log.debug("Tape deletion requested:" + this.getFilename());
}

response.setSuccess(true);
tx.commit();
}
catch (Exception e) {
logger.error("TapeMessage.process: ", e);
log.error("TapeMessage.process: ", e);
response.setSuccess(false);
response.setComment(e.getMessage());
}
Expand Down Expand Up @@ -124,7 +132,7 @@ public String getOrkClassName() {

public void validate() {
// TODO Auto-generated method stub

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class TapeResponse extends SimpleResponseMessage {
private boolean deleteTape = false;

public void define(OrkSerializer serializer) throws OrkException {

super.define(serializer);
deleteTape = serializer.booleanValue("deletetape", deleteTape, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package net.sf.oreka.orktrack.servlets;

import net.sf.oreka.orktrack.Constants;
import net.sf.oreka.orktrack.LogManager;
import net.sf.oreka.orktrack.OrkTrack;
import net.sf.oreka.util.TomcatServerXMLParser;
Expand All @@ -27,8 +28,7 @@ public class ContextListener implements ServletContextListener {
Logger log = LogManager.getInstance().getRootLogger();

public void contextDestroyed(ServletContextEvent arg0) {

log.info(OrkTrack.APP_NAME + " shutting down.");
log.info(Constants.APP_NAME + " shutting down.");
}

public void contextInitialized(ServletContextEvent servletContextEvent) {
Expand Down
Loading

0 comments on commit f36927f

Please sign in to comment.