Skip to content

Commit 09167d5

Browse files
Merge pull request #16 from 4nkitd/feature/dynamic_db_connection
Ignore matched string `it helps to ignore the matched string in the q…
2 parents 1c9304e + 0ba52f7 commit 09167d5

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ Available options are:
2222
- METER_PASSWORD
2323
` Password to access meter UI. Default: null `
2424

25+
```php
26+
"ignore_matched_string" => [
27+
"query" => [
28+
"information_schema",
29+
]
30+
31+
],
32+
```
33+
### Ignore matched string `it helps to ignore the matched string in the query`
34+
```php
35+
2536
there are a lot more options available, please check `config/meter.php` file for more details.
2637

2738
## Monitors ##

src/Config/config.php

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
//
5757
],
5858

59+
'ignore_matched_string' => [
60+
61+
"query" => [
62+
"information_schema",
63+
]
64+
65+
],
66+
5967
#---------------------------------------------------------------------
6068

6169
/*

src/Helpers.php

+7
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,10 @@ function meterFormatModel(Model $model)
7373
return get_class($model) . ':' . implode('_', Arr::wrap($model->getKey()));
7474
}
7575
}
76+
77+
if (!function_exists('meterIgnoreEntry')) {
78+
function meterIgnoreEntry($key, $content)
79+
{
80+
return str_contains($content, $key);
81+
}
82+
}

src/Monitors/Monitor.php

+34-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,40 @@ public function record($type, $isSlow, array $content)
5555
{
5656
Meter::stopMonitoring();
5757

58-
$result = $this->model->create([
59-
'type' => $type,
60-
'is_slow' => $isSlow ? 'Yes' : 'No',
61-
'content' => $content,
62-
]);
58+
$result = true;
59+
$skip = false;
60+
61+
if (count(config('meter.ignore_matched_string', [])) > 0) {
62+
63+
foreach (config('meter.ignore_matched_string', []) as $queryType) {
64+
65+
if (!is_array($queryType)) {
66+
continue;
67+
}
68+
69+
if(count($queryType) == 0) {
70+
continue;
71+
}
72+
73+
foreach ($queryType as $string) {
74+
if (in_array($string, $content)) {
75+
$skip = true;
76+
break;
77+
}
78+
}
79+
}
80+
81+
}
82+
83+
if ($skip === false) {
84+
85+
$result = $this->model->create([
86+
'type' => $type,
87+
'is_slow' => $isSlow ? '1' : '0',
88+
'content' => $content,
89+
'created_at' => now(),
90+
]);
91+
}
6392

6493
Meter::startMonitoring();
6594

0 commit comments

Comments
 (0)