qnotifier 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- =H0 ${�]��@����L��-o�UIB�Ku��`_�0�K���u\�*���O'Q[��fD~�<lj���%�?���A��~�6.!��i����Z��k Wf�j��-��"�l��ߍQ��V�=j+P�L��G����~�@���������?\(J�?��K���N�:��$�h���N�Ơt�#�*�ۙ����V�|$f�t)�C������'�E�ے��g�7Ƙ%ZR�?д>{�W4�Y���
2
- ��
1
+ �����
2
+ kk�߳%E�x:S�N��^/d|��8>0��_��ɛds�I�6��<' ��q�V.��/-T�j|��Y��Mq�)ӚԱ���o�v6�SD�Zs���B�
3
+ ��L��8|�6y9�S��'�
data/Manifest CHANGED
@@ -10,7 +10,6 @@ lib/qnotifier_runner.rb
10
10
  lib/storage.rb
11
11
  lib/web_service.rb
12
12
  plugins/apache.rb
13
- plugins/iostat.rb
14
13
  plugins/mysql.rb
15
14
  plugins/network.rb
16
15
  plugins/nginx.rb
@@ -33,6 +33,11 @@ module Qnotifier
33
33
  `rm /var/lib/qnotifier/saved_variables.yml`
34
34
  end
35
35
 
36
+ elsif argv.first == 'alert'
37
+ require "qnotifier"
38
+ qnotifier = Qnotifier::MainProcess.new
39
+ qnotifier.alert(argv[1], argv[2], 3)
40
+
36
41
  elsif argv.first == 'register'
37
42
  require "qnotifier"
38
43
  qnotifier = Qnotifier::MainProcess.new
@@ -1 +1,54 @@
1
- Plugin Development
1
+ Plugin Development
2
+
3
+ QNotifier supports user defined plugins to extend its capability. With this ability you can monitor and alert on pretty much anything on your system.
4
+
5
+ Location
6
+ - User generated plugins should be placed in /var/lib/qnotifier/plugins
7
+
8
+ Plugin Structure
9
+ - A plugin must subclass Qnotifier::Plugin and contain a main method and an initializer.
10
+
11
+ Here's a basic plugin that counts the number of processes on the system:
12
+
13
+ module Qnotifier
14
+ class Iostat < Qnotifier::Plugin
15
+ def main
16
+ processes = `ps -ef`
17
+ if processes
18
+ process_count = processes.split("/n").count
19
+ stat("Count", process_count)
20
+ report("Count", process_count)
21
+ if process_count > 100
22
+ alert("Count", "There are more than 100 processes running")
23
+ else
24
+ reset_alert("Count", "There are now under 100 processes running")
25
+ end
26
+ else
27
+ Qnotifier.log.error "Couldn't get output from the ps command"
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Methods:
34
+
35
+ stat(key, value)
36
+ Will update the stat for key with value on the server. Value is a text field that will appear next to the property in the stats portion of the client.
37
+
38
+ report(key, value)
39
+ Will create a datapoint for graphs for the associated key. Value is a float or integer.
40
+
41
+ alert(key, message)
42
+ Sends a push notification for the specified key with the message string.
43
+
44
+ reset_alert(key, message)
45
+ Resets an alert, key must match the alert that it is associated with.
46
+
47
+ put(key, value)
48
+ Puts a value string in the saved variables to be retrieved on a subsequent run by get.
49
+
50
+ get(key)
51
+ Retrieves a stored value by key.
52
+
53
+
54
+ Submit your plugin to support@qnotifier.com if you feel like sharing it with others!
@@ -30,12 +30,10 @@ System:
30
30
  use_load: five_minute
31
31
  # normalize_load: whether to divide the reported load by the number of CPUs in the system
32
32
  normalize_load: false
33
- # Alert if the CPU is above this percent usage, 0 disables
34
- alert_cpu_threshold: 95
35
33
  # Alert if the memory is above this percent usage, 0 disables
36
34
  alert_memory_threshold: 90
37
35
  # Alert if the load is above this percent usage, 0 disables
38
- alert_load_threshold: 1.0
36
+ alert_load_threshold: 1.5
39
37
  # Alert if the disk is above this percent usage, 0 disables
40
38
  alert_disk_threshold: 90
41
39
  # Partitions which to monitor for free disk space
@@ -43,20 +41,12 @@ System:
43
41
  - "/"
44
42
 
45
43
  # The Apache built-in plugin
46
- # Not currently supported
44
+ # You must enable mod_status at this URL
47
45
  Apache:
48
46
  # Enabled, set to either true or false
49
47
  enabled: false
50
- monitor_url: "http://localhost/foo"
51
- username: "username"
52
- password: "password"
53
-
54
- # The IOStat built-in plugin
55
- # Not currently supported
56
- Iostat:
57
- # Enabled, set to either true or false
58
- enabled: false
59
-
48
+ url: "http://username:password@127.0.0.1/nginx_status"
49
+
60
50
  # The MySQL built-in plugin
61
51
  Mysql:
62
52
  # Enabled, set to either true or false
@@ -71,7 +61,8 @@ Mysql:
71
61
  #port: 3306
72
62
 
73
63
  # The URL Monitor built-in plugin, will watch a URL for non-200 HTTP responses
74
- Url:
64
+ # Please be aware to make sure this isn't a redirect (301, 302)
65
+ Urls:
75
66
  enabled: false
76
67
  url: "http://localhost"
77
68
 
@@ -84,6 +75,7 @@ Network:
84
75
  - eth0
85
76
 
86
77
  # The Nginx built-in plugin
78
+ # You must compile nginx with --with-http_stub_status_module and point this url to the stub_status location
87
79
  Nginx:
88
80
  # Enabled, set to either true or false
89
81
  enabled: false
@@ -6,6 +6,7 @@ require "storage"
6
6
  module Qnotifier
7
7
  class Plugin
8
8
 
9
+ attr_accessor :defaults
9
10
  attr_accessor :reports
10
11
  attr_accessor :alerts
11
12
  attr_accessor :stats
@@ -45,7 +45,7 @@ module Qnotifier
45
45
  end
46
46
 
47
47
  def run
48
- Qnotifier.log.info "QNotifier Running"
48
+ Qnotifier.log.debug "QNotifier Running"
49
49
 
50
50
  runlock_file = "/var/lib/qnotifier/.runlock"
51
51
  if File.exists?(runlock_file)
@@ -160,6 +160,16 @@ module Qnotifier
160
160
  Qnotifier::Storage.wipe
161
161
  end
162
162
 
163
+ def alert(key, message, priority)
164
+ start_logging
165
+ load_config
166
+
167
+ alerts = {"User" => [[key, message, priority]]}
168
+ webservice = Qnotifier::WebService.new
169
+ webservice.config = @config
170
+ webservice.send_alerts(alerts)
171
+ end
172
+
163
173
  def save_api_key(api_key)
164
174
  return unless api_key
165
175
  @config["api_key"] = api_key
@@ -79,7 +79,6 @@ module Qnotifier
79
79
  return
80
80
  end
81
81
  if last_run and (Time.now - last_run) <= @@poll_interval
82
- Qnotifier.log.info "Not reporting to the service yet, waiting until #{last_run + @@poll_interval}"
83
82
  return
84
83
  end
85
84
  Qnotifier::Storage.put("last_run", Time.now)
@@ -8,7 +8,26 @@ module Qnotifier
8
8
  end
9
9
 
10
10
  def main
11
- Qnotifier.log.error "Apache stats plugin not yet supported in this beta version"
11
+
12
+ return if @options["url"].empty?
13
+
14
+ connections, requests, cpu = nil
15
+
16
+ begin
17
+ open( @options["url"]) {|f|
18
+ f.each_line do |line|
19
+ connections = $1 if line.strip =~ /^(\d+)\srequests\scurrently\sbeing\sprocessed/
20
+ cpu = line if line.strip =~/CPU\sUsage/
21
+ requests = line if line =~/requests\/sec/
22
+ end
23
+ }
24
+
25
+ report("Connections", connections)
26
+ stat("Activity", "#{cpu} #{requests}")
27
+
28
+ rescue Exception => e
29
+ Qnotifier.log.error "Can not check Apache Status #{e}"
30
+ end
12
31
  end
13
32
  end
14
33
  end
@@ -67,7 +67,7 @@ module Qnotifier
67
67
  items = line.split
68
68
 
69
69
  disk = "Used: #{items[-2]} (#{items[-4]}), #{items[-3]} free"
70
- stat("Disk #{partition}", disk) if partition == "/"
70
+ stat("Disk #{partition}", disk)
71
71
  report("Disk #{partition} %", items[-2].delete("%").to_i)
72
72
 
73
73
  if @options["alert_disk_threshold"] != 0 and items[-2].delete("%").to_i >= @options["alert_disk_threshold"]
@@ -86,52 +86,48 @@ module Qnotifier
86
86
  if RUBY_PLATFORM =~ /linux/
87
87
 
88
88
  # Need to rewrite this, vmstat is only giving stats since system boot, not instant stats
89
- vmstat = nil #`vmstat | tail -1`
90
- if vmstat
91
- vmstat = vmstat.split
92
- if vmstat.size >= 16
93
-
94
- cpu = "User: #{vmstat[12].to_i}%, System: #{vmstat[13].to_i}%, Idle: #{vmstat[14].to_i}%, Wait: #{vmstat[15].to_i}%"
95
- cpu_percent = (100 - vmstat[14].to_i)
96
-
97
- stat("CPU", cpu)
98
- report("CPU %", cpu_percent)
99
-
100
- if @options["alert_cpu_threshold"] != 0 and cpu_percent >= @options["alert_cpu_threshold"]
101
- alert("cpu", "CPU is at #{cpu_percent}%")
102
- else
103
- reset_alert("cpu", "CPU is now #{cpu_percent}%")
104
- end
105
-
106
- else
107
- Qnotifier.log.error "Can't parse vmstat, is it installed?"
108
- end
109
- else
110
- Qnotifier.log.error "Can't parse vmstat, is it installed?"
111
- end
112
-
113
- elsif RUBY_PLATFORM =~ /darwin/
114
- iostat = `iostat | tail -1`
115
- if iostat
116
- iostat = iostat.split
117
- if iostat.size >= 9
118
- cpu = "User: #{iostat[3].to_i}%, System: #{iostat[4].to_i}%, Idle: #{iostat[5].to_i}%"
119
- cpu_percent = (100 - iostat[5].to_i)
120
-
121
- stat("CPU", cpu)
122
- report("CPU %", cpu_percent)
123
-
124
- if @options["alert_cpu_threshold"] != 0 and cpu_percent >= @options["alert_cpu_threshold"]
125
- alert("cpu", "CPU is at #{cpu_percent}%")
126
- else
127
- reset_alert("cpu", "CPU is now #{cpu_percent}%")
89
+ proc_stat = `cat /proc/stat`
90
+ if proc_stat
91
+ for line in proc_stat.split("\n")
92
+ item = line.split
93
+ if item[0] == "cpu"
94
+ user = item[1].to_i + item[2].to_i
95
+ system = item[3].to_i
96
+ idle = item[4].to_i
97
+ iowait = item[5].to_i + item[6].to_i + item[7].to_i
98
+
99
+ last_user = get("cpu_user") ? get("cpu_user") : 0
100
+ last_system = get("cpu_system") ? get("cpu_system") : 0
101
+ last_idle = get("cpu_idle") ? get("cpu_idle") : 0
102
+ last_iowait = get("cpu_iowait") ? get("cpu_iowait") : 0
103
+
104
+ user_diff = user - last_user
105
+ system_diff = system - last_system
106
+ idle_diff = idle - last_idle
107
+ iowait_diff = iowait - last_iowait
108
+
109
+ div = user_diff + system_diff + idle_diff + iowait_diff
110
+ half_div = div / 2
111
+
112
+ user_pc = (100 * user_diff + half_div) / div
113
+ system_pc = (100 * system_diff + half_div) / div
114
+ idle_pc = (100 * idle_diff + half_div) / div
115
+ iowait_pc = (100 * iowait_diff + half_div) / div
116
+ cpu_pc = 100 - idle_pc
117
+
118
+ put("cpu_user", user)
119
+ put("cpu_system", system)
120
+ put("cpu_idle", idle)
121
+ put("cpu_iowait", iowait)
122
+
123
+ stat("CPU", "#{user_pc}% user, #{system_pc}% system, #{iowait_pc}% iowait, #{idle_pc}% idle")
124
+ report("CPU %", cpu_pc)
125
+
126
+ break
128
127
  end
129
-
130
- else
131
- Qnotifier.log.error "Can't parse iostat"
132
128
  end
133
129
  else
134
- Qnotifier.log.error "Can't parse iostat"
130
+ Qnotifier.log.error "Can't parse /proc/stat"
135
131
  end
136
132
  else
137
133
  Qnotifier.log.error "Can't parse CPU for this platform - #{RUBY_PLATFORM}"
@@ -169,8 +165,6 @@ module Qnotifier
169
165
  Qnotifier.log.error "Can't get memory information from /proc/meminfo (is it supported by this OS?)"
170
166
  end
171
167
 
172
- elsif RUBY_PLATFORM =~ /darwin/
173
- # Not supported on OSX currently
174
168
  else
175
169
  Qnotifier.log.error "Can't parse Memory for this platform - #{RUBY_PLATFORM}"
176
170
  end
@@ -28,6 +28,9 @@ module Qnotifier
28
28
 
29
29
  start_time = Time.now.usec
30
30
 
31
+ code = 0
32
+ failure_message = ""
33
+
31
34
  begin
32
35
  http = Net::HTTP.new(uri.host,uri.port)
33
36
  http.use_ssl = url =~ %r{\Ahttps://}
@@ -38,23 +41,25 @@ module Qnotifier
38
41
  req.basic_auth uri.user, uri.password
39
42
  end
40
43
  response = http.request(req)
44
+ code = response.code.to_i
41
45
  }
42
46
  rescue Exception => e
43
- puts "Exception #{e}"
44
- stat("Code", 0)
45
- alert("response", "HTTP connection error: #{e.message} #{url}")
46
- return
47
+ Qnotifier.log.error "Exception #{e}"
48
+ failure_message = e
49
+ code = 0
47
50
  end
48
51
 
49
- response_time = (Time.now.usec - start_time) / 1000
50
- report("Latency msec", response_time)
51
-
52
- if response.code == 200
52
+ if code == 200
53
53
  stat("Code", 200)
54
54
  reset_alert("response", "HTTP OK #{url}")
55
+ response_time = (Time.now.usec - start_time) / 1000
56
+ report("Latency msec", response_time)
57
+ elsif code == 0
58
+ stat("Code", code)
59
+ alert("response", "HTTP Connection Failed #{url} #{failure_message}")
55
60
  else
56
- stat("Code", response.code)
57
- alert("response", "HTTP #{response.code} #{url}")
61
+ stat("Code", code)
62
+ alert("response", "HTTP #{code} #{url}")
58
63
  end
59
64
  end
60
65
  end
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{qnotifier}
5
- s.version = "0.7.5"
5
+ s.version = "0.7.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Gersham Meharg"]
9
- s.date = %q{2010-06-30}
9
+ s.date = %q{2010-07-06}
10
10
  s.default_executable = %q{qnotifier}
11
11
  s.description = %q{The server side agent for the QNotifier monitoring system. This software will monitor local Linux system parameters and upload them to the QNotifier servers where users can use iPhone/iPad applications to view those stats and recieve alerts.}
12
12
  s.email = %q{gersham@qnotifier.com}
13
13
  s.executables = ["qnotifier"]
14
14
  s.extra_rdoc_files = ["bin/qnotifier", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb"]
15
- s.files = ["Manifest", "Rakefile", "bin/qnotifier", "config/README", "config/qnotifier_config.yml", "gem-public_cert.pem", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb", "plugins/apache.rb", "plugins/iostat.rb", "plugins/mysql.rb", "plugins/network.rb", "plugins/nginx.rb", "plugins/passenger.rb", "plugins/rails.rb", "plugins/ruby.rb", "plugins/system.rb", "plugins/urls.rb", "init.d/qnotifier", "qnotifier.gemspec"]
15
+ s.files = ["Manifest", "Rakefile", "bin/qnotifier", "config/README", "config/qnotifier_config.yml", "gem-public_cert.pem", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb", "plugins/apache.rb", "plugins/mysql.rb", "plugins/network.rb", "plugins/nginx.rb", "plugins/passenger.rb", "plugins/rails.rb", "plugins/ruby.rb", "plugins/system.rb", "plugins/urls.rb", "init.d/qnotifier", "qnotifier.gemspec"]
16
16
  s.homepage = %q{http://qnotifier.com/qnotifier_gem}
17
17
  s.post_install_message = %q{Qnotifier installed, please register by running 'qnotifier' in order to register this server.}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Qnotifier"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 5
9
- version: 0.7.5
8
+ - 6
9
+ version: 0.7.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gersham Meharg
@@ -35,7 +35,7 @@ cert_chain:
35
35
  wu7A8rLN6CU0SfWf
36
36
  -----END CERTIFICATE-----
37
37
 
38
- date: 2010-06-30 00:00:00 -07:00
38
+ date: 2010-07-06 00:00:00 -07:00
39
39
  default_executable: qnotifier
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
@@ -182,7 +182,6 @@ files:
182
182
  - lib/storage.rb
183
183
  - lib/web_service.rb
184
184
  - plugins/apache.rb
185
- - plugins/iostat.rb
186
185
  - plugins/mysql.rb
187
186
  - plugins/network.rb
188
187
  - plugins/nginx.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- module Qnotifier
3
- class Iostat < Qnotifier::Plugin
4
-
5
- def initialize
6
- @defaults = {
7
- }
8
- end
9
-
10
- def main
11
- Qnotifier.log.error "IOStats plugin not yet supported in this beta version"
12
- end
13
- end
14
- end