Skip to content

Commit cf4e2d0

Browse files
committed
Remove a bit more Boilerplate code
1 parent 3798cae commit cf4e2d0

File tree

8 files changed

+84
-70
lines changed

8 files changed

+84
-70
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@ jobs:
1111
os: [ ubuntu-latest ]
1212
php: [ 7.2, 7.3, 7.4 ]
1313
dependency-version: [ prefer-lowest, prefer-stable ]
14-
redis-version: [ 6 ]
1514

1615
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
1716

18-
env:
19-
# The hostname used to communicate with the Redis service container
20-
REDIS_HOST: redis
21-
# The default Redis port
22-
REDIS_PORT: 6379
2317
steps:
2418
- name: Checkout code
2519
uses: actions/checkout@v2
@@ -34,15 +28,10 @@ jobs:
3428
uses: shivammathur/setup-php@v2
3529
with:
3630
php-version: ${{ matrix.php }}
37-
extensions: redis
3831
coverage: none
3932

4033
- name: Install dependencies
4134
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
42-
- name: Start Redis
43-
uses: supercharge/redis-github-action@1.1.0
44-
with:
45-
redis-version: ${{ matrix.redis-version }}
4635
- name: Run PHP Code Sniffer
4736
run: ./vendor/bin/phpcs
4837
- name: Execute tests

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# A prometheus push gateway client library written in PHP
2+
3+
![Tests](https://github.com/lkaemmerling/prometheus_push_gateway_php/workflows/Tests/badge.svg)
4+
5+
This package provides an easy PHP API for Prometheus Push Gateway. It was part of https://github.com/LKaemmerling/prometheus_client_php and was moved into a seperate package as of Prometheus Client PHP Version 2.0.0.
6+
7+
## How does it work?
8+
9+
The PushGateway allows Prometheus to get Metrics from Systems that are not scrableable (Your Prometheus cannot access that systems). With this library you can easily send your metrics to the PushGateway.
10+
## Installation
11+
12+
Add as [Composer](https://getcomposer.org/) dependency:
13+
14+
```sh
15+
composer require lkaemmerling/prometheus_push_gateway_php
16+
```
17+
18+
## Usage
19+
20+
Let's assume you have that simple counter and want to send it to your PushGateway.
21+
```php
22+
\Prometheus\CollectorRegistry::getDefault()
23+
->getOrRegisterCounter('', 'some_quick_counter', 'just a quick measurement')
24+
->inc();
25+
26+
// Now send it to the PushGateway:
27+
$pushGateway = new \PrometheusPushGateway\PushGateway('192.168.59.100:9091');
28+
$pushGateway->push(\Prometheus\CollectorRegistry::getDefault(), 'my_job', ['instance' => 'foo']);
29+
```
30+
31+
Also look at the [examples](examples).
32+
33+
## Development
34+
35+
### Dependencies
36+
37+
* PHP ^7.2
38+
* [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)
39+
40+
## Black box testing
41+
42+
Just start the pushgateway by using docker-compose
43+
```
44+
docker-compose up
45+
```
46+
47+
Execute the tests:
48+
```
49+
docker-compose run phpunit vendor/bin/phpunit tests/Test/
50+
```

composer.json

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
{
2-
"name": "lkaemmerling/prometheus_push_gateway_php",
3-
"description": "Prometheus Push Gatewy client for PHP applications.",
4-
"type": "library",
5-
"require": {
6-
"php": "^7.2",
7-
"guzzlehttp/guzzle": "^7.0",
8-
"lkaemmerling/prometheus_client_php": "^1.0"
9-
},
10-
"require-dev": {
11-
"phpunit/phpunit": "^9.3"
12-
},
13-
"license": "Apache-2.0",
14-
"authors": [
15-
{
16-
"name": "Lukas Kämmerling",
17-
"email": "kontakt@lukas-kaemmerling.de"
18-
}
19-
],
20-
"autoload": {
21-
"psr-4": {
22-
"PrometheusPushGateway\\": "src/PrometheusPushGateway/"
23-
}
24-
},
25-
"autoload-dev": {
26-
"psr-0": {
27-
"Test\\PrometheusPushGateway\\": "tests/"
28-
}
2+
"name": "lkaemmerling/prometheus_push_gateway_php",
3+
"description": "Prometheus Push Gateway client for PHP applications.",
4+
"type": "library",
5+
"require": {
6+
"php": "^7.2",
7+
"guzzlehttp/guzzle": "^7.0",
8+
"lkaemmerling/prometheus_client_php": "^1.0"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^9.3",
12+
"squizlabs/php_codesniffer": "^3.5"
13+
},
14+
"license": "Apache-2.0",
15+
"authors": [
16+
{
17+
"name": "Lukas Kämmerling",
18+
"email": "kontakt@lukas-kaemmerling.de"
2919
}
20+
],
21+
"autoload": {
22+
"psr-4": {
23+
"PrometheusPushGateway\\": "src/PrometheusPushGateway/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-0": {
28+
"Test\\PrometheusPushGateway\\": "tests/"
29+
}
30+
}
3031
}

docker-compose.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
nginx:
2-
build: nginx/
3-
links:
4-
- php-fpm
5-
ports:
6-
- 8080:80
7-
8-
php-fpm:
9-
build: php-fpm/
10-
volumes:
11-
- .:/var/www/html
12-
links:
13-
- redis
14-
- pushgateway
15-
environment:
16-
- REDIS_HOST=redis
17-
18-
redis:
19-
image: redis
20-
ports:
21-
- 6379:6379
22-
231
pushgateway:
242
image: prom/pushgateway
253
ports:
@@ -30,8 +8,4 @@ phpunit:
308
volumes:
319
- .:/var/www/html
3210
links:
33-
- redis
3411
- pushgateway
35-
- nginx
36-
environment:
37-
- REDIS_HOST=redis

examples/pushgateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
require __DIR__ . '/../vendor/autoload.php';
44

55
use Prometheus\CollectorRegistry;
6-
use Prometheus\PushGateway;
76
use Prometheus\Storage\Redis;
7+
use PrometheusPushGateway\PushGateway;
88

99
$adapter = $_GET['adapter'];
1010

tests/Test/BlackBoxPushGatewayTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use GuzzleHttp\Client;
66
use PHPUnit\Framework\TestCase;
77
use Prometheus\CollectorRegistry;
8-
use Prometheus\PushGateway;
9-
use Prometheus\Storage\APC;
8+
use Prometheus\Storage\InMemory;
9+
use PrometheusPushGateway\PushGateway;
1010

1111
class BlackBoxPushGatewayTest extends TestCase
1212
{
@@ -15,7 +15,7 @@ class BlackBoxPushGatewayTest extends TestCase
1515
*/
1616
public function pushGatewayShouldWork()
1717
{
18-
$adapter = new APC();
18+
$adapter = new InMemory();
1919
$registry = new CollectorRegistry($adapter);
2020

2121
$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);

tests/Test/PrometheusPushGateway/PushGatewayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PHPUnit\Framework\TestCase;
1010
use Prometheus\CollectorRegistry;
1111
use Prometheus\MetricFamilySamples;
12-
use Prometheus\PushGateway;
12+
use PrometheusPushGateway\PushGateway;
1313

1414
class PushGatewayTest extends TestCase
1515
{

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
exit(1);
1212
}
1313
$loader = require $autoload;
14-
$loader->add('Test\\Prometheus', __DIR__);
14+
$loader->add('Test\\PrometheusPushGateway', __DIR__);
1515

1616
define('REDIS_HOST', isset($_ENV['REDIS_HOST']) ? $_ENV['REDIS_HOST'] : '127.0.0.1');

0 commit comments

Comments
 (0)