Skip to content

Commit

Permalink
Merge pull request #16 from 4nkitd/feature/dynamic_db_connection
Browse files Browse the repository at this point in the history
Ignore matched string `it helps to ignore the matched string in the q…
  • Loading branch information
sarfraznawaz2005 authored Dec 15, 2022
2 parents 1c9304e + 0ba52f7 commit 09167d5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ Available options are:
- METER_PASSWORD
` Password to access meter UI. Default: null `

```php
"ignore_matched_string" => [
"query" => [
"information_schema",
]

],
```
### Ignore matched string `it helps to ignore the matched string in the query`
```php

there are a lot more options available, please check `config/meter.php` file for more details.

## Monitors ##
Expand Down
8 changes: 8 additions & 0 deletions src/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
//
],

'ignore_matched_string' => [

"query" => [
"information_schema",
]

],

#---------------------------------------------------------------------

/*
Expand Down
7 changes: 7 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ function meterFormatModel(Model $model)
return get_class($model) . ':' . implode('_', Arr::wrap($model->getKey()));
}
}

if (!function_exists('meterIgnoreEntry')) {
function meterIgnoreEntry($key, $content)
{
return str_contains($content, $key);
}
}
39 changes: 34 additions & 5 deletions src/Monitors/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,40 @@ public function record($type, $isSlow, array $content)
{
Meter::stopMonitoring();

$result = $this->model->create([
'type' => $type,
'is_slow' => $isSlow ? 'Yes' : 'No',
'content' => $content,
]);
$result = true;
$skip = false;

if (count(config('meter.ignore_matched_string', [])) > 0) {

foreach (config('meter.ignore_matched_string', []) as $queryType) {

if (!is_array($queryType)) {
continue;
}

if(count($queryType) == 0) {
continue;
}

foreach ($queryType as $string) {
if (in_array($string, $content)) {
$skip = true;
break;
}
}
}

}

if ($skip === false) {

$result = $this->model->create([
'type' => $type,
'is_slow' => $isSlow ? '1' : '0',
'content' => $content,
'created_at' => now(),
]);
}

Meter::startMonitoring();

Expand Down

0 comments on commit 09167d5

Please sign in to comment.