fiveruns-dash-sensor 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -17
- data/VERSION.yml +4 -0
- data/plugins/noaa_weather.rb +73 -0
- data/plugins/twitter.rb +79 -0
- metadata +30 -18
- data/config.rb +0 -19
data/README.rdoc
CHANGED
@@ -4,11 +4,7 @@ Please see http://dash.fiveruns.com for an overview of the Dash service.
|
|
4
4
|
|
5
5
|
== Summary
|
6
6
|
|
7
|
-
Sensor provides a mechanism for "external" monitoring of infrastructure with Dash.
|
8
|
-
Since Dash is usually embedded within an application (i.e. internal), there's no easy
|
9
|
-
way to monitor things like Apache, memcached, or other pieces. Sensor is designed to
|
10
|
-
be installed on a machine and upload metrics for any infrastructure on that machine.
|
11
|
-
The user just needs to configure which elements they want to monitor.
|
7
|
+
Sensor provides a mechanism for "external" monitoring of infrastructure with Dash. Since Dash is usually embedded within an application (i.e. internal), there's no easy way to monitor things like Apache, memcached, or other pieces. Sensor is designed to be installed on a machine and upload metrics for any infrastructure on that machine. The user just needs to configure which elements they want to monitor.
|
12
8
|
|
13
9
|
== Installation
|
14
10
|
|
@@ -17,31 +13,22 @@ gem install fiveruns-dash-sensor -s http://gems.github.com
|
|
17
13
|
== Configuration
|
18
14
|
|
19
15
|
When you run 'fiveruns-dash-sensor' for the first time, it will create a blank
|
20
|
-
configuration for you in ~/.fiveruns-dash-sensor/config.rb. You will need to edit
|
21
|
-
this file with your app token and activate the plugins for your environment. Once
|
22
|
-
done, you should be able to restart 'fiveruns-dash-sensor' for a few minutes to verify
|
23
|
-
everything is working as designed. If there are no problems, you can run
|
24
|
-
'fiveruns-dash-sensor -d' to spin off the daemon into the background and forget about it.
|
16
|
+
configuration for you in ~/.fiveruns-dash-sensor/config.rb. You will need to edit this file with your app token and activate the plugins for your environment. Once done, you should be able to restart 'fiveruns-dash-sensor' for a few minutes to verify everything is working as designed. If there are no problems, you can run 'fiveruns-dash-sensor -d' to spin off the daemon into the background and forget about it.
|
25
17
|
|
26
18
|
== Command Summary
|
27
19
|
|
28
20
|
fiveruns-dash-sensor --help
|
29
21
|
|
30
|
-
Sensor allows you to control OS-specific parameters like log file and PID file location,
|
31
|
-
the user and group to run as, etc. -d will start Sensor as a daemon. To stop it, just
|
32
|
-
kill the associated PID.
|
22
|
+
Sensor allows you to control OS-specific parameters like log file and PID file location, the user and group to run as, etc. -d will start Sensor as a daemon. To stop it, just kill the associated PID.
|
33
23
|
|
34
24
|
== Creating your own Plugins
|
35
25
|
|
36
|
-
Sensor allows you to create your own custom plugins for your own infrastructure. Each
|
37
|
-
plugin should reside in ~/.fiveruns-dash-sensor/<name>.rb and config.rb should have an
|
38
|
-
entry in it like this:
|
26
|
+
Sensor allows you to create your own custom plugins for your own infrastructure. Each plugin should reside in ~/.fiveruns-dash-sensor/<name>.rb and config.rb should have an entry in it like this:
|
39
27
|
|
40
28
|
sensor.plugin :<name>, any options here...
|
41
29
|
|
42
30
|
Please see the existing plugins for examples of how your code should work.
|
43
31
|
|
44
|
-
|
45
32
|
== License
|
46
33
|
|
47
34
|
# (The FiveRuns License)
|
data/VERSION.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'nokogiri'
|
5
|
+
rescue LoadError => le
|
6
|
+
puts [
|
7
|
+
"The NOAA weather plugin requires the nokogiri gem. Install with:",
|
8
|
+
" sudo gem install nokogiri"
|
9
|
+
].join("\n")
|
10
|
+
raise le
|
11
|
+
end
|
12
|
+
|
13
|
+
# Collect the temperature and air pressure as reported by NOAA and send them to Dash.
|
14
|
+
# Proof that Sensor and Dash work with more than boring old software metrics.
|
15
|
+
# They work with boring real life metrics too. :-)
|
16
|
+
module Dash::Sensor::Plugins
|
17
|
+
class NoaaWeather
|
18
|
+
include SensorPlugin
|
19
|
+
|
20
|
+
register :noaa_weather, :url => 'http://dash.fiveruns.com' do |recipe|
|
21
|
+
recipe.absolute :temperature do
|
22
|
+
data[:temperature]
|
23
|
+
end
|
24
|
+
recipe.absolute :pressure do
|
25
|
+
data[:pressure]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure(options)
|
30
|
+
@url = "http://www.weather.gov/data/current_obs/#{options.fetch(:station, 'katt').upcase}.xml"
|
31
|
+
format = options.fetch(:format, 'metric')
|
32
|
+
case format.to_s
|
33
|
+
when 'metric'
|
34
|
+
@temp_format = 'c'
|
35
|
+
@pres_format = 'mb'
|
36
|
+
when 'english'
|
37
|
+
@temp_format = 'f'
|
38
|
+
@pres_format = 'in'
|
39
|
+
else
|
40
|
+
raise ArgumentError, "Unknown format '#{format}', must be either be :metric or :english"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.data
|
47
|
+
# Cache the data for 15 minutes, we don't really need it every minute.
|
48
|
+
if !@time || @time < Time.now - 900
|
49
|
+
logger.debug "Fetching data at #{Time.now}"
|
50
|
+
@data = instance.send(:data)
|
51
|
+
@time = Time.now
|
52
|
+
end
|
53
|
+
@data
|
54
|
+
end
|
55
|
+
|
56
|
+
def data
|
57
|
+
begin
|
58
|
+
xml = open(@url)
|
59
|
+
doc = Nokogiri::XML(xml)
|
60
|
+
|
61
|
+
result = {}
|
62
|
+
result[:temperature] = Float(doc.xpath("/current_observation/temp_#{@temp_format}").inner_text)
|
63
|
+
result[:pressure] = Float(doc.xpath("/current_observation/pressure_#{@pres_format}").inner_text)
|
64
|
+
result
|
65
|
+
rescue Exception => e
|
66
|
+
logger.error "Error contacting #{@url}"
|
67
|
+
logger.error "#{e.class.name}: #{e.message}"
|
68
|
+
Hash.new(0)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/plugins/twitter.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'nokogiri'
|
5
|
+
rescue LoadError => le
|
6
|
+
puts [
|
7
|
+
"The Twitter plugin requires the nokogiri gem. Install with:",
|
8
|
+
" sudo gem install nokogiri"
|
9
|
+
].join("\n")
|
10
|
+
raise le
|
11
|
+
end
|
12
|
+
|
13
|
+
# Collect common Twitter metrics and send them to Dash.
|
14
|
+
# Proof that Sensor and Dash work with more than boring old technical metrics.
|
15
|
+
# They work with boring social networking metrics too. :-)
|
16
|
+
module Dash::Sensor::Plugins
|
17
|
+
class Twitter
|
18
|
+
include SensorPlugin
|
19
|
+
|
20
|
+
register :twitter, :url => 'http://dash.fiveruns.com' do |recipe|
|
21
|
+
recipe.absolute :updates do
|
22
|
+
data[:update_count]
|
23
|
+
end
|
24
|
+
recipe.absolute :following do
|
25
|
+
data[:following_count]
|
26
|
+
end
|
27
|
+
recipe.absolute :followers do
|
28
|
+
data[:follower_count]
|
29
|
+
end
|
30
|
+
recipe.counter :tweets do
|
31
|
+
count = data[:update_count] - old_data[:update_count]
|
32
|
+
# update the old data to reflect the current metric
|
33
|
+
# since we are caching and don't want to return the same
|
34
|
+
# counter value every minute.
|
35
|
+
old_data.merge(data)
|
36
|
+
count > 0 ? count : 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure(options)
|
41
|
+
@url = "http://twitter.com/#{options[:username]}"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.data
|
47
|
+
# Cache the data for 15 minutes, we don't really need it every minute.
|
48
|
+
if !@time || @time < Time.now - 900
|
49
|
+
logger.debug "Fetching data at #{Time.now}"
|
50
|
+
@old_data = @data || Hash.new(1_000_000_000)
|
51
|
+
@data = instance.send(:data)
|
52
|
+
@time = Time.now
|
53
|
+
end
|
54
|
+
@data
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.old_data
|
58
|
+
@old_data
|
59
|
+
end
|
60
|
+
|
61
|
+
def data
|
62
|
+
begin
|
63
|
+
html = open(@url)
|
64
|
+
doc = Nokogiri::HTML(html)
|
65
|
+
|
66
|
+
%w(following_count follower_count update_count).inject({}) do |result, metric|
|
67
|
+
txt = doc.css("\##{metric}").inner_text
|
68
|
+
result[metric.to_sym] = Integer(txt.gsub /\D/, '')
|
69
|
+
result
|
70
|
+
end
|
71
|
+
rescue Exception => e
|
72
|
+
logger.error "Error contacting #{@url}"
|
73
|
+
logger.error "#{e.class.name}: #{e.message}"
|
74
|
+
Hash.new(0)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,42 +1,54 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiveruns-dash-sensor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- FiveRuns
|
7
|
+
- FiveRuns Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
13
|
-
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
date: 2009-02-26 00:00:00 -08:00
|
13
|
+
default_executable: fiveruns-dash-sensor
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fiveruns-dash-ruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.8.2
|
24
|
+
version:
|
25
|
+
description: Daemon to monitor ad-hoc infrastructure non-invasively for FiveRuns Dash
|
26
|
+
email: dev@fiveruns.com
|
18
27
|
executables:
|
19
28
|
- fiveruns-dash-sensor
|
20
29
|
extensions: []
|
21
30
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
24
33
|
files:
|
34
|
+
- README.rdoc
|
35
|
+
- VERSION.yml
|
25
36
|
- bin/fiveruns-dash-sensor
|
26
|
-
- config.rb
|
27
37
|
- lib/runner.rb
|
28
38
|
- lib/sensor.rb
|
29
39
|
- lib/sensor_plugin.rb
|
40
|
+
- plugins/apache.rb
|
30
41
|
- plugins/memcached.rb
|
31
|
-
- plugins/starling.rb
|
32
42
|
- plugins/nginx.rb
|
33
|
-
- plugins/
|
34
|
-
-
|
35
|
-
|
43
|
+
- plugins/noaa_weather.rb
|
44
|
+
- plugins/starling.rb
|
45
|
+
- plugins/twitter.rb
|
46
|
+
has_rdoc: true
|
36
47
|
homepage: http://github.com/fiveruns/dash-sensor/
|
37
48
|
post_install_message:
|
38
|
-
rdoc_options:
|
39
|
-
|
49
|
+
rdoc_options:
|
50
|
+
- --inline-source
|
51
|
+
- --charset=UTF-8
|
40
52
|
require_paths:
|
41
53
|
- lib
|
42
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -57,6 +69,6 @@ rubyforge_project:
|
|
57
69
|
rubygems_version: 1.2.0
|
58
70
|
signing_key:
|
59
71
|
specification_version: 2
|
60
|
-
summary: Sensor allows Dash to monitor ad-hoc infrastructure non-invasively
|
72
|
+
summary: FiveRuns Sensor allows Dash to monitor ad-hoc infrastructure non-invasively
|
61
73
|
test_files: []
|
62
74
|
|
data/config.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# Example configuration for FiveRuns Dash Sensor daemon.
|
2
|
-
# Configure your Dash sensor instance here.
|
3
|
-
# This file should reside in ~/.fiveruns-dash-sensor/config.rb
|
4
|
-
#
|
5
|
-
# We suggest you have a single Dash Sensor instance running per machine
|
6
|
-
# and an application token per environment. So if you have 8 machines
|
7
|
-
# in your application's production cluster, you would have 8 sensor instances
|
8
|
-
# running for one application named "<App> Production Cluster".
|
9
|
-
|
10
|
-
#sensor.token = 'change-to-your-application-token'
|
11
|
-
|
12
|
-
# One line per piece of infrastructure you wish to monitor.
|
13
|
-
# The plugins are in the plugins directory.
|
14
|
-
|
15
|
-
# Available options and their defaults are listed.
|
16
|
-
#sensor.plugin 'memcached', :iface => 'localhost', :port => 11211
|
17
|
-
#sensor.plugin 'starling', :iface => 'localhost', :port => 22122
|
18
|
-
#sensor.plugin 'apache', :url => 'http://localhost/server-status?auto'
|
19
|
-
#sensor.plugin 'nginx', :url => 'http://localhost/nginx_status'
|