CommandRatePlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 18 2
A data() 0 9 2
1
<?php
2
3
/**
4
 * @file
5
 * Munin plugin for Beanstalkd Command Rate 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 CommandRatePlugin extends BasePlugin
17
{
18
19
    public array $commands = [
20
      ['put', 'cmd-put', 'Put'],
21
      ['reserve', 'cmd-reserve', 'Reserve'],
22
      ['reserve_timeout', 'cmd-reserve-with-timeout', 'Reserve with timeout'],
23
      ['delete', 'cmd-delete', 'Delete'],
24
      ['touch', 'cmd-touch', 'Touch'],
25
      ['release', 'cmd-release', 'Release'],
26
      ['bury', 'cmd-bury', 'Bury'],
27
    ];
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function config(): string
33
    {
34
        $ret = <<<'CONFIG'
35
graph_title Command Rate
36
graph_vlabel Commands per ${graph_period}
37
graph_category Beanstalk
38
graph_args --lower-limit 0
39
graph_scale no
40
41
CONFIG;
42
43
        foreach ($this->commands as $cmd) {
44
            [$name, , $label] = $cmd;
45
            $ret .= sprintf("cmd_%s.label %s\n", $name, $label)
46
              . sprintf("cmd_%s.type DERIVE\n", $name)
47
              . sprintf("cmd_%s.min 0\n", $name);
48
        }
49
        return $ret;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function data(): string
56
    {
57
        $stats = $this->server->stats();
58
        $ret = '';
59
        foreach ($this->commands as $cmd) {
60
            [$name, $counter,] = $cmd;
61
            $ret .= sprintf("cmd_%s.value %d\n", $name, $stats[$counter]);
62
        }
63
        return $ret;
64
    }
65
}
66