monitoring-client 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monitoring-client (0.2.1)
4
+ monitoring-client (0.2.3)
5
5
  json
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- diff-lcs (1.1.2)
11
- json (1.5.1)
10
+ diff-lcs (1.1.3)
11
+ json (1.5.3)
12
12
  rspec (2.6.0)
13
13
  rspec-core (~> 2.6.0)
14
14
  rspec-expectations (~> 2.6.0)
15
15
  rspec-mocks (~> 2.6.0)
16
- rspec-core (2.6.0)
16
+ rspec-core (2.6.4)
17
17
  rspec-expectations (2.6.0)
18
18
  diff-lcs (~> 1.1.2)
19
19
  rspec-mocks (2.6.0)
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Monitoring
4
+ class SystemInfo
5
+
6
+ require "monitoring/client/profiler"
7
+
8
+ RC_OK = 0
9
+ RC_USAGE = 1
10
+ RC_KILLED = 2
11
+
12
+
13
+ def initialize()
14
+ @config_fn = File.join(ENV["HOME"], ".monitoring.yml")
15
+ @daemon_mode = true
16
+ @pid_file_fn = "/var/run/monitoringd.pid"
17
+ @sleep_period = 60
18
+ @stdout = "/dev/null"
19
+ @stderr = "/dev/null"
20
+ @alive = true
21
+ end
22
+
23
+
24
+ def parse_opts(argv)
25
+ optparser = OptionParser.new() do |o|
26
+ o.banner = "monitor-system-info [options]"
27
+
28
+ o.separator("")
29
+ o.separator("options")
30
+
31
+ o.on("-c", "--config=CONFIG",
32
+ "Config file to use",
33
+ "Default: #{@config_fn.inspect()}") do |v|
34
+ @config_fn = v
35
+ end
36
+
37
+ o.on("-f", "--forgeround",
38
+ "Run in forground",
39
+ "Default: #{!@daemon_mode}") do |v|
40
+ @daemon_mode = !v
41
+ end
42
+
43
+ o.on("--pid-file=FILE",
44
+ "Place to store our pid file",
45
+ "Default: " + @pid_file_fn.inspect()) do |v|
46
+ @pid_file_fn = v
47
+ end
48
+
49
+ o.on("--sleep-period=s",
50
+ "Time to sleep between posts",
51
+ "Default: #{@sleep_period}") do |v|
52
+ @sleep_period = Float(v)
53
+ end
54
+
55
+ o.on("--stdout=FILE",
56
+ "Place to write stdout to",
57
+ "Default: " + @stdout.inspect()) do |v|
58
+ @stdout = v
59
+ end
60
+
61
+ o.on("--stderr=FILE",
62
+ "Place to write stdout to",
63
+ "Default: " + @stderr.inspect()) do |v|
64
+ @stderr = v
65
+ end
66
+
67
+ o.separator("")
68
+ o.on_tail("-h", "--help", "You're reading it :-)") do
69
+ puts(o)
70
+ Kernel.exit(RC_USAGE)
71
+ end
72
+ end
73
+
74
+ optparser.parse(argv)
75
+ self
76
+ end
77
+
78
+ def load_config()
79
+ @config = YAML.load_file(@config_fn)
80
+ end
81
+
82
+ def run()
83
+ load_config()
84
+ daemonize() if @daemon_mode
85
+
86
+ trap(:INT) do
87
+ if @alive
88
+ STDOUT.puts("SIGINT: going away gracefully")
89
+ @alive = false
90
+ else
91
+ STDOUT.puts("SIGINT (again): going away not so gracefully")
92
+ Kernel.exit!(RC_KILLED)
93
+ end
94
+ end
95
+
96
+ while @alive
97
+ post_load_avg()
98
+ post_mem_info()
99
+ Kernel.sleep(@sleep_period)
100
+ end
101
+ end
102
+
103
+ def daemonize()
104
+ pid_file_fd = File.open(@pid_file_fn, "w")
105
+ pid_file_fd.flock(File::LOCK_EX | File::LOCK_NB) ||
106
+ die("Daemon already exists")
107
+
108
+ die("First fork failed") if (pid = Kernel.fork()) == -1
109
+ exit unless pid.nil?
110
+
111
+ Process.setsid
112
+ pid_file_fd.puts(Process.pid)
113
+ pid_file_fd.flush()
114
+
115
+ Dir.chdir("/")
116
+ File.umask(0000)
117
+ STDIN.reopen("/dev/null")
118
+ STDOUT.reopen(@stdout)
119
+ STDERR.reopen(@stderr)
120
+ end
121
+
122
+ def die(why)
123
+ STDERR.puts(why)
124
+ Kernel.exit!(1)
125
+ end
126
+
127
+ def get_profiler
128
+ @profiler ||= Monitoring::Client::Profiler.new(@config[:profiler_name])
129
+ end
130
+
131
+ def routine(routine_name)
132
+ get_profiler.routine(routine_name) do |routine|
133
+ yield(routine)
134
+ end
135
+ end
136
+
137
+ def post_load_avg
138
+ loadavg = File.read("/proc/loadavg").split(" ")
139
+ routine("load") do |load|
140
+ load.count("1m", Float(loadavg[0]), "")
141
+ end
142
+ end
143
+
144
+ def post_mem_info
145
+ routine("memory") do |memory|
146
+ free_m = %x(free).split("\n")
147
+ [
148
+ [1, "mem"],
149
+ [3, "swap"],
150
+ ].each do |row, type|
151
+ heading, total, used, free, rest = free_m[row].split(/\s+/)
152
+ memory.count("#{type}.total", Float(total), "bytes")
153
+ memory.count("#{type}.used", Float(used), "bytes")
154
+ memory.count("#{type}.free", Float(free), "bytes")
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ Monitoring::SystemInfo.new().parse_opts(ARGV).run()
@@ -1,5 +1,5 @@
1
1
  module Monitoring
2
2
  module Client
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monitoring-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marc Bowes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-27 00:00:00 +02:00
18
+ date: 2011-08-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ description: Ruby client which uses UDP to communicate with a daemon which uses
50
50
  email:
51
51
  - marcbowes+monitoring+client@gmail.com
52
52
  executables:
53
+ - monitor-system-info
53
54
  - monitoringd
54
55
  extensions: []
55
56
 
@@ -60,6 +61,7 @@ files:
60
61
  - Gemfile
61
62
  - Gemfile.lock
62
63
  - Rakefile
64
+ - bin/monitor-system-info
63
65
  - bin/monitoringd
64
66
  - lib/monitoring.rb
65
67
  - lib/monitoring/client/compiler.rb
@@ -107,5 +109,8 @@ rubygems_version: 1.6.2
107
109
  signing_key:
108
110
  specification_version: 3
109
111
  summary: Simple client & daemon to post metrics
110
- test_files: []
111
-
112
+ test_files:
113
+ - spec/compiler_spec.rb
114
+ - spec/config_spec.rb
115
+ - spec/profiler_spec.rb
116
+ - spec/spec_helper.rb