1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Implement Rackspace Monitoring Agent Host information

This commit is contained in:
kfafel 2013-11-27 15:36:48 -06:00
parent c0a15eb4c8
commit 038a874d50
9 changed files with 595 additions and 0 deletions

View file

@ -78,6 +78,14 @@ module Fog
request :get_check
request :get_entity
request :get_notification
request :get_cpus_info
request :get_disks_info
request :get_filesystems_info
request :get_memory_info
request :get_network_interfaces_info
request :get_processes_info
request :get_system_info
request :get_logged_in_user_info
request :create_agent_token
request :create_alarm

View file

@ -0,0 +1,72 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_cpus_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/cpus"
)
end
end
class Mock
def get_cpus_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"name" => "cpu.0",
"vendor" => "AMD",
"model" => "Opteron",
"mhz" => Fog::Mock.random_numbers(4).to_s,
"idle" => Fog::Mock.random_numbers(10).to_s,
"irq" => Fog::Mock.random_numbers(5).to_s,
"soft_irq" => Fog::Mock.random_numbers(7).to_s,
"nice" => Fog::Mock.random_numbers(9).to_s,
"stolen" => Fog::Mock.random_numbers(7).to_s,
"sys" => Fog::Mock.random_numbers(7).to_s,
"user" => Fog::Mock.random_numbers(9).to_s,
"wait" => Fog::Mock.random_numbers(7).to_s,
"total" => Fog::Mock.random_numbers(11).to_s,
"total_cores" => 1,
"total_sockets" => 1
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,65 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_disks_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/disks"
)
end
end
class Mock
def get_disks_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"read_bytes" => Fog::Mock.random_numbers(10).to_s,
"reads" => Fog::Mock.random_numbers(6).to_s,
"rtime" => Fog::Mock.random_numbers(6).to_s,
"write_bytes" => Fog::Mock.random_numbers(10).to_s,
"writes" => Fog::Mock.random_numbers(8).to_s,
"wtime" => Fog::Mock.random_numbers(9).to_s,
"time" => Fog::Mock.random_numbers(7).to_s,
"name" => "/dev/xvda1"
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,73 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_filesystems_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/filesystems"
)
end
end
class Mock
def get_filesystems_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"dir_name" => "/",
"dev_name" => "/dev/xvda1",
"sys_type_name" => "ext4",
"options" => "rw,noatime,acl,errors=remount-ro,barrier=0",
"free" => Fog::Mock.random_numbers(8).to_s,
"used" => Fog::Mock.random_numbers(5).to_s,
"avail" => Fog::Mock.random_numbers(7).to_s,
"total" => Fog::Mock.random_numbers(9).to_s,
"files" => Fog::Mock.random_numbers(6).to_s,
"free_files" => Fog::Mock.random_numbers(6).to_s,
}
{
"dir_name" => "/proc",
"dev_name" => "proc",
"sys_type_name" => "ext4",
"options" => "rw",
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,67 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_logged_in_user_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/who"
)
end
end
class Mock
def get_logged_in_user_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"user" => "root",
"device" => "pts/1",
"time" => Time.now.to_i - 100,
"host" => "somehost1.company.local"
},
{
"user" => "user123",
"device" => "pts/2",
"time" => Time.now.to_i - 50,
"host" => "somehost2.company.local"
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,68 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_memory_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/memory"
)
end
end
class Mock
def get_memory_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"actual_free" => Fog::Mock.random_numbers(9).to_s,
"actual_used" => Fog::Mock.random_numbers(8).to_s,
"free" => Fog::Mock.random_numbers(7).to_s,
"used" => Fog::Mock.random_numbers(9).to_s,
"total" => Fog::Mock.random_numbers(10).to_s,
"ram" => Fog::Mock.random_numbers(4).to_s,
"swap_total" => Fog::Mock.random_numbers(10).to_s,
"swap_used" => Fog::Mock.random_numbers(8).to_s,
"swap_free" => Fog::Mock.random_numbers(10).to_s,
"swap_page_in" => Fog::Mock.random_numbers(3).to_s,
"swap_page_out" => Fog::Mock.random_numbers(3).to_s,
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,100 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_network_interfaces_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/network_interfaces"
)
end
end
class Mock
def get_network_interfaces_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"name" => "lo",
"type" => "Local Loopback",
"address" => Fog::Mock.random_ip({:version => :v4}),
"netmask" => "255.0.0.0",
"address6" => "::1",
"broadcast" => "0.0.0.0.0",
"hwaddr" => "00:00:00:00:00:00",
"mtu" => Fog::Mock.random_numbers(4).to_s,
"rx_packets" => Fog::Mock.random_numbers(3).to_s,
"rx_bytes" => Fog::Mock.random_numbers(4).to_s,
"tx_packets" => Fog::Mock.random_numbers(3).to_s,
"tx_bytes" => Fog::Mock.random_numbers(4).to_s,
"flags" => Fog::Mock.random_numbers(2).to_s,
},
{
"name" => "eth0",
"type" => "Ethernet",
"address" => Fog::Mock.random_ip({:version => :v4}),
"netmask" => "255.255.255.0",
"address6" => Fog::Mock.random_ip({:version => :v6}),
"broadcast" => Fog::Mock.random_ip({:version => :v4}),
"hwaddr" => "A1:B2:C3:D4:E5:F6",
"mtu" => "1500",
"rx_packets" => Fog::Mock.random_numbers(7).to_s,
"rx_bytes" => Fog::Mock.random_numbers(9).to_s,
"tx_packets" => Fog::Mock.random_numbers(7).to_s,
"tx_bytes" => Fog::Mock.random_numbers(9).to_s,
"flags" => Fog::Mock.random_numbers(4).to_s,
},
{
"name" => "eth1",
"type" => "Ethernet",
"address" => Fog::Mock.random_ip({:version => :v4}),
"netmask" => "255.255.128.0",
"address6" => Fog::Mock.random_ip({:version => :v6}),
"broadcast" => Fog::Mock.random_ip({:version => :v4}),
"hwaddr" => "A2:B3:C4:D5:E6:F7",
"mtu" => "1500",
"rx_packets" => Fog::Mock.random_numbers(7).to_s,
"rx_bytes" => Fog::Mock.random_numbers(9).to_s,
"tx_packets" => Fog::Mock.random_numbers(7).to_s,
"tx_bytes" => Fog::Mock.random_numbers(9).to_s,
"flags" => Fog::Mock.random_numbers(4).to_s,
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,80 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_processes_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/processes"
)
end
end
class Mock
def get_processes_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
memory_major_faults = Fog::Mock.random_numbers(1).to_i
memory_minor_faults = Fog::Mock.random_numbers(3).to_i
memory_page_faults = memory_major_faults+memory_minor_faults
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"pid" => Fog::Mock.random_numbers(4).to_s,
"exe_name" => "/usr/share/nova-agent/0.0.1.38/sbin/nova-agent",
"exe_cwd" => "/",
"exe_root" => "/",
"time_total" => Fog::Mock.random_numbers(3).to_s,
"time_sys" => Fog::Mock.random_numbers(2).to_s,
"time_user" => Fog::Mock.random_numbers(2).to_s,
"time_start_time" => Time.now.utc.to_i - 10000,
"state_name" => "nova-agent",
"state_ppid" => Fog::Mock.random_numbers(3).to_s,
"state_priority" => "15",
"state_threads" => Fog::Mock.random_numbers(1).to_s,
"memory_size" => Fog::Mock.random_numbers(9).to_s,
"memory_resident" => Fog::Mock.random_numbers(7).to_s,
"memory_share" => Fog::Mock.random_numbers(6).to_s,
"memory_major_faults" => memory_major_faults.to_s,
"memory_minor_faults" => memory_minor_faults.to_s,
"memory_page_faults" => memory_page_faults.to_s,
"cred_user" => "root",
"cred_group" => "root"
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end

View file

@ -0,0 +1,62 @@
module Fog
module Rackspace
class Monitoring
class Real
def get_system_info(agent_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "agents/#{agent_id}/host_info/system"
)
end
end
class Mock
def get_system_info(agent_id)
agent_id = Fog::Rackspace::MockData.uuid
if agent_id == -1
raise Fog::Rackspace::Monitoring::NotFound
end
response = Excon::Response.new
response.status = 200
response.body = {
"values" => [
{
"name" => "Linux",
"arch" => "x86_64",
"version" => "2.6.18-308.el5xen",
"vendor" => "CentOS",
"vendor_version" => "5.10"
}
],
"metadata" => {
"count" => 1,
"limit" => 100,
"marker" => nil,
"next_marker" => nil,
"next_href" => nil
}
}
response.headers = {
"Date" => Time.now.utc.to_s,
"Content-Type" => "application/json; charset=UTF-8",
"X-RateLimit-Limit" => "50000",
"X-RateLimit-Remaining" => "49627",
"X-RateLimit-Window" => "24 hours",
"X-RateLimit-Type" => "global",
"X-Response-Id" => "j23jlk234jl2j34j",
"X-LB" => "dfw1-maas-prod-api0",
"Vary" => "Accept-Encoding",
"Transfer-Encoding" => "chunked"
}
response.remote_ip = Fog::Mock.random_ip({:version => :v4})
response
end
end
end
end
end