Skip to content

Commit

Permalink
Merge pull request #6 from renoki-co/feature/grouping
Browse files Browse the repository at this point in the history
[1.x] Grouping
  • Loading branch information
rennokki authored Sep 27, 2021
2 parents 162428a + a04cc09 commit 7f281b4
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ php artisan vendor:publish --provider="RenokiCo\LaravelExporter\LaravelExporte

## 🙌 Usage

This package is pretty straightforward. Upon installing it, it will register the route at `/exporter/metrics` and you can point Prometheus towards it for scraping.
This package is pretty straightforward. Upon installing it, it will register the route at `/exporter/group/horizon-metrics` and you can point Prometheus towards it for scraping.

Please keep in mind that the metrics are not calculated by-process, but as a whole across all supervisors. Point your Prometheus scraper to one of the instances for horizontally-scaled environments.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": "^8.0",
"renoki-co/laravel-exporter-contracts": "^1.0",
"renoki-co/laravel-exporter-contracts": "^1.1",
"laravel/horizon": "^5.7"
},
"autoload": {
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/JobsByType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class JobsByType extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/JobsRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class JobsRuntime extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/JobsThroughput.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class JobsThroughput extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/MasterStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class MasterStatus extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/MasterSupervisorsStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class MasterSupervisorsStatus extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/QueuesRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class QueuesRuntime extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Metrics/QueuesThroughput.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class QueuesThroughput extends Metric
*/
protected $collector;

/**
* The group this metric gets shown into.
*
* @var string|null
*/
public static $showsOnGroup = 'horizon-metrics';

/**
* Perform the update call on the collector.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function test_http_metrics()
$this->work();
$this->work();

$this->get('/exporter/metrics')
$this->get('/exporter/group/horizon-metrics')
->assertSee('horizon_jobs_by_type{type="completed"} 3', escape: false);
}
}
18 changes: 9 additions & 9 deletions tests/MetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function test_master_status_metric()
resolve(MasterSupervisorRepository::class)->update($master1);
resolve(MasterSupervisorRepository::class)->update($master2);

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString("horizon_master_status{name=\"master-1\",pid=\"{$master1->pid()}\"} 2", $response);
$this->assertStringContainsString("horizon_master_status{name=\"master-2\",pid=\"{$master2->pid()}\"} 1", $response);
Expand All @@ -50,7 +50,7 @@ public function test_master_supervisors_status_metric()

$master->loop();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
"horizon_supervisor_status{name=\"{$supervisor->name}\",master=\"{$master->name}\",pid=\"{$master->pid()}\"} 2",
Expand Down Expand Up @@ -82,7 +82,7 @@ public function test_queues_throughput_metric()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_queue_throughput{queue="default"} 6',
Expand Down Expand Up @@ -118,7 +118,7 @@ public function test_jobs_throughput_metric()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_job_throughput{job="RenokiCo\\\\HorizonExporter\\\\Test\\\\Jobs\\\\BasicJob"} 6',
Expand Down Expand Up @@ -155,7 +155,7 @@ public function test_queues_runtime_metric()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_queue_runtime{queue="default"}',
Expand Down Expand Up @@ -191,7 +191,7 @@ public function test_jobs_runtime_metric()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_job_runtime{job="RenokiCo\\\\HorizonExporter\\\\Test\\\\Jobs\\\\BasicJob"}',
Expand Down Expand Up @@ -223,7 +223,7 @@ public function test_jobs_throughput_by_type()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_jobs_by_type{type="completed"} 4',
Expand Down Expand Up @@ -265,7 +265,7 @@ public function test_memory_is_kept_between_sessions()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_queue_throughput{queue="default"} 3',
Expand All @@ -280,7 +280,7 @@ public function test_memory_is_kept_between_sessions()
$this->work();
$this->work();

$response = Exporter::exportAsPlainText();
$response = Exporter::exportAsPlainText('horizon-metrics');

$this->assertStringContainsString(
'horizon_queue_throughput{queue="default"} 6',
Expand Down

0 comments on commit 7f281b4

Please sign in to comment.