Completed
Pull Request — master (#4)
by Frédéric G.
06:18 queued 05:15
created

QueueSizePlugin::data()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @file
5
 * Munin plugin for Beanstalkd queue size monitoring
6
 *
7
 * @author: Frédéric G. MARAND <[email protected]>
8
 * @copyright (c) 2014-2018 Ouest Systèmes Informatiques (OSInet)
9
 * @license Apache License 2.0 or later
10
 */
11
12
namespace OSInet\Beanstalkd\Munin;
13
14
class QueueSizePlugin extends BasePlugin
15
{
16
    public $jobTypes = [
17
      ['ready', 'current-jobs-ready', 'Ready'],
18
      ['urgent', 'current-jobs-urgent', 'Urgent'],
19
      ['reserved', 'current-jobs-reserved', 'Reserved'],
20
      ['delayed', 'current-jobs-delayed', 'Delayed'],
21
      ['buried', 'current-jobs-buried', 'Buried'],
22
    ];
23
24
    public static function cleanTube($tube)
25
    {
26
        return str_replace('.', '_', $tube);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function config()
33
    {
34
        $ret = <<<'EOT'
35
graph_title Queue Size
36
graph_vlabel Number of jobs in the queue
37
graph_category Beanstalk
38
graph_args --lower-limit 0
39
graph_scale no
40
41
EOT;
42
43
        foreach ($this->jobTypes as $jobType) {
44
            list($name, , $label) = $jobType;
45
            $ret .= sprintf("%s.label %s\n", $name, $label)
46
              . sprintf("%s.type GAUGE\n", $name)
47
              . sprintf("%s.min 0\n", $name);
48
        }
49
        return $ret;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function data()
56
    {
57
        //      print '%s.value %d' % (j[0], stats[j[1]])
58
        //
59
        $server = $this->server;
60
        $stats = $server->stats();
61
        $ret = '';
62
        foreach ($this->jobTypes as $jobType) {
63
            list($name, $machine,) = $jobType;
64
            $ret .= sprintf("%s.value %d\n", $name, $stats[$machine]);
65
        }
66
67
        return $ret;
68
    }
69
}
70