Class: Riemann::Tools::NginxStatus
- Inherits:
-
Object
- Object
- Riemann::Tools::NginxStatus
- Includes:
- Riemann::Tools
- Defined in:
- lib/riemann/tools/nginx_status.rb
Constant Summary
Constants included from Riemann::Tools
Instance Attribute Summary
Attributes included from Riemann::Tools
Instance Method Summary collapse
-
#initialize ⇒ NginxStatus
constructor
A new instance of NginxStatus.
- #state(key, value) ⇒ Object
- #tick ⇒ Object
Methods included from Riemann::Tools
#attributes, #endpoint_name, included, #options, #report, #riemann, #run
Constructor Details
#initialize ⇒ NginxStatus
Returns a new instance of NginxStatus.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/riemann/tools/nginx_status.rb', line 28 def initialize super @uri = URI.parse(opts[:uri]) # sample response: # # Active connections: 1 # server accepts handled requests # 39 39 39 # Reading: 0 Writing: 1 Waiting: 0 @keys = %w[active accepted handled requests reading writing waiting] @re = /Active connections: (\d+) \n.+\n (\d+) (\d+) (\d+) \nReading: (\d+) Writing: (\d+) Waiting: (\d+)/m end |
Instance Method Details
#state(key, value) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/riemann/tools/nginx_status.rb', line 43 def state(key, value) if opts.key? :"#{key}_critical" critical_threshold = opts[:"#{key}_critical"] return 'critical' if critical_threshold.positive? && (value >= critical_threshold) end if opts.key? :"#{key}_warning" warning_threshold = opts[:"#{key}_warning"] return 'warning' if warning_threshold.positive? && (value >= warning_threshold) end 'ok' end |
#tick ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/riemann/tools/nginx_status.rb', line 57 def tick response = nil begin response = ::Net::HTTP.new(@uri.host, @uri.port).get(@uri, { 'user-agent' => opts[:user_agent] }).body rescue StandardError => e report( service: 'nginx health', state: 'critical', description: "Connection error: #{e.class} - #{e.}", ) end return if response.nil? report( service: 'nginx health', state: 'ok', description: 'Nginx status connection ok', ) values = @re.match(response).to_a[1, 7].map(&:to_i) @keys.zip(values).each do |key, value| next unless opts[:checks].include?(key) report({ service: "nginx #{key}", metric: value, state: state(key, value), tags: ['nginx'], }) end end |