kanshi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  ## Purpose
4
4
 
5
5
  Kanshi watches your Postgres database and reports metrics to the log
6
- stream. You can then drain this log to an application - or fork and
7
- modify kanshi itself - to send these metrics to a service, like Librato
8
- or Splunk.
6
+ stream. You can then drain this log to an application (or provide your
7
+ own reporter class) to send these metrics to a service, like Librato or
8
+ Splunk.
9
9
 
10
10
  ## Installation
11
11
 
@@ -37,6 +37,26 @@ of your choosing, e.g. monitor specific databases or provide your own
37
37
  reporter for output. An easy way to do this would be to create a Rake
38
38
  task to run Kanshi.
39
39
 
40
+ ## Configuration
41
+
42
+ If using the `kanshi` binary, configuration is optional but is done
43
+ through environment variables:
44
+
45
+ * Kanshi will monitor all `postgres://` URLs in your environment.
46
+ * `KANSHI_SAMPLE_DELAY` will change how often Kanshi monitors your
47
+ database in seconds. Default: 300
48
+ * `KANSHI_PREFIX` will change the prefix used on metrics. Default:
49
+ `kanshi`
50
+
51
+ Environment variables have no effect on the Kanshi library code, so if
52
+ executing Kanshi manually, configuration is done via the options hash
53
+ passed to `Kanshi.run`:
54
+
55
+ * `:databases`: A hash of database names to URLs ({String => String})
56
+ * `:delay`: The delay between samples (Fixnum). Default: 300.
57
+ * `:reporter`: A Class that responds to `#report` to recieve metrics
58
+ (Class). Default: `Kanshi::ScrollsReporter`.
59
+
40
60
  ## Name
41
61
 
42
62
  Kanshi (監視) is Japanese for _surveillance_.
data/bin/kanshi CHANGED
@@ -4,7 +4,15 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
4
 
5
5
  require 'kanshi'
6
6
 
7
+ databases = ENV.select { |k, v| v =~ %r{^postgres://} }.invert.invert
8
+ prefix = ENV['KANSHI_PREFIX'] || 'kanshi'
9
+ unless prefix.empty?
10
+ databases.keys.each do |db|
11
+ databases["#{prefix}.#{db}"] = databases.delete(db)
12
+ end
13
+ end
14
+
7
15
  Kanshi.run(
8
- :databases => ENV.select { |k, v| v =~ %r{^postgres://} }.invert.invert,
16
+ :databases => databases,
9
17
  :delay => (ENV['KANSHI_SAMPLE_DELAY'] || 300).to_i
10
18
  )
data/lib/kanshi.rb CHANGED
@@ -11,7 +11,7 @@ class Kanshi
11
11
 
12
12
  def initialize(options = {})
13
13
  @options = {
14
- :databases => [],
14
+ :databases => {},
15
15
  :delay => 300,
16
16
  :reporter => ScrollsReporter
17
17
  }
@@ -11,7 +11,7 @@ class Kanshi::ScrollsReporter
11
11
  def report(name, url, data)
12
12
  data = calculate_hit_rate(record_and_diff(name, data))
13
13
  if data
14
- Scrolls.context(:app => "kanshi.#{name}", :measure => true) do
14
+ Scrolls.context(:app => name, :measure => true) do
15
15
  data.each do |k, v|
16
16
  Scrolls.log(:at => k, :last => v)
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanshi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: