Sha256: b2fab84509489e87f920b6d72742da68b3a88fca9d4e0d0d8449e619d5da775e

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

# uses http://wiki.nginx.org/HttpStubStatusModule
require "zabbix-ruby-client/logger"

module ZabbixRubyClient
  module Plugins
    module Nginx
      extend self
      extend ZabbixRubyClient::PluginBase

      def collect(*args)
        host = args[0]
        info = get_status

        time = Time.now.to_i
        back = []
        back << "#{host} nginx[total] #{time} #{info[:total]}"
        back << "#{host} nginx[reading] #{time} #{info[:reading]}"
        back << "#{host} nginx[writing] #{time} #{info[:writing]}"
        back << "#{host} nginx[waiting] #{time} #{info[:waiting]}"
        back << "#{host} nginx[accepted] #{time} #{info[:accepted]}"
        back << "#{host} nginx[handled] #{time} #{info[:handled]}"
        back << "#{host} nginx[requests] #{time} #{info[:requests]}"
        return back
      end

      def get_status
        ret = {}
        open "http://127.0.0.1:8090/nginx_status" do |f|
          f.each_line do |line|
            ret[:total] = $1 if line =~ /^Active connections:\s+(\d+)/
            if line =~ /^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/
              ret[:reading] = $1
              ret[:writing] = $2
              ret[:waiting] = $3
            end
            ret[:accepted], ret[:handled], ret[:requests] = [$1, $2, $3] if line =~ /^\s+(\d+)\s+(\d+)\s+(\d+)/
          end
        end
        ret
      end

    end
  end
end

ZabbixRubyClient::Plugins.register('nginx', ZabbixRubyClient::Plugins::Nginx)

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.1.2 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.1.1 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.1.0 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.0.23 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.0.22 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.0.21 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.0.20 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.0.19 lib/zabbix-ruby-client/plugins/nginx.rb
zabbix-ruby-client-0.0.18 lib/zabbix-ruby-client/plugins/nginx.rb