1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHPProm package. |
5
|
|
|
* |
6
|
|
|
* (c) Philip Lehmann-Böhm <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PHPProm\Storage; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AbstractStorage |
16
|
|
|
* The parent class of all storage implementations. |
17
|
|
|
* @package PHPProm\Storage |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractStorage { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
* Holds the available metrics. |
24
|
|
|
*/ |
25
|
|
|
protected $availableMetrics; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* AbstractStorage constructor. |
29
|
|
|
*/ |
30
|
|
|
public function __construct() { |
31
|
|
|
$this->availableMetrics = []; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Adds a metric to the available ones. |
36
|
|
|
* |
37
|
|
|
* @param string $metric |
38
|
|
|
* the metric itself as delivered by Prometheus |
39
|
|
|
* @param string $label |
40
|
|
|
* the name of the one Prometheus label to categorize the values |
41
|
|
|
* @param string $help |
42
|
|
|
* a helping text for the metric |
43
|
|
|
* @param string $type |
44
|
|
|
* the Prometheus type of the metric |
45
|
|
|
* @param string $defaultValue |
46
|
|
|
* the default value which the metric gets if there is no value stored |
47
|
|
|
*/ |
48
|
|
|
public function addAvailableMetric($metric, $label, $help, $type, $defaultValue) { |
49
|
|
|
$this->availableMetrics[] = [ |
50
|
|
|
'metric' => $metric, |
51
|
|
|
'label' => $label, |
52
|
|
|
'help' => $help, |
53
|
|
|
'type' => $type, |
54
|
|
|
'defaultValue' => $defaultValue |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Gets all available metrics in an array. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
* the available metrics |
63
|
|
|
*/ |
64
|
|
|
public function getAvailableMetrics() { |
65
|
|
|
return $this->availableMetrics; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Stores a measurement. |
70
|
|
|
* |
71
|
|
|
* @param string $metric |
72
|
|
|
* the name of the metric |
73
|
|
|
* @param string $key |
74
|
|
|
* the key |
75
|
|
|
* @param float $value |
76
|
|
|
* the value |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
abstract public function storeMeasurement($metric, $key, $value); |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Increments a measurement, starting with 1 if it doesn't exist yet. |
83
|
|
|
* @param string $metric |
84
|
|
|
* the name of the metric |
85
|
|
|
* @param string $key |
86
|
|
|
* the key |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
abstract public function incrementMeasurement($metric, $key); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Gets all measurements. |
93
|
|
|
* |
94
|
|
|
* @param string $metric |
95
|
|
|
* the name of the metric |
96
|
|
|
* @param array $keys |
97
|
|
|
* the keys to retrieve |
98
|
|
|
* @param string $defaultValue |
99
|
|
|
* the default value a key gets if there is no value for it in the storage |
100
|
|
|
* @return array |
101
|
|
|
* the map with the keys and values |
102
|
|
|
*/ |
103
|
|
|
abstract public function getMeasurements($metric, array $keys, $defaultValue = 'Nan'); |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|