bipbip 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f941fb989afaa352100d0f5abb6db11979061f1a
4
- data.tar.gz: 02155b7336f3b851c825f35c7daa59c8f083e5fb
3
+ metadata.gz: 0b7777292e1ad5542031723e2560daf16236b60c
4
+ data.tar.gz: e377adebf53bc1b22624627dac1901dd056c3f6e
5
5
  SHA512:
6
- metadata.gz: 7691f2ff5ec9333e7ad52b33261a9bf1815741dab78b4bbc560a1d867a16942156b890ab89869876f6f17d984a4397f056b7e29aac5e70bc0f3d3f406317e52e
7
- data.tar.gz: 614662716ef0d44b25e17dd93a0274cfe2dac73fbc19c3d3546b6c7196930c9ecda70c6eed83e4dbf32780a6e790e94dd90e81a964da3a2afda6ee2f6787dbdd
6
+ metadata.gz: 08f7c9b3eb80606e59c7e323b140f7288cc72f5ec3bcb549fa63d2e9b93e01830aeabf5883eb0a67af4be9ce5e7da4c68e341ea1c03338568cf884bb8838b19a
7
+ data.tar.gz: 21cec67eb92bf830b11e30f63a987121e06d1c77b9da182c1558a75c80ec9e00cf85aba6e4ffad5859aee5e2ff1289714c67a21b0f9dea13a2ff4d00b33829c0
@@ -1,20 +1,28 @@
1
1
  require 'gearman/server'
2
+ require 'mysql2'
2
3
  class GearmanServer < Gearman::Server
3
4
  end
4
5
 
5
6
  module Bipbip
6
7
  class Plugin::Gearman < Plugin
8
+ PRIORITY_LOW = 0
9
+ PRIORITY_NORMAL = 1
10
+ PRIORITY_HIGH = 2
11
+
7
12
  def metrics_schema
8
13
  [
9
14
  { name: 'jobs_queued_total', type: 'gauge', unit: 'Jobs' },
10
15
  { name: 'jobs_active_total', type: 'gauge', unit: 'Jobs' },
11
- { name: 'jobs_waiting_total', type: 'gauge', unit: 'Jobs' }
16
+ { name: 'jobs_waiting_total', type: 'gauge', unit: 'Jobs' },
17
+
18
+ { name: 'jobs_queued_total_low', type: 'gauge', unit: 'Jobs' },
19
+ { name: 'jobs_queued_total_normal', type: 'gauge', unit: 'Jobs' },
20
+ { name: 'jobs_queued_total_high', type: 'gauge', unit: 'Jobs' }
12
21
  ]
13
22
  end
14
23
 
15
24
  def monitor
16
- gearman = GearmanServer.new(config['hostname'] + ':' + config['port'].to_s)
17
- stats = gearman.status
25
+ stats = _fetch_gearman_status
18
26
 
19
27
  jobs_queued_total = 0
20
28
  jobs_active_total = 0
@@ -23,11 +31,46 @@ module Bipbip
23
31
  jobs_active_total += data[:active].to_i
24
32
  end
25
33
 
34
+ priority_stats = {}
35
+ if config['persistence'] == 'mysql'
36
+ stats = _fetch_mysql_priority_stats(config)
37
+ priority_stats = {
38
+ jobs_queued_total_low: stats[PRIORITY_LOW],
39
+ jobs_queued_total_normal: stats[PRIORITY_NORMAL],
40
+ jobs_queued_total_high: stats[PRIORITY_HIGH]
41
+ }
42
+ end
43
+
26
44
  {
27
45
  jobs_queued_total: jobs_queued_total,
28
46
  jobs_active_total: jobs_active_total,
29
47
  jobs_waiting_total: (jobs_queued_total - jobs_active_total)
30
- }
48
+ }.merge(priority_stats)
49
+ end
50
+
51
+ private
52
+
53
+ def _fetch_gearman_status
54
+ gearman = GearmanServer.new(config['hostname'] + ':' + config['port'].to_s)
55
+ gearman.status
56
+ end
57
+
58
+ def _fetch_mysql_priority_stats(config)
59
+ mysql = Mysql2::Client.new(
60
+ host: config['mysql_hostname'] || 'localhost',
61
+ port: config['mysql_port'] || 3306,
62
+ username: config['mysql_username'] || nil,
63
+ password: config['mysql_password'] || nil,
64
+ database: config['mysql_database'] || 'gearman'
65
+ )
66
+
67
+ stats = Hash.new(0)
68
+
69
+ mysql.query('SELECT priority, count(priority) as jobs_count FROM gearman_queue GROUP by priority').each do |row|
70
+ stats[row['priority']] = row['jobs_count']
71
+ end
72
+
73
+ stats
31
74
  end
32
75
  end
33
76
  end
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.7.7'.freeze
2
+ VERSION = '0.7.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bipbip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-02 00:00:00.000000000 Z
13
+ date: 2016-11-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: copperegg-revealmetrics
@@ -343,7 +343,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
343
343
  version: '0'
344
344
  requirements: []
345
345
  rubyforge_project:
346
- rubygems_version: 2.6.7
346
+ rubygems_version: 2.6.8
347
347
  signing_key:
348
348
  specification_version: 4
349
349
  summary: Gather services data and store in CopperEgg