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)]); diff --git a/resources/grafana/MainDashboard.json b/resources/grafana/MainDashboard.json index 5c54ed4a8a..f2a50eba5a 100644 --- a/resources/grafana/MainDashboard.json +++ b/resources/grafana/MainDashboard.json @@ -946,6 +946,159 @@ ], "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" + }, + { + "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, @@ -955,13 +1108,13 @@ "list": [] }, "time": { - "from": "now-6h", + "from": "now-30d", "to": "now" }, "timepicker": {}, "timezone": "browser", "title": "ProcessMaker Dashboard", "uid": "be96wxsnlmn7kc", - "version": 43, + "version": 49, "weekStart": "" } \ No newline at end of file