QueueSizePlugin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 29
c 1
b 0
f 0
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 18 2
A cleanTube() 0 3 1
A data() 0 11 2
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-2020 Ouest Systèmes Informatiques (OSInet)
9
 * @license Apache License 2.0 or later
10
 */
11
12
declare(strict_types=1);
13
14
namespace OSInet\Beanstalkd\Munin;
15
16
class QueueSizePlugin extends BasePlugin
17
{
18
19
    public array $jobTypes = [
20
      ['ready', 'current-jobs-ready', 'Ready'],
21
      ['urgent', 'current-jobs-urgent', 'Urgent'],
22
      ['reserved', 'current-jobs-reserved', 'Reserved'],
23
      ['delayed', 'current-jobs-delayed', 'Delayed'],
24
      ['buried', 'current-jobs-buried', 'Buried'],
25
    ];
26
27
    public static function cleanTube($tube)
28
    {
29
        return str_replace('.', '_', $tube);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function config(): string
36
    {
37
        $ret = <<<'CONFIG'
38
graph_title Queue Size
39
graph_vlabel Number of jobs in the queue
40
graph_category Beanstalk
41
graph_args --lower-limit 0
42
graph_scale no
43
44
CONFIG;
45
46
        foreach ($this->jobTypes as $jobType) {
47
            [$name, , $label] = $jobType;
48
            $ret .= sprintf("%s.label %s\n", $name, $label)
49
              . sprintf("%s.type GAUGE\n", $name)
50
              . sprintf("%s.min 0\n", $name);
51
        }
52
        return $ret;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function data(): string
59
    {
60
        $server = $this->server;
61
        $stats = $server->stats();
62
        $ret = '';
63
        foreach ($this->jobTypes as $jobType) {
64
            [$name, $machine,] = $jobType;
65
            $ret .= sprintf("%s.value %d\n", $name, $stats[$machine]);
66
        }
67
68
        return $ret;
69
    }
70
}
71