オンメモリKVSサーバーが欲しくなって、コード書きました。
特徴としてはこんな感じです。
- golang
- HTTP REST APIなので、クライアントはcurlとかでも大丈夫
- オンメモリで高速動作
- スレッドセーフ
- 一応管理機能もついてる
…で、これで何がしたかったの?という話なのですが、fluentdのデータをダッシュボードで可視化する時のストレージにしたかった、ということなのです。べんり。
aws s3 cp s3://[bucket-name] [local-dir] \
--recursive \
--exclude "*" \
--include "*2015-04-*"
module Fluent
class HttpHealthCheckInput < HttpInput
Plugin.register_input('http_healthcheck', self)
def on_request(path_info, params)
begin
return ["200 OK", {'Content-type'=>'text/plain'}, ":) < Hello!"]
end
end
end
end
<source> type http_healthcheck port 8889 bind 0.0.0.0 </source> <source> type http port 8888 bind 0.0.0.0 body_size_limit 32m keepalive_timeout 10s </source>
root@hoge:/etc/google-fluentd/catch-all-inputs.d# curl http://localhost:8889 :) < Hello! root@hoge:/etc/google-fluentd/catch-all-inputs.d# curl http://localhost:8888 400 Bad Request 'json' or 'msgpack' parameter is required
upstream backend {
server [proxy先URL];
}
server {
listen 80 default;
server_name 127.0.0.1 localhost;
location / {
content_by_lua '
local STR = "/check"..ngx.var.uri
local res = ngx.location.capture(STR)
if res.status == ngx.HTTP_OK then
ngx.say(res.body)
else
ngx.sleep(1)
res = ngx.location.capture("/check")
ngx.say(res.body)
end
';
}
location /check {
internal;
rewrite /check/(.*) /$1 break;
proxy_pass http://backend/;
}
}