From 7673a0960473ed64dc68379715fd6b1eeaca18c6 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 7 Jul 2013 19:48:39 -0400 Subject: [PATCH] Goofing around with a POC Go -> Logstash setup --- logstash/.gitignore | 1 + logstash/Makefile | 2 ++ logstash/agent/Makefile | 19 +++++++++++++++++++ logstash/agent/conf/shipper.conf | 14 ++++++++++++++ logstash/crispy/main.go | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 logstash/.gitignore create mode 100644 logstash/Makefile create mode 100644 logstash/agent/Makefile create mode 100644 logstash/agent/conf/shipper.conf create mode 100644 logstash/crispy/main.go diff --git a/logstash/.gitignore b/logstash/.gitignore new file mode 100644 index 0000000..17fc145 --- /dev/null +++ b/logstash/.gitignore @@ -0,0 +1 @@ +/agent/lib/ diff --git a/logstash/Makefile b/logstash/Makefile new file mode 100644 index 0000000..db92b8c --- /dev/null +++ b/logstash/Makefile @@ -0,0 +1,2 @@ +run-crispy: + go run crispy/main.go diff --git a/logstash/agent/Makefile b/logstash/agent/Makefile new file mode 100644 index 0000000..19789e9 --- /dev/null +++ b/logstash/agent/Makefile @@ -0,0 +1,19 @@ +LOGSTASH_VERSION ?= 1.1.13 + +all: lib/logstash.jar + + +lib/logstash.jar: lib/logstash-$(LOGSTASH_VERSION)-flatjar.jar + pushd lib && ln -sv $(notdir $^) $(notdir $@) ; popd + + +lib/logstash-$(LOGSTASH_VERSION)-flatjar.jar: lib + pushd lib && \ + curl -L -O http://logstash.objects.dreamhost.com/release/logstash-$(LOGSTASH_VERSION)-flatjar.jar ; \ + popd + +lib: + mkdir -p $@ + +run-agent: all + java -jar lib/logstash.jar agent -f conf/shipper.conf diff --git a/logstash/agent/conf/shipper.conf b/logstash/agent/conf/shipper.conf new file mode 100644 index 0000000..f0c0505 --- /dev/null +++ b/logstash/agent/conf/shipper.conf @@ -0,0 +1,14 @@ +input { + tcp { + message_format => "json" + port => 55784 + type => "fried" + } +} + +output { + stdout { + debug => true + debug_format => "json" + } +} diff --git a/logstash/crispy/main.go b/logstash/crispy/main.go new file mode 100644 index 0000000..3f514e3 --- /dev/null +++ b/logstash/crispy/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "log" + "net/http" + "os" +) + +func main() { + server := newCrispyServer() + http.Handle("/", server) + log.Printf("Serving on :9764 with %+v\n", server) + log.Fatal(http.ListenAndServe(":9764", nil)) +} + +type crispyServer struct { + logstasher *log.Logger +} + +func newCrispyServer() *crispyServer { + return &crispyServer{ + logstasher: newLogstashLogger(), + } +} + +func (me *crispyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { + me.logstasher.Printf("%+v\n", r) +} + +func newLogstashLogger() *log.Logger { + return log.New(os.Stderr, "", 0) +}