From 667820728a7903615657248ebaa008f31ad355d7 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Wed, 29 Jan 2025 14:57:21 -0400 Subject: [PATCH 1/3] Add "Top Slowest Script Tasks" gauge to MainDashboard --- resources/grafana/MainDashboard.json | 81 +++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/resources/grafana/MainDashboard.json b/resources/grafana/MainDashboard.json index 5c54ed4a8a..bd49be446a 100644 --- a/resources/grafana/MainDashboard.json +++ b/resources/grafana/MainDashboard.json @@ -946,6 +946,83 @@ ], "title": "Script Task Completion Time series", "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "de96jy15v6qrkc" + }, + "description": "Top Slowest Tasks", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": false, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "ms" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 40 + }, + "id": 11, + "interval": "15s", + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": [], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "sizing": "auto" + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "de96jy15v6qrkc" + }, + "disableTextWrap": false, + "editorMode": "code", + "exemplar": false, + "expr": "topk(10, avg(processmaker_activity_execution_time_seconds_sum{element_type=\"scriptTask\"}) by (process_id, activity_name))", + "format": "time_series", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "interval": "", + "legendFormat": "{{activity_name}} (process={{process_id}})", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Top Slowest Script Tasks", + "type": "gauge" } ], "preload": false, @@ -955,13 +1032,13 @@ "list": [] }, "time": { - "from": "now-6h", + "from": "now-30d", "to": "now" }, "timepicker": {}, "timezone": "browser", "title": "ProcessMaker Dashboard", "uid": "be96wxsnlmn7kc", - "version": 43, + "version": 45, "weekStart": "" } \ No newline at end of file From 987ca6d2fa21d0e6d73f13cf918401b130892213 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Thu, 30 Jan 2025 10:39:26 -0400 Subject: [PATCH 2/3] Add metrics tracking for completed script tasks --- ProcessMaker/Jobs/RunScriptTask.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ProcessMaker/Jobs/RunScriptTask.php b/ProcessMaker/Jobs/RunScriptTask.php index 4e83d63d9e..37f748c9b7 100644 --- a/ProcessMaker/Jobs/RunScriptTask.php +++ b/ProcessMaker/Jobs/RunScriptTask.php @@ -8,6 +8,7 @@ use ProcessMaker\Enums\ScriptExecutorType; use ProcessMaker\Exception\ConfigurationException; use ProcessMaker\Exception\ScriptException; +use ProcessMaker\Facades\Metrics; use ProcessMaker\Facades\WorkflowManager; use ProcessMaker\Managers\DataManager; use ProcessMaker\Models\Process as Definitions; @@ -111,6 +112,26 @@ public function action(ProcessRequestToken $token = null, ScriptTaskInterface $e $response = $script->runScript($data, $configuration, $token->getId(), $errorHandling->timeout(), 1, $metadata); $this->updateData($response); + + Metrics::counter( + 'script_task_completed_total', + 'Total number of script tasks completed', + [ + 'activity_id', + 'activity_name', + 'process_id', + 'request_id', + 'script_executor', + ] + )->inc( + [ + 'activity_id' => $element->getId(), + 'activity_name' => $element->getName(), + 'process_id' => $this->definitionsId, + 'request_id' => $this->instanceId, + 'script_executor' => $scriptExecutor ? $scriptExecutor->title : 'inline', + ] + ); } catch (ConfigurationException $exception) { $this->unlock(); $this->updateData(['output' => $exception->getMessageForData($token)]); From 9ce3aa7d9fcfc4e2b1a1aa6e6d88c1b4c89e9dde Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Thu, 30 Jan 2025 14:40:10 -0400 Subject: [PATCH 3/3] Add chart to show script tasks completion count by task and process --- resources/grafana/MainDashboard.json | 78 +++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/resources/grafana/MainDashboard.json b/resources/grafana/MainDashboard.json index bd49be446a..f2a50eba5a 100644 --- a/resources/grafana/MainDashboard.json +++ b/resources/grafana/MainDashboard.json @@ -1023,6 +1023,82 @@ ], "title": "Top Slowest Script Tasks", "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "de96jy15v6qrkc" + }, + "description": "Shows task completion distribution by activity and process to highlight execution patterns and identify key task volumes.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "fieldMinMax": false, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 40 + }, + "id": 12, + "interval": "5m", + "options": { + "displayLabels": [ + "percent" + ], + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "de96jy15v6qrkc" + }, + "disableTextWrap": false, + "editorMode": "code", + "exemplar": false, + "expr": "sum by(activity_name, process_id) (processmaker_script_task_completed_total)", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "{{activity_name}} (process={{process_id}})", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Completion Count by Task and Process", + "type": "piechart" } ], "preload": false, @@ -1039,6 +1115,6 @@ "timezone": "browser", "title": "ProcessMaker Dashboard", "uid": "be96wxsnlmn7kc", - "version": 45, + "version": 49, "weekStart": "" } \ No newline at end of file