workaholic-cron 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/workaholic.rb +38 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8b2b6993e993311c9af07aa7cfb142534c9a285
4
+ data.tar.gz: c049fa2c20eb9b13e926231d781fdda1af619d03
5
+ SHA512:
6
+ metadata.gz: 7cce7ae0c10515cf84f983c91d12ea576207b0b401c6c17812eb1979e165100ed238d3745f4a98726562164123fb1952c9c937858145f3b4372e61bede1732df
7
+ data.tar.gz: 89f8b1ef1bfab0de5fd95db77b50beb60df58db1b4d53eb4518ab6adc439b86e66ac25e5dded8e9613316115ec31d9c853331e5f4b57803e2b5c3078211a3875
data/lib/workaholic.rb ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/ruby
2
+ require 'time'
3
+
4
+ class Workaholic
5
+ # Find long running cron jobs.
6
+ #
7
+ # Example:
8
+ # >> require 'workaholic'
9
+ # >> workers = Workaholic.new 'cron', 300
10
+ # >> workers.scan
11
+ # => => {:"4389"=>71983, :"4335"=>71994}
12
+ #
13
+ # Arguments:
14
+ # proccess: (String)
15
+ # limit: (Int)
16
+ attr_accessor :proccess, :limit
17
+
18
+ def initialize proccess, limit
19
+ @proccess = proccess
20
+ @limit = limit.to_i
21
+ end
22
+
23
+ def scan
24
+ # Get all child processes of the desired parent process.
25
+ pids = %x(ps -o pid,etime --ppid=`pidof -s #{proccess}` --sort=etime | awk '{print $1,$2}' | tr '-' ' ' | awk '{print $1,$3}' | egrep '^[0-9]' | grep ':')
26
+ workaholics = {}
27
+ pids.each_line do |proccess|
28
+ pid, etime = proccess.split
29
+ workaholics[pid.to_sym] = etime_to_i etime if (etime_to_i etime) > limit
30
+ end
31
+ workaholics
32
+ end
33
+
34
+ def etime_to_i etime
35
+ h,m,s = etime.split(':')
36
+ (h.to_i * 60 * 60) + (m.to_i * 60) + (s.to_i)
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workaholic-cron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alaa Qutaish
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple gem to find cron jobs that have been running for long time https://github.com/alaa/workaholic-cron
14
+ email: alaa.qutaish@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/workaholic.rb
20
+ homepage: http://rubygems.org/gems/workaholic
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.1.10
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Workaholic
44
+ test_files: []