Skip to content

Commit b4c6e7e

Browse files
add cleanup data patch to delete metrics with wrong structure
1 parent c4feae7 commit b4c6e7e

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ in the table and renders the correct response for prometheus.
4848

4949
The following metrics will be collected:
5050

51-
| Metric | Labels | TYPE | Help |
52-
|:------------------------------------|:--------------------------------|:------|:-----------------------------------------------------------------------------|
53-
| magento_orders_count_total | status, store_code | gauge | All Magento Orders |
54-
| magento_orders_amount_total | status, store_code | gauge | Total amount of all Magento Orders |
55-
| magento_order_items_count_total | status, store_code | gauge | Total count of orderitems |
56-
| magento_cms_block_count_total | store_code | gauge | Total count of available cms blocks |
57-
| magento_cms_page_count_total | store_code | gauge | Total count of available cms pages |
58-
| magento_customer_count_total | store_code | gauge | Total count of available customer |
59-
| magento_cronjob_broken_count_total | | gauge | Broken CronJobs occur when when status is pending but execution_time is set. |
60-
| magento_cronjob_count_total | status, job_code | gauge | Total count of available CronJob Count. |
61-
| magento_indexer_backlog_count_total | isValid, title, status | gauge | Total count of backlog item in indexer. |
62-
| magento_shipments_count_total | source, store_code | counter| Count of Shipments created by store and source. |
63-
| magento_catalog_category_count_total| status, menu_status, store_code | gauge | Count of Categories by store, status and menu status. |
64-
| magento_store_count_total | status | gauge | Total count of Stores by status. |
65-
| magento_website_count_total | | gauge | Total count websites. |
51+
| Metric | Labels | TYPE | Help |
52+
|:-------------------------------------|:--------------------------------|:--------|:--------------------------------------------------------------------------------|
53+
| magento_orders_count_total | status, store_code | gauge | All Magento Orders |
54+
| magento_orders_amount_total | status, store_code | gauge | Total amount of all Magento Orders |
55+
| magento_order_items_count_total | status, store_code | gauge | Total count of orderitems |
56+
| magento_cms_block_count_total | store_code | gauge | Total count of available cms blocks |
57+
| magento_cms_page_count_total | store_code | gauge | Total count of available cms pages |
58+
| magento_customer_count_total | store_code | gauge | Total count of available customer |
59+
| magento_cronjob_broken_count_total | | gauge | Broken CronJobs occur when when status is pending but execution_time is set. |
60+
| magento_cronjob_count_total | status, job_code | gauge | Total count of available CronJob Count. |
61+
| magento_indexer_backlog_count_total | title | gauge | Total count of backlog item in indexer (the data from `indexer:status` command) |
62+
| magento_shipments_count_total | source, store_code | counter | Count of Shipments created by store and source. |
63+
| magento_catalog_category_count_total | status, menu_status, store_code | gauge | Count of Categories by store, status and menu status. |
64+
| magento_store_count_total | status | gauge | Total count of Stores by status. |
65+
| magento_website_count_total | | gauge | Total count websites. |
6666

6767
## Add you own Metric
6868

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
<?php
22

3-
class CleanIndexerBacklogCountDataPatch
3+
declare(strict_types=1);
4+
5+
namespace RunAsRoot\PrometheusExporter\Setup\Patch\Data;
6+
7+
use Magento\Framework\Api\SearchCriteriaBuilder;
8+
use Magento\Framework\Exception\CouldNotDeleteException;
9+
use Magento\Framework\Setup\Patch\DataPatchInterface;
10+
use RunAsRoot\PrometheusExporter\Api\Data\MetricInterface;
11+
use RunAsRoot\PrometheusExporter\Repository\MetricRepository;
12+
13+
class CleanIndexerBacklogCountDataPatch implements DataPatchInterface
414
{
5-
//todo:
15+
private const METRIC_CODE = 'magento_indexer_backlog_count_total';
16+
17+
public function __construct(
18+
private readonly MetricRepository $metricRepository,
19+
private readonly SearchCriteriaBuilder $searchCriteriaBuilder
20+
) {
21+
}
22+
23+
public static function getDependencies(): array
24+
{
25+
return [];
26+
}
27+
28+
public function getAliases(): array
29+
{
30+
return [];
31+
}
32+
33+
/**
34+
* @throws CouldNotDeleteException
35+
*/
36+
public function apply(): void
37+
{
38+
$searchCriteriaMetrics = $this->searchCriteriaBuilder->addFilter('code', self::METRIC_CODE)->create();
39+
$metricsSearchResult = $this->metricRepository->getList($searchCriteriaMetrics);
40+
$metrics = $metricsSearchResult->getItems();
41+
/** @var MetricInterface $metric */
42+
foreach ($metrics as $metric) {
43+
$this->metricRepository->delete($metric);
44+
}
45+
}
646
}

0 commit comments

Comments
 (0)