You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iota.apache.org by to...@apache.org on 2016/09/28 01:19:17 UTC

[07/10] incubator-iota git commit: New feature: Implement simple monitoring: Simple monitoring keeps track only of the latest event for each actor - Reason: Less memory usage, specially when using routers

New feature: Implement simple monitoring: Simple monitoring keeps track only of the latest event for each actor
- Reason: Less memory usage,  specially when using routers


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/adf71bb1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/adf71bb1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/adf71bb1

Branch: refs/heads/master
Commit: adf71bb1d84f6397a315dfc7b042b351201a47ae
Parents: 2135e87
Author: Barbara Gomes <ba...@gmail.com>
Authored: Fri Jul 29 12:35:23 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Fri Jul 29 12:35:23 2016 -0700

----------------------------------------------------------------------
 fey-core/src/main/resources/application.conf    | 11 +++++
 .../scala/org/apache/iota/fey/Monitor.scala     | 48 +++++++++++++++++++-
 .../scala/org/apache/iota/fey/MyService.scala   | 10 +++-
 .../main/scala/org/apache/iota/fey/Utils.scala  | 26 ++++++-----
 4 files changed, 81 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/adf71bb1/fey-core/src/main/resources/application.conf
----------------------------------------------------------------------
diff --git a/fey-core/src/main/resources/application.conf b/fey-core/src/main/resources/application.conf
index a1193af..a80f13e 100644
--- a/fey-core/src/main/resources/application.conf
+++ b/fey-core/src/main/resources/application.conf
@@ -83,6 +83,17 @@ fey-global-configuration{
     // No default custom implementations
   }
 
+  // Configure monitoring options. If enabled the actors events will be stored
+  // together with other information, and the user should be able to visualize
+  // using the rest-api.
+  // Types:
+  //    COMPLETE: Keeps track of all the events for all of the actors. Backed by a Trie data structure
+  //    SIMPLE: Keeps track only of the latest event for each actor. Backed by HashMap
+  monitoring{
+    enable = true,
+    type = "COMPLETE"
+  }
+
 }
 
 // Fey akka configuration. Can not be overwritten by user

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/adf71bb1/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala b/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
index 2de05b9..ded1c9f 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
@@ -32,12 +32,22 @@ protected class Monitor(eventsStore: Trie) extends Actor {
   val log: DiagnosticLoggingAdapter = Logging(this)
   log.mdc(Map("fileName" -> "monitor_events"))
 
+
+  override def preStart(): Unit = {
+    if(CONFIG.MONITORING_ENABLED) {
+      if (CONFIG.MONITORING_TYPE == "SIMPLE") {
+        context.become(simple)
+      } else {
+        context.become(complete)
+      }
+    }
+  }
+
   override def postStop(): Unit = {
     log.clearMDC()
   }
 
-  override def receive: Receive = {
-
+  private def complete: Receive = {
     case START(timestamp, info) =>
       logInfo(sender().path.toString, EVENTS.START, timestamp, info)
       eventsStore.append(sender().path.toString,MonitorEvent(EVENTS.START, timestamp, info))
@@ -53,7 +63,28 @@ protected class Monitor(eventsStore: Trie) extends Actor {
     case TERMINATE(actorPath, timestamp, info) =>
       logInfo(actorPath, EVENTS.TERMINATE, timestamp, info)
       eventsStore.append(actorPath,MonitorEvent(EVENTS.TERMINATE, timestamp, info))
+  }
+
+  private def simple: Receive = {
+    case START(timestamp, info) =>
+      logInfo(sender().path.toString, EVENTS.START, timestamp, info)
+      Monitor.simpleEvents.put(sender().path.toString, ('S',timestamp))
 
+    case STOP(timestamp, info) =>
+      logInfo(sender().path.toString, EVENTS.STOP, timestamp, info)
+      Monitor.simpleEvents.put(sender().path.toString, ('O',timestamp))
+
+    case RESTART(reason, timestamp) =>
+      logInfo(sender().path.toString, EVENTS.RESTART, timestamp, "", reason)
+      Monitor.simpleEvents.put(sender().path.toString, ('R',timestamp))
+
+    case TERMINATE(actorPath, timestamp, info) =>
+      logInfo(actorPath, EVENTS.TERMINATE, timestamp, info)
+      Monitor.simpleEvents.put(actorPath, ('T',timestamp))
+  }
+
+  override def receive: Receive = {
+    case _ =>
   }
 
   def logInfo(path:String, event:String, timestamp: Long, info:String, reason:Throwable = null) = {
@@ -80,6 +111,7 @@ protected object Monitor{
     * Contains the lifecycle events for actors in Fey
     */
   val events: Trie = new Trie("FEY-MANAGEMENT-SYSTEM")
+  val simpleEvents:scala.collection.mutable.HashMap[String,(Char, Long)] = scala.collection.mutable.HashMap.empty
 
   //Static HTML content from d3
   val html = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/eventsTable.html"), "UTF-8")
@@ -100,6 +132,18 @@ protected object Monitor{
     }).flatten
   }
 
+  def getSimpleHTMLEvents: String = {
+    val content = simpleEvents.map(event => {
+      event._2._1 match {
+        case 'S' => getTableLine(event._1, event._2._2, "START", "")
+        case 'O' => getTableLine(event._1, event._2._2, "STOP", "")
+        case 'R' => getTableLine(event._1, event._2._2, "RESTART", "")
+        case 'T' => getTableLine(event._1, event._2._2, "TERMINATE", "")
+      }
+    }).mkString("\n")
+    html.replace("$EVENTS_TABLE_CONTENT", content)
+  }
+
   private def getTableLine(path: String,timestamp: Long, event: String, info: String):String = {
     s"<tr><td>$path</td><td>$event</td><td>$info</td><td>$timestamp</td></tr>"
   }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/adf71bb1/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala b/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
index 0935c5b..f686321 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
@@ -70,7 +70,15 @@ sealed trait MyService extends HttpService {
         get{
           respondWithMediaType(`text/html`) {
             complete {
-              Monitor.getHTMLevents
+              try {
+                if(CONFIG.MONITORING_TYPE == "COMPLETE") {
+                  Monitor.getHTMLevents
+                }else{
+                  Monitor.getSimpleHTMLEvents
+                }
+              }catch {
+                case e: Exception => ""
+              }
             }
           }
         }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/adf71bb1/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
index 8a0f36d..095785b 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
@@ -217,6 +217,8 @@ object CONFIG{
   var DYNAMIC_JAR_REPO = ""
   var DYNAMIC_JAR_FORCE_PULL = false
   var CUSTOM_DISPATCHERS: ConfigValue = null
+  var MONITORING_ENABLED: Boolean = true
+  var MONITORING_TYPE: String = "COMPLETE"
 
   def loadUserConfiguration(path: String) : Unit = {
 
@@ -230,17 +232,19 @@ object CONFIG{
       }
     }.getConfig("fey-global-configuration").resolve()
 
-      CHECKPOINT_DIR = app.getString("checkpoint-directory")
-      JSON_REPOSITORY = app.getString("json-repository")
-      JSON_EXTENSION = app.getString("json-extension")
-      JAR_REPOSITORY = app.getString("jar-repository")
-      CHEKPOINT_ENABLED = app.getBoolean("enable-checkpoint")
-      LOG_LEVEL = app.getString("log-level").toUpperCase()
-      LOG_APPENDER = app.getString("log-appender").toUpperCase()
-      MESSAGES_PER_RESIZE = app.getInt("auto-scale.messages-per-resize")
-      DYNAMIC_JAR_REPO = app.getString("dynamic-jar-population.downloaded-repository")
-      DYNAMIC_JAR_FORCE_PULL = app.getBoolean("dynamic-jar-population.force-pull")
-      CUSTOM_DISPATCHERS = app.getValue("custom-dispatchers")
+    CHECKPOINT_DIR = app.getString("checkpoint-directory")
+    JSON_REPOSITORY = app.getString("json-repository")
+    JSON_EXTENSION = app.getString("json-extension")
+    JAR_REPOSITORY = app.getString("jar-repository")
+    CHEKPOINT_ENABLED = app.getBoolean("enable-checkpoint")
+    LOG_LEVEL = app.getString("log-level").toUpperCase()
+    LOG_APPENDER = app.getString("log-appender").toUpperCase()
+    MESSAGES_PER_RESIZE = app.getInt("auto-scale.messages-per-resize")
+    DYNAMIC_JAR_REPO = app.getString("dynamic-jar-population.downloaded-repository")
+    DYNAMIC_JAR_FORCE_PULL = app.getBoolean("dynamic-jar-population.force-pull")
+    CUSTOM_DISPATCHERS = app.getValue("custom-dispatchers")
+    MONITORING_ENABLED = app.getBoolean("monitoring.enable")
+    MONITORING_TYPE = app.getString("monitoring.type").toUpperCase()
 
     setLogbackConfiguration()
   }