forked from kuenishi/fluent-plugin-riak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.html
178 lines (168 loc) · 5.07 KB
/
browser.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<html>
<head>
<title>Riak mapreducer</title>
<style type="text/css">
body {
background: #678; text-align: center; width: 100%; font-family: 'Titillium', Monospace;
}
body div {
width: 80%; background: #ddd;
padding: 20px; text-align: left; margin: 0px auto;
}
h2 {
padding: 0px;
margin: 0px auto;
}
a {
text-shadow: 1px 1px #888888;
text-decoration:underline;
}
</style>
<script lang="JavaScript">
function get_map(){ return document.getElementById("map").value; }
function get_reduce(){ return document.getElementById("reduce").value; }
function get_bucketname(){ return document.getElementById("bucket").value; }
function exec_query(m, r){
var q = { inputs : get_bucketname(),
query : [
{ map: { language: "javascript", source: m}},
{ reduce: { language: "javascript", source: r}}
]};
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "/mapred", false);
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify(q, null, ""));
var result = xmlhttp.responseText;
var resultBox = document.getElementById("result");
resultBox.innerText = result;
}
</script>
</head>
<body>
<div id="content">
<div style="text-align:right">
<script lang="JavaScript">
</script>
bucket name:<input type="text" id="bucket" value="fluentlog"/>
</div>
<h2>Run mapreduce on fluentd log</h2>
<table style="border: 1px solid black;">
<tr>
<th>map</th> <th>reduce</th>
</tr>
<tr>
<td>
<textarea name="map" id="map" rows="16" cols="50">
function(v){
var data = v.values[0].data;
var c = JSON.parse(data);
return [c.count];
}
</textarea>
</td><td>
<textarea name="reduce" id="reduce" rows="16" cols="50" >
function(v){
var sum = 0;
for( var i=0; i < v.length; ++i){
sum += v[i];
}
return [sum];
}
</textarea>
</td>
</tr>
<tr>
<th colspan="2"> <a onClick="exec_query(get_map(), get_reduce());">query</a> </th>
</tr>
<tr>
<td width="200px" colspan="2">
<div id="result" style="font: bold;"></div>
</td>
</tr>
<tr><td colspan="3">
<script lang="JavaScript">
function grep(){
}
</script>
<script lang="JavaScript" type="text/javascript">
function count_rank(){
var m = "function(v){
var data = v.values[0].data;
var c = JSON.parse(data);
var tags = {};
for(var i=0; i<c.length; ++i){
count = tags[c[i].tag];
if(count == null){ tags[c[i].tag] = 1; }
else{ tags[c[i].tag] = count+1; }
}
return [tags];
}";
var r = "function(v){
var tags = {};
for(var i=0; i<v.length; ++i){
for (var prop in v[i]) {
count = tags[prop];
if(count == null){ tags[prop] = v[i][prop]; }
else{ tags[prop] = count+v[i][prop]; }
}
}
return [tags];
}";
exec_query(m, r);
}
</script>
<!-- <a onClick="grep();">grep</a> <input type="text" id="grep" value="debug"/> -->
<a onClick="count_rank();">count&rank</a> <input type="text" id="count_rank" value="tag"/>
</td></tr>
</table>
<hr/>
<h2>Riak object viewer</h2>
<script lang="JavaScript">
function get(){
var key = document.getElementById("key").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "/buckets/"+ get_bucketname() +"/keys/"+key, false);
xmlhttp.send();
var result = xmlhttp.responseText;
console.log(result);
document.getElementById("object").innerText = result;
}
</script>
<a onClick="get();" >get</a> <input type="text" id="key" />
<div id="object"></div>
<h2>Riak keylister</h2>
<script lang="JavaScript">
function listkeys(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "/buckets/"+ get_bucketname() +"/keys?keys=true", false);
xmlhttp.send();
var result = JSON.parse(xmlhttp.responseText);
console.log(result);
document.getElementById("keylist").innerText = result.keys.sort().join("\n");
}
</script>
<a onClick="listkeys();" >listkeys</a>
<div id="keylist"></div>
<hr/>
(C)@kuenishi distributed under Apache 2 license
</div>
<!--
<h2>Riak object putter</h2>
<script lang="JavaScript">
function put(){
var key = document.getElementById("key2").value;
var value = document.getElementById("value").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("PUT", "/buckets/fluentlog/keys/"+key, false);
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(value);
var result = xmlhttp.responseText;
console.log(result);
document.getElementById("object2").innerText = result;
}
</script>
<a onClick="put();" >put</a> <input type="text" id="key2" /> <input type="text" id="value" />
<div id="object2"></div>
-->
</body>
</html>