diff --git a/agent/src/main/scala/se/callista/loganalyzer/agent/LogAgent.scala b/agent/src/main/scala/se/callista/loganalyzer/agent/LogAgent.scala index f5eba97..57d8d63 100644 --- a/agent/src/main/scala/se/callista/loganalyzer/agent/LogAgent.scala +++ b/agent/src/main/scala/se/callista/loganalyzer/agent/LogAgent.scala @@ -6,7 +6,10 @@ import akka.actor.{Actor, ActorRef, ActorLogging} import akka.util.duration._ import se.callista.loganalyzer.{AccessLog, ConfirmationMessage, LogMessage, HandleUnprocessedLogs} -class LogAgent(hostname: String, server: ActorRef) extends Actor with ActorLogging { +class LogAgent( + val hostname: String, // hostname of the agent + val server: ActorRef // actor reference to the log service + ) extends Actor with ActorLogging { def receive = { case None => // replace this row diff --git a/common/src/main/scala/se/callista/loganalyzer/AccessLog.scala b/common/src/main/scala/se/callista/loganalyzer/AccessLog.scala new file mode 100644 index 0000000..b8f2784 --- /dev/null +++ b/common/src/main/scala/se/callista/loganalyzer/AccessLog.scala @@ -0,0 +1,18 @@ +package se.callista.loganalyzer + +import java.text.SimpleDateFormat +import java.util.Date + +case class AccessLog( + ip: String, + timestamp: Date, + method: String, + path: String, + statusCode: Int, + size: Int) { + + override def toString = { + val formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z") + ip + " - - [" + formatter.format(timestamp) + "] " + method + " " + path + " " + statusCode + " " + size + } +} diff --git a/common/src/main/scala/se/callista/loganalyzer/ConfirmationMessage.scala b/common/src/main/scala/se/callista/loganalyzer/ConfirmationMessage.scala new file mode 100644 index 0000000..e7ddcb6 --- /dev/null +++ b/common/src/main/scala/se/callista/loganalyzer/ConfirmationMessage.scala @@ -0,0 +1,3 @@ +package se.callista.loganalyzer + +case class ConfirmationMessage(id: Int) \ No newline at end of file diff --git a/common/src/main/scala/se/callista/loganalyzer/Count.scala b/common/src/main/scala/se/callista/loganalyzer/Count.scala index 53e5930..0f3e730 100644 --- a/common/src/main/scala/se/callista/loganalyzer/Count.scala +++ b/common/src/main/scala/se/callista/loganalyzer/Count.scala @@ -1,23 +1,9 @@ package se.callista.loganalyzer case class Count( - status: HttpStatus, + status: HttpStatus, // Success, ClientError or ServerError count: Int) { def toJson = "{ \"status\":\"%s\", \"count\": %s }".format(status, count) } - -abstract class HttpStatus - -case object Success extends HttpStatus { - override def toString = "success" -} - -case object ClientError extends HttpStatus{ - override def toString = "clientError" -} - -case object ServerError extends HttpStatus{ - override def toString = "serverError" -} diff --git a/common/src/main/scala/se/callista/loganalyzer/HandleUnprocessedLogs.scala b/common/src/main/scala/se/callista/loganalyzer/HandleUnprocessedLogs.scala new file mode 100644 index 0000000..adedaea --- /dev/null +++ b/common/src/main/scala/se/callista/loganalyzer/HandleUnprocessedLogs.scala @@ -0,0 +1,6 @@ +package se.callista.loganalyzer + +/** + * Use this object to trigger LogAgent to handle unprocessed logs + */ +case object HandleUnprocessedLogs \ No newline at end of file diff --git a/common/src/main/scala/se/callista/loganalyzer/HttpStatus.scala b/common/src/main/scala/se/callista/loganalyzer/HttpStatus.scala new file mode 100644 index 0000000..befced0 --- /dev/null +++ b/common/src/main/scala/se/callista/loganalyzer/HttpStatus.scala @@ -0,0 +1,15 @@ +package se.callista.loganalyzer + +abstract class HttpStatus + +case object Success extends HttpStatus { + override def toString = "success" +} + +case object ClientError extends HttpStatus{ + override def toString = "clientError" +} + +case object ServerError extends HttpStatus{ + override def toString = "serverError" +} diff --git a/common/src/main/scala/se/callista/loganalyzer/LogMessage.scala b/common/src/main/scala/se/callista/loganalyzer/LogMessage.scala index 31c311d..828bbe7 100644 --- a/common/src/main/scala/se/callista/loganalyzer/LogMessage.scala +++ b/common/src/main/scala/se/callista/loganalyzer/LogMessage.scala @@ -3,23 +3,4 @@ package se.callista.loganalyzer import java.util.Date import java.text.SimpleDateFormat -case class AccessLog( - ip: String, - timestamp: Date, - method: String, - path: String, - statusCode: Int, - size: Int) { - - - override def toString = { - val formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z") - ip + " - - [" + formatter.format(timestamp) + "] " + method + " " + path + " " + statusCode + " " + size - } -} - -case class LogMessage(host: String, id: Int, log: AccessLog) - -case class ConfirmationMessage(id: Int) - -case object HandleUnprocessedLogs \ No newline at end of file +case class LogMessage(host: String, id: Int, log: AccessLog) \ No newline at end of file diff --git a/server/src/main/scala/se/callista/loganalyzer/server/Database.scala b/server/src/main/scala/se/callista/loganalyzer/server/Database.scala index 777cc17..c665707 100644 --- a/server/src/main/scala/se/callista/loganalyzer/server/Database.scala +++ b/server/src/main/scala/se/callista/loganalyzer/server/Database.scala @@ -22,7 +22,7 @@ abstract class Database { def latestTwenty: Seq[AccessLog] = { (for( (_,keys) <- timeline.takeRight(20); key <- keys) yield logs(key) ).toList.take(20) } -} +} object StableDatabase extends Database diff --git a/server/src/main/scala/se/callista/loganalyzer/server/LogServer.scala b/server/src/main/scala/se/callista/loganalyzer/server/LogServer.scala index 6fc939e..95b32b4 100644 --- a/server/src/main/scala/se/callista/loganalyzer/server/LogServer.scala +++ b/server/src/main/scala/se/callista/loganalyzer/server/LogServer.scala @@ -4,7 +4,9 @@ import akka.actor._ import akka.actor.SupervisorStrategy.Restart import se.callista.loganalyzer._ -class LogServer(presenter: ActorRef) extends Actor with ActorLogging { +class LogServer( + val presenter: ActorRef // actor reference to the presenter + ) extends Actor with ActorLogging { def receive = { case None => // replace this row diff --git a/server/src/main/scala/se/callista/loganalyzer/server/StatusCounter.scala b/server/src/main/scala/se/callista/loganalyzer/server/StatusCounter.scala index f5eed7b..adaae7b 100644 --- a/server/src/main/scala/se/callista/loganalyzer/server/StatusCounter.scala +++ b/server/src/main/scala/se/callista/loganalyzer/server/StatusCounter.scala @@ -4,7 +4,10 @@ import scala.collection.mutable.HashSet import akka.actor.{Actor, ActorLogging, ActorRef} import se.callista.loganalyzer.{Count, HttpStatus, LogMessage} -class StatusCounter(status: HttpStatus, presenter: ActorRef) extends Actor with ActorLogging { +class StatusCounter( + val status: HttpStatus, // HTTP Status (Success, ClientError or ServerError) + val presenter: ActorRef // actor reference to the presenter + ) extends Actor with ActorLogging { def receive = { case None => // replace this row diff --git a/server/src/main/scala/se/callista/loganalyzer/server/WebSocketPresenter.scala b/server/src/main/scala/se/callista/loganalyzer/server/WebSocketPresenter.scala index d7b56ea..d4ac11a 100644 --- a/server/src/main/scala/se/callista/loganalyzer/server/WebSocketPresenter.scala +++ b/server/src/main/scala/se/callista/loganalyzer/server/WebSocketPresenter.scala @@ -2,8 +2,7 @@ package se.callista.loganalyzer.server import scala.collection.mutable.Map import akka.actor.Actor -import se.callista.loganalyzer.Count -import se.callista.loganalyzer.HttpStatus +import se.callista.loganalyzer.{Count, HttpStatus} import unfiltered.netty.websockets.WebSocket /**