Commit 087dc483 authored by Qianwen's avatar Qianwen
Browse files

add behavior topic

parent 465c68da
......@@ -69,6 +69,9 @@ func task(ag *agency.Agent) (err error) {
msg, _ := ag.ACL.NewMessage(recv, 0, 0, "test message")
ag.ACL.SendMessage(msg)
ag.Logger.NewLog("app", "This is agent "+strconv.Itoa(id), "")
time.Sleep(2 * time.Second)
ag.Logger.NewLog("beh", "This is the behavior of the agent"+strconv.Itoa(id), "")
ag.Logger.NewLog("debug", "This is the debug of the agent"+strconv.Itoa(id), "")
svc := schemas.Service{
Desc: "agent" + strconv.Itoa(id),
}
......
......@@ -390,6 +390,7 @@ data:
CREATE TABLE clonemap.logging_msg ( masid int, agentid int, t timestamp, log varchar, PRIMARY KEY ((masid, agentid), t)) WITH CLUSTERING ORDER BY (t ASC);
CREATE TABLE clonemap.logging_status ( masid int, agentid int, t timestamp, log varchar, PRIMARY KEY ((masid, agentid), t)) WITH CLUSTERING ORDER BY (t ASC);
CREATE TABLE clonemap.logging_debug ( masid int, agentid int, t timestamp, log varchar, PRIMARY KEY ((masid, agentid), t)) WITH CLUSTERING ORDER BY (t ASC);
CREATE TABLE clonemap.logging_beh ( masid int, agentid int, t timestamp, log varchar, PRIMARY KEY ((masid, agentid), t)) WITH CLUSTERING ORDER BY (t ASC);
CREATE TABLE clonemap.logging_series ( masid int, agentid int, name varchar, t timestamp, series varchar, PRIMARY KEY ((masid, agentid), name, t)) WITH CLUSTERING ORDER BY (name ASC, t ASC);
CREATE TABLE clonemap.state ( masid int, agentid int, state varchar, PRIMARY KEY (masid, agentid));
EOF
......
......@@ -13,7 +13,8 @@
"msg":true,
"app":true,
"status":true,
"debug":true
"debug":true,
"beh": true
}
},
"imagegroups":[
......
......@@ -271,7 +271,8 @@ func (logCol *LogCollector) storeLogs() (err error) {
if (logMsg.Topic == "msg" && !logCol.config.TopicMsg) ||
(logMsg.Topic == "app" && !logCol.config.TopicApp) ||
(logMsg.Topic == "debug" && !logCol.config.TopicDebug) ||
(logMsg.Topic == "status" && !logCol.config.TopicStatus) {
(logMsg.Topic == "status" && !logCol.config.TopicStatus) ||
(logMsg.Topic == "beh" && !logCol.config.TopicBeh) {
continue
}
logMsgs[index] = logMsg
......@@ -303,7 +304,8 @@ func (logCol *LogCollector) storeLogs() (err error) {
if (logMsg.Topic == "msg" && !logCol.config.TopicMsg) ||
(logMsg.Topic == "app" && !logCol.config.TopicApp) ||
(logMsg.Topic == "debug" && !logCol.config.TopicDebug) ||
(logMsg.Topic == "status" && !logCol.config.TopicStatus) {
(logMsg.Topic == "status" && !logCol.config.TopicStatus) ||
(logMsg.Topic == "beh" && !logCol.config.TopicBeh) {
continue
}
logCol.logInfo.Println(logMsg)
......@@ -392,7 +394,7 @@ func (agLog *AgentLogger) NewLog(topic string, message string, data string) (err
}
agLog.mutex.Unlock()
if topic != "error" && topic != "debug" && topic != "status" && topic != "msg" &&
topic != "app" {
topic != "app" && topic != "beh" {
err = errors.New("unknown topic")
return
}
......
......@@ -70,6 +70,7 @@ type cassStorage struct {
logErrorIn chan schemas.LogMessage // logging inbox
logDebugIn chan schemas.LogMessage // logging inbox
logMsgIn chan schemas.LogMessage // logging inbox
logBehIn chan schemas.LogMessage // logging inbox
stateIn chan schemas.State // state inbox
logSeriesIn chan schemas.LogSeries // logging inbox
}
......@@ -100,6 +101,10 @@ func (stor *cassStorage) addAgentLogMessage(log schemas.LogMessage) (err error)
stor.logAppIn <- log
// err = stor.session.Query("INSERT INTO logging_app (masid, agentid, t, log) "+
// "VALUES (?, ?, ?, ?)", masID, agentID, log.Timestamp, js).Exec()
case "beh":
stor.logBehIn <- log
// err = stor.session.Query("INSERT INTO logging_beh (masid, agentid, t, log) "+
// "VALUES (?, ?, ?, ?)", masID, agentID, log.Timestamp, js).Exec()
default:
err = errors.New("wrong topic")
}
......@@ -126,6 +131,9 @@ func (stor *cassStorage) getLatestAgentLogMessages(masID int, agentID int, topic
case "app":
iter = stor.session.Query("SELECT log FROM logging_app WHERE masid = ? AND "+
"agentid = ? LIMIT ?", masID, agentID, num).Iter()
case "beh":
iter = stor.session.Query("SELECT log FROM logging_beh WHERE masid = ? AND "+
"agentid = ? LIMIT ?", masID, agentID, num).Iter()
default:
err = errors.New("wrong topic")
}
......@@ -164,6 +172,9 @@ func (stor *cassStorage) getAgentLogMessagesInRange(masID int, agentID int, topi
case "app":
iter = stor.session.Query("SELECT log FROM logging_app WHERE masid = ? AND "+
"agentid = ? AND t > ? AND t < ?", masID, agentID, start, end).Iter()
case "beh":
iter = stor.session.Query("SELECT log FROM logging_beh WHERE masid = ? AND "+
"agentid = ? AND t > ? AND t < ?", masID, agentID, start, end).Iter()
default:
err = errors.New("wrong topic")
}
......@@ -306,6 +317,8 @@ func (stor *cassStorage) storeLogs(topic string) {
logIn = stor.logDebugIn
} else if topic == "msg" {
logIn = stor.logMsgIn
} else if topic == "beh" {
logIn = stor.logBehIn
} else {
return
}
......@@ -450,6 +463,7 @@ func newCassandraStorage(ip []string, user string, pass string) (stor storage, e
temp.logDebugIn = make(chan schemas.LogMessage, 10000)
temp.logErrorIn = make(chan schemas.LogMessage, 10000)
temp.logMsgIn = make(chan schemas.LogMessage, 10000)
temp.logBehIn = make(chan schemas.LogMessage, 10000)
temp.stateIn = make(chan schemas.State, 10000)
temp.logSeriesIn = make(chan schemas.LogSeries, 10000)
......@@ -459,6 +473,7 @@ func newCassandraStorage(ip []string, user string, pass string) (stor storage, e
go temp.storeLogs("error")
go temp.storeLogs("debug")
go temp.storeLogs("msg")
go temp.storeLogs("beh")
go temp.storeSeries()
go temp.storeState()
}
......
......@@ -117,6 +117,7 @@ type agentStorage struct {
msgLogs []schemas.LogMessage
statLogs []schemas.LogMessage
appLogs []schemas.LogMessage
behLogs []schemas.LogMessage
logSeries map[string][]schemas.LogSeries
state schemas.State
commData []schemas.Communication
......@@ -153,6 +154,9 @@ func (stor *localStorage) addAgentLogMessage(log schemas.LogMessage) (err error)
case "app":
stor.mas[log.MASID].agents[log.AgentID].appLogs = append(stor.mas[log.MASID].agents[log.AgentID].appLogs,
log)
case "beh":
stor.mas[log.MASID].agents[log.AgentID].behLogs = append(stor.mas[log.MASID].agents[log.AgentID].behLogs,
log)
default:
err = errors.New("wrong topic")
}
......@@ -202,6 +206,13 @@ func (stor *localStorage) getLatestAgentLogMessages(masID int, agentID int, topi
}
logs = make([]schemas.LogMessage, num)
copy(logs, stor.mas[masID].agents[agentID].appLogs[length-num:length])
case "beh":
length := len(stor.mas[masID].agents[agentID].behLogs)
if length < num {
num = length
}
logs = make([]schemas.LogMessage, num)
copy(logs, stor.mas[masID].agents[agentID].behLogs[length-num:length])
default:
err = errors.New("wrong topic")
}
......@@ -299,6 +310,22 @@ func (stor *localStorage) getAgentLogMessagesInRange(masID int, agentID int, top
copy(logs, stor.mas[masID].agents[agentID].appLogs[startIndex:endIndex])
}
}
case "beh":
length := len(stor.mas[masID].agents[agentID].behLogs)
if length > 0 {
startIndex := sort.Search(length,
func(i int) bool {
return stor.mas[masID].agents[agentID].behLogs[i].Timestamp.After(start)
})
endIndex := sort.Search(length,
func(i int) bool {
return stor.mas[masID].agents[agentID].behLogs[i].Timestamp.After(end)
})
if endIndex-startIndex >= 0 {
logs = make([]schemas.LogMessage, endIndex-startIndex)
copy(logs, stor.mas[masID].agents[agentID].behLogs[startIndex:endIndex])
}
}
default:
err = errors.New("wrong topic")
}
......@@ -385,6 +412,7 @@ func (stor *localStorage) deleteAgentLogMessages(masID int, agentID int) (err er
stor.mas[masID].agents[agentID].msgLogs = nil
stor.mas[masID].agents[agentID].statLogs = nil
stor.mas[masID].agents[agentID].appLogs = nil
stor.mas[masID].agents[agentID].behLogs = nil
}
}
stor.mutex.Unlock()
......
......@@ -55,6 +55,7 @@ type LoggerConfig struct {
TopicApp bool `json:"app,omitempty"` // activation of app log topic
TopicStatus bool `json:"status,omitempty"` // activation of status log topic
TopicDebug bool `json:"debug,omitempty"` // activation of debug log topic
TopicBeh bool `json:"beh,omitempty"` // activation of beh log topic
Host string `json:"host,omitempty"` // hostname of Logger
Port int `json:"port,omitempty"` // port of Logger
}
......@@ -64,7 +65,7 @@ type LogMessage struct {
MASID int `json:"masid"` // ID of MAS agent runs in
AgentID int `json:"agentid"` // ID of agent
Timestamp time.Time `json:"timestamp"` // time of message
Topic string `json:"topic"` // log type (error, debug, msg, status, app)
Topic string `json:"topic"` // log type (error, debug, msg, status, app, beh)
Message string `json:"msg"` // log message
AdditionalData string `json:"data,omitempty"` // additional information e.g in json
}
......
......@@ -295,6 +295,10 @@ text {
fill: rgb(56, 202, 221);
}
.beh {
fill: rgb(223, 170, 72);
}
.topics .selected {
color: white;
......@@ -330,6 +334,10 @@ text {
background-color: rgb(56, 202, 221) ;
}
.topics .beh-tag.selected {
background-color: rgb(223, 170, 72) ;
}
.log-series-graph {
margin-top: 50px;
width: 1200px;
......
......@@ -42,9 +42,12 @@
<li class="nav-item" >
<a class="nav-link" [class.active]="currState==='log'" (click)="onClickLog()" >log</a>
</li>
<li class="nav-item" style="padding-right:100px;">
<li class="nav-item">
<a class="nav-link" [class.active]="currState==='logSeries'" (click)="onClickLogSeries()">logSeries</a>
</li>
<li class="nav-item" style="padding-right:100px;">
<a class="nav-link" [class.active]="currState==='statistics'" (click)="onClickStatistics()">statistics</a>
</li>
</ul>
<div class="selectionBoard d-flex">
......@@ -159,6 +162,7 @@
<div [class.selected]="isTopicSelected[2]"class="msg-tag tag" (click)="onToggleTopic(2)">msg</div>
<div [class.selected]="isTopicSelected[3]" class="status-tag tag" (click)="onToggleTopic(3)">status</div>
<div [class.selected]="isTopicSelected[4]" class="app-tag tag" (click)="onToggleTopic(4)">app</div>
<div [class.selected]="isTopicSelected[5]" class="beh-tag tag" (click)="onToggleTopic(5)">beh</div>
</div>
......
......@@ -29,8 +29,8 @@ export class LoggerComponent implements OnInit {
// parameters and variables for drawing logs
searchStartTime: string = "20210301000000";
searchEndTime: string = "20210331000000"
isTopicSelected: boolean[] = [true, true, true, true, true];
topics: string[] = ["error", "debug", "msg", "status", "app"];
isTopicSelected: boolean[] = [true, true, true, true, true, true];
topics: string[] = ["error", "debug", "msg", "status", "app", "beh" ];
width: number = 1500;
height: number = 2000;
boxWidth: number = 100;
......@@ -466,4 +466,10 @@ export class LoggerComponent implements OnInit {
onDeactivate(data): void {
console.log('Deactivate', JSON.parse(JSON.stringify(data)));
}
/********************************* functions for drawing logs ************************************/
onClickStatistics() {
this.currState = "staticstics";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment