bin/instrument_server in instrumental_tools-0.5.6 vs bin/instrument_server in instrumental_tools-0.5.7
- old
+ new
@@ -11,10 +11,12 @@
require 'instrumental_agent'
require 'pidly'
require 'tmpdir'
require 'optparse'
require 'socket'
+$: << File.join(File.dirname(__FILE__), "..", "lib")
+require 'instrumental_tools/version'
class SystemInspector
TYPES = [:gauges, :incrementors]
attr_accessor *TYPES
@@ -132,17 +134,13 @@
output
end
def self.df
output = {}
- `df -ka`.split("\n").grep(%r{^(/dev/|tmpfs)}).each do |line|
+ `df -k`.split("\n").grep(%r{^/dev/}).each do |line|
device, total, used, available, capacity, mount = line.split(/\s+/)
- if device == "tmpfs"
- names = ["tmpfs_#{mount.gsub(/[^[:alnum:]]/, "_")}".gsub(/_+/, "_")]
- else
- names = [File.basename(device)]
- end
+ names = [File.basename(device)]
names << 'root' if mount == '/'
names.each do |name|
output["disk.#{name}.total_mb"] = total.to_f / 1024
output["disk.#{name}.used_mb"] = used.to_f / 1024
output["disk.#{name}.available_mb"] = available.to_f / 1024
@@ -248,13 +246,19 @@
output
end
def self.disk_storage
output = {}
- `df -Pk`.split("\n").grep(%r{^/dev/}).each do |line|
+ `df -Pka`.split("\n").each do |line|
device, total, used, available, capacity, mount = line.split(/\s+/)
- names = [File.basename(device)]
+ if device == "tmpfs"
+ names = ["tmpfs_#{mount.gsub(/[^[:alnum:]]/, "_")}".gsub(/_+/, "_")]
+ elsif device =~ %r{/dev/}
+ names = [File.basename(device)]
+ else
+ next
+ end
names << 'root' if mount == '/'
names.each do |name|
output["disk.#{name}.total_mb"] = total.to_f / 1024
output["disk.#{name}.used_mb"] = used.to_f / 1024
output["disk.#{name}.available_mb"] = available.to_f / 1024
@@ -351,9 +355,10 @@
puts 'Error encountered'
end
def self.run(options)
agent = Instrumental::Agent.new(options[:api_key], :collector => [options[:collector], options[:port]].compact.join(':'))
+ puts "insrument_server version #{Instrumental::Tools::VERSION} started at #{Time.now.utc}"
puts "Collecting stats under the hostname: #{options[:hostname]}"
loop do
t = Time.now.to_i
next_run_at = (t - t % REPORT_INTERVAL) + REPORT_INTERVAL
sleep [next_run_at - t, 0].max