mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 19:33:52 +00:00
First implementation of a simple monitoring service
This commit is contained in:
1 parent
be03df8a70
commit
1f3dff91e2
9 files changed
+228
No files matched your search
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.sap.sailing.monitoring</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
||||
@@ -0,0 +1,17 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Monitoring
|
||||
Bundle-SymbolicName: com.sap.sailing.monitoring
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: com.sap.sailing.monitoring.Activator
|
||||
Bundle-Vendor: SAP
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Import-Package: org.osgi.framework;version="1.3.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: javax.servlet;bundle-version="2.5.0",
|
||||
org.eclipse.jetty.http;bundle-version="7.5.4",
|
||||
org.eclipse.jetty.continuation;bundle-version="7.5.4",
|
||||
org.eclipse.jetty.server;bundle-version="7.5.4",
|
||||
org.eclipse.jetty.util;bundle-version="7.5.4",
|
||||
org.eclipse.jetty.io;bundle-version="7.5.4",
|
||||
org.eclipse.jetty.servlet;bundle-version="7.5.4"
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package com.sap.sailing.monitoring;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
/**
|
||||
* Simple post monitoring application. Checks given ports in an regular interval.
|
||||
* If there is a problem it calls the registered handler.
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 25, 2012
|
||||
*/
|
||||
public abstract class AbstractPortMonitor extends Thread {
|
||||
|
||||
private final int TIMEOUT = 1000;
|
||||
private final int GRACEFUL = 5000;
|
||||
private final int PAUSE = 1000;
|
||||
|
||||
private InetSocketAddress[] endpoints = null;
|
||||
private int interval;
|
||||
|
||||
boolean started = false;
|
||||
private long lastmillis;
|
||||
private InetSocketAddress currentendpoint;
|
||||
|
||||
public AbstractPortMonitor(InetSocketAddress[] endpoints, int interval) {
|
||||
this.endpoints = endpoints;
|
||||
|
||||
if (interval < 10000) {
|
||||
throw new RuntimeException("Interval can not be lower than 10 seconds!");
|
||||
}
|
||||
|
||||
this.interval = interval;
|
||||
this.started = true;
|
||||
}
|
||||
|
||||
public void startMonitoring() {
|
||||
this.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
/* graceful start - give services some time */
|
||||
Thread.sleep(GRACEFUL);
|
||||
|
||||
while (started) {
|
||||
long currentmillis = System.currentTimeMillis();
|
||||
try {
|
||||
if (currentmillis >= (lastmillis + interval + (100*endpoints.length))) {
|
||||
for (int i = 0; i < endpoints.length; i++) {
|
||||
currentendpoint = endpoints[i];
|
||||
|
||||
Socket sn = new Socket();
|
||||
sn.connect(currentendpoint, TIMEOUT);
|
||||
|
||||
handleConnection(currentendpoint);
|
||||
lastmillis = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
Thread.sleep(PAUSE);
|
||||
|
||||
} catch (SocketTimeoutException ex) {
|
||||
handleFailure(currentendpoint);
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (InterruptedException ex) {
|
||||
System.out.println("Interrupted");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stopMonitoring() {
|
||||
this.started = false;
|
||||
}
|
||||
|
||||
public abstract void handleFailure(InetSocketAddress endpoint);
|
||||
|
||||
public abstract void handleConnection(InetSocketAddress endpoint);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.sap.sailing.monitoring;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* Activator for the monitoring service
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 25, 2012
|
||||
*/
|
||||
public class Activator implements BundleActivator {
|
||||
|
||||
private static BundleContext context;
|
||||
private AbstractPortMonitor monitor;
|
||||
|
||||
static BundleContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext bundleContext) throws Exception {
|
||||
Activator.context = bundleContext;
|
||||
|
||||
/* Starts a new port monitoring app */
|
||||
monitor = new SystemPrinterPortMonitor(new InetSocketAddress[]{new InetSocketAddress(InetAddress.getByName("173.194.69.94"), 80)}, 10000);
|
||||
monitor.startMonitoring();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext bundleContext) throws Exception {
|
||||
monitor.stopMonitoring();
|
||||
Activator.context = null;
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.sap.sailing.monitoring;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* Implementation of port monitor that prints out messages if
|
||||
* given endpoint is not connected.
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 25, 2012
|
||||
*/
|
||||
public class SystemPrinterPortMonitor extends AbstractPortMonitor {
|
||||
|
||||
public SystemPrinterPortMonitor(InetSocketAddress[] endpoints, int interval) {
|
||||
super(endpoints, interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(InetSocketAddress endpoint) {
|
||||
System.out.println("ERROR: Could not connect to endpoint " + endpoint.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleConnection(InetSocketAddress endpoint) {
|
||||
System.out.println("INFO: Connection to " + endpoint.toString() + " succeeded.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user