Sha256: 18e950415a2bb0c1bc4bb56352bdfd24f2b63966593912d95dde15c93db1440e

Contents?: true

Size: 861 Bytes

Versions: 3

Compression:

Stored size: 861 Bytes

Contents

#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'

def overview (host, port)
  url = URI.parse("http://#{host}:#{port}/_status")
  req = Net::HTTP::Get.new(url.path)

  begin
    resp = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
  rescue => msg
    error "Could not connect - #{msg}"
  end

  if resp.code != "200"
    if resp.nil?
      error "Nil response object"
    else
      error "Bad status #{resp.code}"
    end
  elsif not resp['content-type'].include? 'application/json'
    error "Not getting JSON output from MongoDB"
  end

  j = JSON::parse(resp.body)
  j['serverStatus']
end

def error message
  puts JSON::generate({:error => message})
  exit 1
end

config = JSON::parse(ARGV[0])
config["host"] ||= 'localhost'
config["port"] ||= '28017'

puts JSON::generate(overview(config["host"], config["port"]))

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panoptimon-0.4.5 collectors/mongodb/mongodb
panoptimon-0.4.4 collectors/mongodb/mongodb
panoptimon-0.4.2 collectors/mongodb/mongodb