Skip to content

Commit

Permalink
add monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamori committed Nov 9, 2011
1 parent 19ff923 commit 030babc
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wakamori/dscript/converter/converter.k → wakamori/dscript/converter/converter 100644 → 100755
@@ -1,3 +1,5 @@
#!/usr/local/bin/konoha

void main(String[] args)
{
assert |args| == 1;
Expand Down
6 changes: 6 additions & 0 deletions wakamori/dscript/monitor/kick.k
@@ -0,0 +1,6 @@
using konoha.actor.*;

a = actor:localhost:2000;
a.startTask("foo");
a.eval("print \"hi\"");
a.endTask();
65 changes: 65 additions & 0 deletions wakamori/dscript/monitor/logcache.k
@@ -0,0 +1,65 @@
using konoha.memcached.*;
using konoha.json.*;

class Log {
String time;
String host;
int pid;
String trace;
String name;
Map val;

Log(String time, String host, int pid, String trace, String name, Map val) {
_time = time;
_host = host;
_pid = pid;
_trace = trace;
_name = name;
_val = val;
}
}

class Logcache {
Memcache mcd;
String trace;
//String log_name;
int ctxid;
Map<int> seq;
}

Logcache Logcache.new(String host, int port, String task_name) {
_mcd = new Memcache(host, port);
_trace = mcd[task_name];
if (trace == null) throw new Script!!("cannot trace " + task_name);
_task_name = task_name;
//_log_name = log_name;
_ctxid = 0;
_seq = {};
}

Log Logcache.readLog() {
String key;
String line;
int i = seq[trace];
key = trace + "+" + i;
//print key;
//print log_name;
//line = mcd.getByKey(log_name, key);
line = mcd[key];
if (line == null) return null;

//print line;
String[] e = line.split(" ");
String logname = e[6];
//print logname;
String json = line.substring(line.indexOf(logname) + |logname| + 1);
//print json;

//print line;
seq[trace] += 1;
//print e[4];
int port = (to int)e[4].replace($/konoha\[(\d+)\]:/, "$1");
Map m = ((to Bytes)json).readJson(0, |json|);
Log l = new Log(line.substring(0, line.indexof(e[3]) - 1), e[3], port, e[5], e[6], m);
return l;
}
11 changes: 11 additions & 0 deletions wakamori/dscript/monitor/test.k
@@ -0,0 +1,11 @@
include "logcache.k"

void main(String[] args)
{
l = new Logcache("localhost", 11211, "foo");
Log log = l.readLog();
while (log.val != null) {
print log;
log = l.readLog();
}
}

0 comments on commit 030babc

Please sign in to comment.