This repository was archived by the owner on Oct 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathCollector.php
More file actions
74 lines (63 loc) · 1.81 KB
/
Collector.php
File metadata and controls
74 lines (63 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Prometheus;
use Prometheus\Storage\Adapter;
abstract class Collector
{
const RE_METRIC_LABEL_NAME = '/^[a-zA-Z_:][a-zA-Z0-9_:]*$/';
protected $storageAdapter;
protected $name;
protected $help;
protected $labels;
/**
* @param Adapter $storageAdapter
* @param string $namespace
* @param string $name
* @param string $help
* @param array $labels
*/
public function __construct(Adapter $storageAdapter, $namespace, $name, $help, $labels = [])
{
$this->storageAdapter = $storageAdapter;
$metricName = ($namespace ? $namespace . '_' : '') . $name;
if (!preg_match(self::RE_METRIC_LABEL_NAME, $metricName)) {
throw new \InvalidArgumentException("Invalid metric name: '" . $metricName . "'");
}
$this->name = $metricName;
$this->help = $help;
foreach ($labels as $label) {
if (!preg_match(self::RE_METRIC_LABEL_NAME, $label)) {
throw new \InvalidArgumentException("Invalid label name: '" . $label . "'");
}
}
$this->labels = $labels;
}
/**
* @return string
*/
abstract public function getType();
public function getName()
{
return $this->name;
}
public function getLabelNames()
{
return $this->labels;
}
public function getHelp()
{
return $this->help;
}
public function getKey()
{
return sha1($this->getName() . serialize($this->getLabelNames()));
}
/**
* @param $labels
*/
protected function assertLabelsAreDefinedCorrectly($labels)
{
if (count($labels) != count($this->labels)) {
throw new \InvalidArgumentException(sprintf('Labels are not defined correctly: ', print_r($labels, true)));
}
}
}