|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of graze/dog-statsd |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md |
|
11
|
|
|
* @link https://github.com/graze/dog-statsd |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Graze\DogStatsD\Test\Unit; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\DogStatsD\Client; |
|
17
|
|
|
use Graze\DogStatsD\Test\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
class ServiceCheckTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testSimpleServiceCheck() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->client->serviceCheck('service.api', Client::STATUS_OK); |
|
24
|
|
|
$this->assertEquals('_sc|service.api|0', $this->client->getLastMessage()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testMetaData() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->client->serviceCheck( |
|
30
|
|
|
'service.api', |
|
31
|
|
|
Client::STATUS_CRITICAL, |
|
32
|
|
|
[ |
|
33
|
|
|
'time' => 12345678, |
|
34
|
|
|
'hostname' => 'some.host', |
|
35
|
|
|
] |
|
36
|
|
|
); |
|
37
|
|
|
$this->assertEquals( |
|
38
|
|
|
'_sc|service.api|2|d:12345678|h:some.host', |
|
39
|
|
|
$this->client->getLastMessage() |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testTags() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->client->serviceCheck( |
|
46
|
|
|
'service.api', |
|
47
|
|
|
Client::STATUS_WARNING, |
|
48
|
|
|
[ |
|
49
|
|
|
'time' => 12345678, |
|
50
|
|
|
'hostname' => 'some.host', |
|
51
|
|
|
], |
|
52
|
|
|
['tag'] |
|
53
|
|
|
); |
|
54
|
|
|
$this->assertEquals( |
|
55
|
|
|
'_sc|service.api|1|d:12345678|h:some.host|#tag', |
|
56
|
|
|
$this->client->getLastMessage() |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testMessageIsAfterTags() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->client->serviceCheck( |
|
63
|
|
|
'service.api', |
|
64
|
|
|
Client::STATUS_UNKNOWN, |
|
65
|
|
|
[ |
|
66
|
|
|
'time' => 12345678, |
|
67
|
|
|
'message' => 'some_message', |
|
68
|
|
|
], |
|
69
|
|
|
['tag'] |
|
70
|
|
|
); |
|
71
|
|
|
$this->assertEquals( |
|
72
|
|
|
'_sc|service.api|3|d:12345678|#tag|m:some_message', |
|
73
|
|
|
$this->client->getLastMessage() |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testCoreStatsDImplementation() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->client->configure([ |
|
80
|
|
|
'host' => '127.0.0.1', |
|
81
|
|
|
'port' => 8125, |
|
82
|
|
|
'dataDog' => false, |
|
83
|
|
|
]); |
|
84
|
|
|
$this->client->serviceCheck('service.api', Client::STATUS_OK); |
|
85
|
|
|
$this->assertEquals('', $this->client->getLastMessage()); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|