QueueSizePlugin::cleanTube()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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