1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ZoiloMora\ElasticAPM\Events\Common; |
4
|
|
|
|
5
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\System\Container; |
6
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\System\Kubernetes; |
7
|
|
|
use ZoiloMora\ElasticAPM\Helper\Encoding; |
8
|
|
|
|
9
|
|
|
class System implements \JsonSerializable |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Architecture of the system the agent is running on. |
13
|
|
|
* |
14
|
|
|
* @var string|null |
15
|
|
|
*/ |
16
|
|
|
private $architecture; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Hostname of the host the monitored service is running on. |
20
|
|
|
* It normally contains what the hostname command returns on the host machine. |
21
|
|
|
* Will be ignored if kubernetes information is set, otherwise should always be set. |
22
|
|
|
* |
23
|
|
|
* @var string|null |
24
|
|
|
*/ |
25
|
|
|
private $detectedHostname; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Name of the host the monitored service is running on. |
29
|
|
|
* It should only be set when configured by the user. |
30
|
|
|
* If empty, will be set to detected_hostname or derived from kubernetes information if provided. |
31
|
|
|
* |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $configuredHostname; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Name of the system platform the agent is running on. |
38
|
|
|
* |
39
|
|
|
* @var string|null |
40
|
|
|
*/ |
41
|
|
|
private $platform; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Container|null |
45
|
|
|
*/ |
46
|
|
|
private $container; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Kubernetes|null |
50
|
|
|
*/ |
51
|
|
|
private $kubernetes; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string|null $architecture |
55
|
|
|
* @param string|null $detectedHostname |
56
|
|
|
* @param string|null $configuredHostname |
57
|
|
|
* @param string|null $platform |
58
|
|
|
* @param Container|null $container |
59
|
|
|
* @param Kubernetes|null $kubernetes |
60
|
|
|
*/ |
61
|
14 |
|
public function __construct( |
62
|
|
|
$architecture = null, |
63
|
|
|
$detectedHostname = null, |
64
|
|
|
$configuredHostname = null, |
65
|
|
|
$platform = null, |
66
|
1 |
|
Container $container = null, |
67
|
1 |
|
Kubernetes $kubernetes = null |
68
|
|
|
) { |
69
|
14 |
|
$this->architecture = $architecture; |
70
|
14 |
|
$this->detectedHostname = $detectedHostname; |
71
|
14 |
|
$this->configuredHostname = $configuredHostname; |
72
|
14 |
|
$this->platform = $platform; |
73
|
14 |
|
$this->container = $container; |
74
|
14 |
|
$this->kubernetes = $kubernetes; |
75
|
14 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string|null |
79
|
|
|
*/ |
80
|
1 |
|
public function architecture() |
81
|
|
|
{ |
82
|
1 |
|
return $this->architecture; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string|null |
87
|
|
|
*/ |
88
|
1 |
|
public function detectedHostname() |
89
|
|
|
{ |
90
|
1 |
|
return $this->detectedHostname; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return string|null |
95
|
|
|
*/ |
96
|
1 |
|
public function configuredHostname() |
97
|
|
|
{ |
98
|
1 |
|
return $this->configuredHostname; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string|null |
103
|
|
|
*/ |
104
|
1 |
|
public function platform() |
105
|
|
|
{ |
106
|
1 |
|
return $this->platform; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return Container|null |
111
|
|
|
*/ |
112
|
1 |
|
public function container() |
113
|
|
|
{ |
114
|
1 |
|
return $this->container; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return Kubernetes|null |
119
|
|
|
*/ |
120
|
1 |
|
public function kubernetes() |
121
|
|
|
{ |
122
|
1 |
|
return $this->kubernetes; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return System |
127
|
|
|
*/ |
128
|
11 |
|
public static function discover() |
129
|
|
|
{ |
130
|
11 |
|
return new self( |
131
|
11 |
|
php_uname('m'), |
132
|
11 |
|
php_uname('n'), |
133
|
11 |
|
null, |
134
|
11 |
|
php_uname('s'), |
135
|
11 |
|
Container::discover(), |
136
|
11 |
|
Kubernetes::discover() |
137
|
11 |
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
1 |
|
public function jsonSerialize() |
144
|
|
|
{ |
145
|
|
|
return [ |
146
|
1 |
|
'architecture' => Encoding::keywordField($this->architecture), |
147
|
1 |
|
'detected_hostname' => Encoding::keywordField($this->detectedHostname), |
148
|
1 |
|
'configured_hostname' => Encoding::keywordField($this->configuredHostname), |
149
|
1 |
|
'platform' => Encoding::keywordField($this->platform), |
150
|
1 |
|
'container' => $this->container, |
151
|
1 |
|
'kubernetes' => $this->kubernetes, |
152
|
1 |
|
]; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|