Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core_apps/sysmon/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
*/

group 'edu.upenn.cis.precise.openicelite.coreapps.sysmon'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

/**
* A class that holds information about a channel
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public class ChannelInfo extends Info {

public static final String[] required = {
"time", "name", "username", "connection", "state", "publish_rate", "publish_count", "messages_unacknowledged",
"deliver_get_rate", "deliver_get_count", "ack_rate", "ack_count", "redeliver_rate", "redeliver_count"
};

public ChannelInfo() {
super();
}

@Override
public String[] requiredFields() {
return required;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

/**
* A class that holds information about a connection
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public class ConnectionInfo extends Info{

public static final String[] required = {
"time", "name", "username", "state", "ssl", "channels",
"recv_oct_rate", "recv_oct_count", "send_oct_rate", "send_oct_count"
};

@Override
public String[] requiredFields() {
return required;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

import java.util.List;

/**
* A listener interface for receiving periodic data
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public interface DataListener extends Listener {
/**
* Called when the requested metrics are received.
* @param data Metrics received
*/
void handleData(List<Info> data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

import java.util.List;

/**
* A listener interface for receiving particular states or changes in data.
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public interface EventListener extends Listener {

/**
* Specifies the condition to be notified with the metric. onConditionMet() will be called when this function returns true.
* @param data List of metrics to apply the condition onto
* @return Whether to notify the caller or not
*/
boolean apply(List<Info> data);

/**
* Called when apply() returns true.
* @param data Data that satisfied the condition stated by apply()
*/
void onConditionMet(List<Info> data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

import java.util.Properties;

/**
* Interface to monitor system metrics
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public interface ISysmon {

/**
* Initializes the system monitor with given options (properties).
* @param properties Parsed object of the properties file
*/
void init(Properties properties);

/**
* Start receiving system metrics periodically.
*/
void start();

/**
* Stops receiving system metrics.
*/
void stop();

/**
* Adds the given metric to the list of metrics to request on the next interval.
* @param metric Name of the metric to request
*/
void addMonitor(String metric);

/**
* Adds the given metric to the list of metrics to request on the next interval.
* @param metric Enum of the metric to request
*/
void addMonitor(Metric metric);

/**
* Attaches a listener to the specified metric. Starts monitoring the metric if
* the monitor doesn't already
* @param metric Name of the metric to attach the listener to
* @param listener The listener to be added
*/
void addListener(String metric, Listener listener);

/**
* Attaches a listener to the specified metric. Starts monitoring the metric if
* the monitor doesn't already
* @param metric Enum of the metric to attach the listener to
* @param listener The listener to be added
*/
void addListener(Metric metric, Listener listener);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* A class the represents data from the system monitor
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public class Info {
private HashMap<String, Object> content;

public Info() {
content = new HashMap<>();
guarantee();
}

/**
* Populates the required fields with empty strings, making sure that the required fields exist
*/
private void guarantee() {
for (String s : requiredFields()) {
content.put(s, "");
}
}

/**
* Returns a list of fields guaranteed to exist for this data.
* @return String array of the names of the guaranteed fields
*/
public String[] requiredFields() {
return new String[0];
}

/**
* Returns whether this Info contains the specified field.
* @param field Name of the field to look for
* @return True if this info contains the field; false otherwise.
*/
public boolean containsField(String field) {
return content.containsKey(field);
}

/**
* Adds a field and a value to the instance. Both the field and the value cannot be null.
* @param field Name of the field to add
* @param value Value of the field
*/
public void add(String field, Object value) {
if (field == null || value == null) {
throw new NullPointerException("Field and value cannot be null");
}
content.put(field, value);
}

/**
* Returns the value of the field given as a String, or an empty string if the field doesn't exist.
* @param field Name of the field to find
* @return Value of the field as a string, or null if the field doesn't exist
*/
public String getAsString(String field) {
if (content.containsKey(field)) {
return content.get(field).toString();
}
return "";
}

/**
* Returns the value of the field given as a long, or 0 if the field doesn't exist.
* @param field Name of the field to find
* @return value of the field as a Long, or null if the field doesn't exist
*/
public long getAsLong(String field) {
if (content.containsKey(field) && (content.get(field) instanceof Long)) {
return (Long) content.get(field);
}
return 0;
}

/**
* Returns the value of the field given as a double, or 0 if the field doesn't exist.
* @param field Name of the field to find
* @return value of the field as a double, or null if the field doesn't exist
*/
public double getAsDouble(String field) {
if (content.containsKey(field) && (content.get(field) instanceof Double)) {
return (Double) content.get(field);
}
return 0;
}

/**
* Returns all data in this Info as a map.
* @return Map representation of all data
*/
public Map<String, Object> getMap() {
return Collections.unmodifiableMap(content);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

/**
* A listener interface for receiving data from the system monitor.
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public interface Listener {

/**
* Called when no data is available for the requested metric.
*/
void onNotAvailable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

/**
* An empty interface that all metric enums are required to implement.
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public interface Metric {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

/**
* An Enum class specifying the metrics that all implementation of sysmon API are required to supply.
*
* @author Hyun Jung (hyju@seas.upenn.edu)
*/
public enum MetricType implements Metric {
CONNECTIONS,
CHANNELS,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.upenn.cis.precise.openicelite.coreapps.sysmon.api;

import static org.junit.Assert.*;

public class InfoTest {

}
11 changes: 11 additions & 0 deletions core_apps/sysmon/mqtt/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
group 'edu.upenn.cis.precise.openicelite.coreapps.sysmon'

dependencies {
compile project(':core_apps:sysmon:api')
compile 'org.apache.httpcomponents:httpclient:4.5.5'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.23.1'

testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'org.apache.httpcomponents:httpclient:4.5.5:tests'
}
Loading