Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added monitoring for sevaks
  • Loading branch information
amitrathore committed May 22, 2009
1 parent 18737c8 commit afbce7e
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "lib/clojure/clj-record"]
path = lib/clojure/clj-record
url = git://github.com/duelinmarkers/clj-record.git
11 changes: 11 additions & 0 deletions db/init.sql
@@ -0,0 +1,11 @@
drop database if exists swarmiji_development;
drop database if exists swarmiji_test;
drop database if exists swarmiji_staging;
drop database if exists swarmiji_sandbox;
drop database if exists swarmiji_production;

create database swarmiji_development;
create database swarmiji_test;
create database swarmiji_staging;
create database swarmiji_sandbox;
create database swarmiji_production;
33 changes: 33 additions & 0 deletions db/schema.rb
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

require "rubygems"
require "activerecord"

def usage
puts "Swarmiji DB creator."
puts "Usage: schema.rb db-host[localhost|remote.runa.com|etc] db-environment [development|test|production|staging|etc.]"
end

puts "ARGV.length: #{ARGV.length} ARGV: #{ARGV.inspect}"

if ARGV.length != 2
usage
exit -1
end

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => ARGV[0],
:database => "swarmiji_#{ARGV[1]}",
:username => "root",
:password => "password"
)

ActiveRecord::Base.connection.instance_eval do
create_table "control_messages", :force => true do |t|
t.string "sevak_server_pid", "message_type", "sevak_name", "sevak_args", "sevak_time", "messaging_time", "return_q_name"
t.timestamps
end
end

puts "Created swarmiji_#{ARGV[1]} schema on #{ARGV[0]}."
47 changes: 47 additions & 0 deletions fujure.sh
@@ -0,0 +1,47 @@
#!/bin/sh

# Please make sure to configure ~/.clojure.conf or /etc/clojure.conf
# sample configuration can be found at clojure.conf.sample
#
# Note, running this script will:
# - Run ~/.clojurerc on boot up (if exists)
# - Add all .jar files within clj_ext (~/.clojure on default)
# to the classpath
#
#

if [ ! -f /etc/clojure.conf -a ! -f /mnt/furtive/clojure.conf -a ! -f ~/.clojure.conf ]; then
echo "Error: No config not found at /etc/clojure.conf or ~/.clojure.conf."
echo " Please provide one before starting this script."
echo " A sample can be found in the emacs-clojure repository named "
echo " clojure.conf.sample"
exit
fi


# Whether to load the repl or script
if [ -z "$1" ]; then
clj_class=clojure.lang.Repl
else
clj_class=clojure.lang.Script
fi

echo "SWARMIJI_HOME is ${SWARMIJI_HOME}"
echo "SWARMIJI_ENV is ${SWARMIJI_ENV}"

swarmiji_jars="${SWARMIJI_HOME}/lib/java"
swarmiji_clj="${SWARMIJI_HOME}/src/:${SWARMIJI_HOME}/lib/clojure/clj-record/src/"

clj_cp="."
[ -f /etc/clojure.conf ] && . /etc/clojure.conf
[ -f /mnt/furtive/clojure.conf ] && . /mnt/furtive/clojure.conf
[ -f ~/.clojure.conf ] && . ~/.clojure.conf
[ -f ~/.clojurerc ] && clj_rc=~/.clojurerc
clj_cp="${clj_cp}:${swarmiji_jars}/*:${swarmiji_clj}/:${clj_ext}/*"

if [ -n "${clj_lib}" ]; then
export LD_LIBRARY_PATH=${clj_lib}:$LD_LIBRARY_PATH
fi

echo exec java -Xms256m -Xmx512m -server -Dpid=$$ ${clj_opts} -cp ${clj_cp}:${clj} ${clj_wrapper} ${clj_class} ${clj_rc} $*
exec java -Xms256m -Xmx512m -server -Dpid=$$ ${clj_opts} -cp ${clj_cp}:${clj} ${clj_wrapper} ${clj_class} ${clj_rc} $1 -- $*
1 change: 1 addition & 0 deletions lib/clojure/clj-record
Submodule clj-record added at c8d124
Binary file added lib/java/mysql-connector-java-5.1.7-bin.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions src/org/runa/swarmiji/monitor/control_message.clj
@@ -0,0 +1,6 @@
(ns org.runa.swarmiji.monitor.control_message
(:require clj-record.boot)
(:use [org.runa.swarmiji.config.system-config]))

(def db (swarmiji-mysql-config))
(clj-record.core/init-model)
24 changes: 24 additions & 0 deletions src/org/runa/swarmiji/monitor/recorder.clj
@@ -0,0 +1,24 @@
(ns org.runa.swarmiji.monitor.recorder
(:use [org.runa.swarmiji.mpi.transport])
(:use [org.runa.swarmiji.config.system-config])
(:use [org.runa.swarmiji.utils.logger])
(:use [org.runa.swarmiji.monitor.control_message :as control-message])
(:import (java.sql Date Time)))

(defn timestamp-for-sql [time-in-millis]
(str (.toString (Date. time-in-millis)) " " (.toString (Time. time-in-millis))))

(defn persist-message [control-message]
(log-message "control-message:" control-message)
(let [now (timestamp-for-sql (System/currentTimeMillis))
with-timestamps (merge {:created_at now :updated_at now} control-message)]
(control-message/insert with-timestamps)))

(defn start []
(let [client (new-queue-client)
q-name (queue-diagnostics-q-name)
handler (queue-message-handler-for-function persist-message)]
(log-message "Swarmiji: Starting Control-Message-Recorder...")
(log-message "Listening on:" q-name)
(.subscribe client q-name handler)))

3 changes: 3 additions & 0 deletions utils/start_recorder.clj
@@ -0,0 +1,3 @@
(use 'org.runa.swarmiji.monitor.recorder)

(start)

0 comments on commit afbce7e

Please sign in to comment.