-
Notifications
You must be signed in to change notification settings - Fork 30
Introducing monitoring #1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Introducing monitoring #1960
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3c74ee9
Introducing monitoring
BentiGorlich 0441809
Add filtering, fix some things
BentiGorlich 047cef9
Move to First-In-Last-Out for the twig renders
BentiGorlich 5a0f5cd
Remove control characters from the query parameters
BentiGorlich e67a541
Swap the property in which the message class is back
BentiGorlich 03d3fb2
End execution context on kernel termination
BentiGorlich 780f98a
Add response sending time to requests
BentiGorlich bd1a226
Add response sending time to requests
BentiGorlich 3289d42
Space optimizations, more filtering
BentiGorlich 57be742
Fix exception due to routing failing
BentiGorlich d9858e8
Fix min duration filter not working
BentiGorlich 56fad25
Add more monitoring options
BentiGorlich 4336f27
Fix messages.en.yaml
BentiGorlich ee7d00a
Remove unnecessary escaping (triggered deprecation)
BentiGorlich b496acc
Merge branch 'main' into new/monitoring
BentiGorlich 063d684
Add some documentation
BentiGorlich 6491849
Adapt docs, add command to delete monitoring data
BentiGorlich 8fedc31
Show hint at admin page if monitoring is disabled
BentiGorlich 29a7b89
Add docs for the new command
BentiGorlich dc21c6e
Merge branch 'main' into new/monitoring
BentiGorlich 831f6c5
Move command docs to miscellaneous
BentiGorlich 51619e9
Merge branch 'main' into new/monitoring
BentiGorlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| .page-admin-monitoring { | ||
| h1, h2, h3, h4, h5, h6 { | ||
| margin-top: 0; | ||
| } | ||
| .monitoring-twig-render { | ||
| .children { | ||
| margin-left: 2rem; | ||
| } | ||
| } | ||
|
|
||
| .more { | ||
| background: var(--kbin-bg); | ||
| cursor: pointer; | ||
| text-align: center; | ||
| width: 100%; | ||
| margin-top: 1rem; | ||
|
|
||
| // bigger button for touch devices | ||
| @media (pointer:none), (pointer:coarse) { | ||
| margin-top: 2rem; | ||
| padding: 0.5rem; | ||
| } | ||
|
|
||
| i { | ||
| padding: .35rem; | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| .rounded-edges & { | ||
| border-radius: var(--kbin-rounded-edges-radius); | ||
| } | ||
| } | ||
|
|
||
| input[type=text], | ||
| input[type=datetime-local], | ||
| select { | ||
| padding: 0.65rem; | ||
| width: 100%; | ||
| } | ||
|
|
||
| form div { | ||
| margin-bottom: .25rem; | ||
| } | ||
|
|
||
| table tr { | ||
| vertical-align: top; | ||
| td.query * { | ||
| margin: 0; | ||
| overflow: hidden; | ||
| } | ||
| } | ||
|
|
||
| .row { | ||
| display: flex; | ||
| flex-direction: row; | ||
|
|
||
| .col { | ||
| flex: 1 1; | ||
| margin-bottom: 0; | ||
| padding: 0 .25rem; | ||
| } | ||
|
|
||
| .col-auto { | ||
| flex: 0 0 auto; | ||
| margin-bottom: 0; | ||
| } | ||
|
|
||
| .btn-col { | ||
| text-align: right; | ||
| margin: auto; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Internal Mbin Monitoring | ||
|
|
||
| We have a few environment variables that can enable monitoring of the mbin server, | ||
| specifically the executed database queries, rendered html components and requested web resources during the execution of | ||
| an HTTP request or a message handler (a background job). | ||
| This allows the admin to collect performance metrics for optimizing the server settings, | ||
| or developers to optimize the code. | ||
|
|
||
| Enabling monitoring on your server will have a performance impact. It is not necessarily noticeable for your users, | ||
| but it will increase the resource consumption. | ||
| During an execution context (request or messenger) the server will collect monitoring information according to your settings. | ||
| After the execution is finished the collected information will be saved to the DB according to your settings | ||
| (which is the main performance impact and happens after a request is finished). | ||
|
|
||
| The available settings are: | ||
| - `MBIN_MONITORING_ENABLED`: Whether monitoring is enabled at all, if `false` then the other settings do not matter | ||
| - `MBIN_MONITORING_QUERIES_ENABLED`: Whether to monitor query execution, defaults to true | ||
| - `MBIN_MONITORING_QUERY_PERSISTING_ENABLED`: Whether the monitored queries are persisted to the database. If this is disabled only the total query time will be persisted. | ||
| - `MBIN_MONITORING_QUERY_PARAMETERS_ENABLED`: Whether the parameter of database queries should be saved. If enabled the spaces used might increase a lot. | ||
| - `MBIN_MONITORING_TWIG_RENDERS_ENABLED`: Whether to monitor twig rendering, defaults to true | ||
| - `MBIN_MONITORING_TWIG_RENDER_PERSISTING_ENABLED`: Whether to persist the monitored twig renders. If this is disabled only the total rendering time will be persisted. | ||
| - `MBIN_MONITORING_CURL_REQUESTS_ENABLED`: Whether to monitor curl requests, defaults to true | ||
| - `MBIN_MONITORING_CURL_REQUEST_PERSISTING_ENABLED`: Whether to persist the monitored curl requests. If this is disabled only total request time will be persisted. | ||
|
|
||
| If the monitoring of e.g. queries is enabled, but the persistence is not, | ||
| then the execution context will have a total duration of the executed queries, | ||
| but you cannot inspect the executed queries. | ||
|
|
||
| Depending on your persistence settings the monitoring can take up a lot of space. | ||
| The largest amount will come from the queries, then the twig renders and at last the curl requests. | ||
|
|
||
| > [!TIP] | ||
| > To delete you monitoring data see [cli docs](../04-running-mbin/05-cli.md#delete-monitoring-data). | ||
|
|
||
| ## UI | ||
|
|
||
| At `/admin/monitoring` is the overview of the monitoring. There you can see a chart of the longest taking execution contexts. | ||
| Underneath that is a table containing the most recent execution contexts according to your filter settings. | ||
| The chart also takes the filter settings into account. | ||
|
|
||
| By clicking the alphanumeric string in the first column of the table (part of the GUID of the execution context) | ||
| you get to the overview of that context, containing the meta information about this context. | ||
|
|
||
| > [!TIP] | ||
| > The percentage numbers of "SQL Queries", "Twig Renders" and "Curl Requests" do not necessarily add up to 100% or even below 100%, | ||
| > because "Twig Renders" could execute database queries for example. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DoctrineMigrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| final class Version20260120175744 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return 'Add initial monitoring tables'; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| $this->addSql('CREATE SEQUENCE monitoring_curl_request_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
| $this->addSql('CREATE SEQUENCE monitoring_query_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
| $this->addSql('CREATE SEQUENCE monitoring_twig_render_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
| $this->addSql('CREATE TABLE monitoring_curl_request (id INT NOT NULL, context_id UUID DEFAULT NULL, url VARCHAR(255) NOT NULL, method VARCHAR(255) NOT NULL, was_successful BOOLEAN NOT NULL, exception VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, started_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, started_at_microseconds DOUBLE PRECISION NOT NULL, ended_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, ended_at_microseconds DOUBLE PRECISION NOT NULL, duration_milliseconds DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))'); | ||
| $this->addSql('CREATE INDEX IDX_19A4B8546B00C1CF ON monitoring_curl_request (context_id)'); | ||
| $this->addSql('CREATE TABLE monitoring_execution_context (uuid UUID NOT NULL, execution_type VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, handler VARCHAR(255) NOT NULL, user_type VARCHAR(255) NOT NULL, status_code INT DEFAULT NULL, exception VARCHAR(255) DEFAULT NULL, stacktrace VARCHAR(255) DEFAULT NULL, response_sending_duration_milliseconds DOUBLE PRECISION DEFAULT NULL, query_duration_milliseconds DOUBLE PRECISION NOT NULL, twig_render_duration_milliseconds DOUBLE PRECISION NOT NULL, curl_request_duration_milliseconds DOUBLE PRECISION NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, started_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, started_at_microseconds DOUBLE PRECISION NOT NULL, ended_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, ended_at_microseconds DOUBLE PRECISION NOT NULL, duration_milliseconds DOUBLE PRECISION NOT NULL, PRIMARY KEY(uuid))'); | ||
| $this->addSql('CREATE TABLE monitoring_query (id INT NOT NULL, context_id UUID DEFAULT NULL, query_string_id VARCHAR(40) DEFAULT NULL, parameters JSONB DEFAULT NULL, created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, started_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, started_at_microseconds DOUBLE PRECISION NOT NULL, ended_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, ended_at_microseconds DOUBLE PRECISION NOT NULL, duration_milliseconds DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))'); | ||
| $this->addSql('CREATE INDEX IDX_760D8AF36B00C1CF ON monitoring_query (context_id)'); | ||
| $this->addSql('CREATE INDEX IDX_760D8AF3BCAEFD40 ON monitoring_query (query_string_id)'); | ||
| $this->addSql('CREATE TABLE monitoring_query_string (query_hash VARCHAR(40) NOT NULL, query TEXT NOT NULL, PRIMARY KEY(query_hash))'); | ||
| $this->addSql('CREATE TABLE monitoring_twig_render (id INT NOT NULL, context_id UUID DEFAULT NULL, parent_id INT DEFAULT NULL, short_description TEXT NOT NULL, template_name VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, type VARCHAR(255) DEFAULT NULL, memory_usage INT DEFAULT NULL, peak_memory_usage INT DEFAULT NULL, profiler_duration DOUBLE PRECISION DEFAULT NULL, created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, started_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, started_at_microseconds DOUBLE PRECISION NOT NULL, ended_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, ended_at_microseconds DOUBLE PRECISION NOT NULL, duration_milliseconds DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))'); | ||
| $this->addSql('CREATE INDEX IDX_55BA2A536B00C1CF ON monitoring_twig_render (context_id)'); | ||
| $this->addSql('CREATE INDEX IDX_55BA2A53727ACA70 ON monitoring_twig_render (parent_id)'); | ||
| $this->addSql('ALTER TABLE monitoring_curl_request ADD CONSTRAINT FK_19A4B8546B00C1CF FOREIGN KEY (context_id) REFERENCES monitoring_execution_context (uuid) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
| $this->addSql('ALTER TABLE monitoring_query ADD CONSTRAINT FK_760D8AF36B00C1CF FOREIGN KEY (context_id) REFERENCES monitoring_execution_context (uuid) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
| $this->addSql('ALTER TABLE monitoring_query ADD CONSTRAINT FK_760D8AF3BCAEFD40 FOREIGN KEY (query_string_id) REFERENCES monitoring_query_string (query_hash) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
| $this->addSql('ALTER TABLE monitoring_twig_render ADD CONSTRAINT FK_55BA2A536B00C1CF FOREIGN KEY (context_id) REFERENCES monitoring_execution_context (uuid) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
| $this->addSql('ALTER TABLE monitoring_twig_render ADD CONSTRAINT FK_55BA2A53727ACA70 FOREIGN KEY (parent_id) REFERENCES monitoring_twig_render (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| $this->addSql('DROP SEQUENCE monitoring_curl_request_id_seq CASCADE'); | ||
| $this->addSql('DROP SEQUENCE monitoring_query_id_seq CASCADE'); | ||
| $this->addSql('DROP SEQUENCE monitoring_twig_render_id_seq CASCADE'); | ||
| $this->addSql('ALTER TABLE monitoring_curl_request DROP CONSTRAINT FK_19A4B8546B00C1CF'); | ||
| $this->addSql('ALTER TABLE monitoring_query DROP CONSTRAINT FK_760D8AF36B00C1CF'); | ||
| $this->addSql('ALTER TABLE monitoring_query DROP CONSTRAINT FK_760D8AF3BCAEFD40'); | ||
| $this->addSql('ALTER TABLE monitoring_twig_render DROP CONSTRAINT FK_55BA2A536B00C1CF'); | ||
| $this->addSql('ALTER TABLE monitoring_twig_render DROP CONSTRAINT FK_55BA2A53727ACA70'); | ||
| $this->addSql('DROP TABLE monitoring_curl_request'); | ||
| $this->addSql('DROP TABLE monitoring_execution_context'); | ||
| $this->addSql('DROP TABLE monitoring_query'); | ||
| $this->addSql('DROP TABLE monitoring_query_string'); | ||
| $this->addSql('DROP TABLE monitoring_twig_render'); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.