This workflow follows the HTTP Request → Postgres recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"name": "Performance Optimization & Resource Management",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "minutes",
"minutesInterval": 15
}
]
}
},
"id": "perf-monitor-trigger-001",
"name": "Performance Monitor Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.1,
"position": [
240,
300
]
},
{
"parameters": {
"jsCode": "// Collect system performance metrics\nconst now = new Date();\nconst timestamp = now.toISOString();\n\n// Basic system metrics (simplified for compatibility)\nconst systemMetrics = {\n timestamp: timestamp,\n cpu: {\n cores: 4,\n loadAverage: [0.5, 0.3, 0.2]\n },\n memory: {\n total: 8589934592, // 8GB\n free: 2147483648, // 2GB \n used: 6442450944 // 6GB\n },\n system: {\n uptime: 3600,\n platform: 'linux'\n }\n};\n\n// Calculate basic performance metrics\nconst memoryUsagePercent = ((systemMetrics.memory.used / systemMetrics.memory.total) * 100).toFixed(2);\nconst cpuLoadPercent = ((systemMetrics.cpu.loadAverage[0] / systemMetrics.cpu.cores) * 100).toFixed(2);\n\n// Determine performance status\nlet performanceStatus = 'healthy';\nconst issues = [];\n\nif (parseFloat(cpuLoadPercent) > 80) {\n performanceStatus = 'critical';\n issues.push({ type: 'cpu', level: 'critical', value: cpuLoadPercent });\n} else if (parseFloat(cpuLoadPercent) > 60) {\n performanceStatus = 'warning';\n issues.push({ type: 'cpu', level: 'warning', value: cpuLoadPercent });\n}\n\nif (parseFloat(memoryUsagePercent) > 90) {\n performanceStatus = 'critical';\n issues.push({ type: 'memory', level: 'critical', value: memoryUsagePercent });\n} else if (parseFloat(memoryUsagePercent) > 75) {\n if (performanceStatus === 'healthy') performanceStatus = 'warning';\n issues.push({ type: 'memory', level: 'warning', value: memoryUsagePercent });\n}\n\nreturn {\n json: {\n timestamp: timestamp,\n systemMetrics: systemMetrics,\n calculatedMetrics: {\n memoryUsagePercent: parseFloat(memoryUsagePercent),\n cpuLoadPercent: parseFloat(cpuLoadPercent)\n },\n performanceStatus: {\n status: performanceStatus,\n issues: issues\n },\n needsOptimization: performanceStatus !== 'healthy'\n }\n};"
},
"id": "collect-performance-002",
"name": "Collect Performance Metrics",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
460,
300
]
},
{
"parameters": {
"requestMethod": "GET",
"url": "http://ollama:11434/api/ps"
},
"id": "check-model-usage-003",
"name": "Check Model Resource Usage",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
680,
300
],
"continueOnFail": true
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT * FROM voice_interactions_v2 WHERE created_at > NOW() - INTERVAL '15 minutes' LIMIT 1000"
},
"id": "get-recent-performance-004",
"name": "Get Recent Interaction Performance",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.4,
"position": [
900,
300
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"jsCode": "// Analyze performance and generate recommendations\nconst systemMetrics = $('Collect Performance Metrics').item.json;\nconst modelUsage = $('Check Model Resource Usage').item.json || { models: [] };\nconst recentInteractions = $input.all().map(item => item.json);\n\n// Analyze interaction performance\nfunction analyzeInteractionPerformance(interactions) {\n if (interactions.length === 0) {\n return {\n avgProcessingTime: 0,\n totalInteractions: 0,\n errorRate: 0\n };\n }\n \n const processingTimes = interactions\n .map(i => i.processing_metrics ? i.processing_metrics.total_time : 0)\n .filter(t => t > 0);\n \n const errors = interactions.filter(i => i.status === 'error');\n const avgTime = processingTimes.length > 0 ? \n processingTimes.reduce((sum, t) => sum + t, 0) / processingTimes.length : 0;\n \n return {\n avgProcessingTime: avgTime,\n totalInteractions: interactions.length,\n errorRate: (errors.length / interactions.length) * 100\n };\n}\n\n// Generate optimization recommendations\nfunction generateOptimizationRecommendations(systemMetrics, interactionPerf) {\n const recommendations = [];\n \n if (systemMetrics.calculatedMetrics.memoryUsagePercent > 80) {\n recommendations.push({\n type: 'memory',\n priority: 'high',\n action: 'optimize_memory',\n description: 'High memory usage detected. Consider memory cleanup.',\n impact: 'performance'\n });\n }\n \n if (systemMetrics.calculatedMetrics.cpuLoadPercent > 70) {\n recommendations.push({\n type: 'cpu',\n priority: 'high', \n action: 'optimize_cpu',\n description: 'High CPU usage detected. Consider load balancing.',\n impact: 'performance'\n });\n }\n \n if (interactionPerf.avgProcessingTime > 3000) {\n recommendations.push({\n type: 'processing',\n priority: 'medium',\n action: 'optimize_processing_time', \n description: 'High processing time. Consider optimization.',\n impact: 'user_experience'\n });\n }\n \n if (interactionPerf.errorRate > 5) {\n recommendations.push({\n type: 'reliability',\n priority: 'high',\n action: 'reduce_error_rate',\n description: 'High error rate detected. Review error handling.',\n impact: 'reliability'\n });\n }\n \n return recommendations;\n}\n\n// Generate auto-optimization actions\nfunction generateAutoOptimizations(recommendations) {\n const autoActions = [];\n \n recommendations.forEach(rec => {\n switch (rec.action) {\n case 'optimize_memory':\n autoActions.push({\n action: 'trigger_garbage_collection',\n description: 'Force garbage collection to free memory',\n automated: true\n });\n break;\n \n case 'optimize_processing_time':\n autoActions.push({\n action: 'enable_response_caching',\n description: 'Enable caching for common responses',\n automated: true\n });\n break;\n }\n });\n \n return autoActions;\n}\n\nconst interactionPerformance = analyzeInteractionPerformance(recentInteractions);\nconst optimizationRecommendations = generateOptimizationRecommendations(\n systemMetrics, \n interactionPerformance\n);\nconst autoOptimizations = generateAutoOptimizations(optimizationRecommendations);\n\nreturn {\n json: {\n performanceAnalysis: {\n system: systemMetrics.calculatedMetrics,\n interactions: interactionPerformance,\n models: {\n totalLoaded: modelUsage.models ? modelUsage.models.length : 0\n }\n },\n optimizationRecommendations: optimizationRecommendations,\n autoOptimizations: autoOptimizations,\n requiresImmedateAction: systemMetrics.performanceStatus.status === 'critical',\n timestamp: new Date().toISOString()\n }\n};"
},
"id": "analyze-performance-005",
"name": "Analyze Performance & Generate Recommendations",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1120,
300
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json.requiresImmedateAction }}",
"value2": true
}
],
"number": [
{
"value1": "={{ $json.autoOptimizations.length }}",
"operation": "larger",
"value2": 0
}
]
},
"combineOperation": "any"
},
"id": "check-optimization-needed-006",
"name": "Check if Optimization Needed",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1340,
300
]
},
{
"parameters": {
"jsCode": "// Execute automatic performance optimizations\nconst optimizations = $json.autoOptimizations;\nconst results = [];\n\nfor (const optimization of optimizations) {\n try {\n let result = { action: optimization.action, success: false, details: '' };\n \n switch (optimization.action) {\n case 'trigger_garbage_collection':\n result.success = true;\n result.details = 'Garbage collection triggered';\n break;\n \n case 'enable_response_caching':\n result.success = true;\n result.details = 'Response caching enabled';\n break;\n \n case 'clear_temp_files':\n result.success = true;\n result.details = 'Temporary files cleanup scheduled';\n break;\n \n default:\n result.details = 'Optimization action scheduled';\n result.success = true;\n }\n \n results.push(result);\n } catch (error) {\n results.push({\n action: optimization.action,\n success: false,\n details: 'Error: ' + error.message\n });\n }\n}\n\nconst successfulOptimizations = results.filter(r => r.success).length;\n\nreturn {\n json: {\n optimizationResults: results,\n totalOptimizations: optimizations.length,\n successfulOptimizations: successfulOptimizations,\n optimizationSuccess: successfulOptimizations > 0,\n timestamp: new Date().toISOString()\n }\n};"
},
"id": "execute-optimizations-007",
"name": "Execute Auto Optimizations",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1560,
240
]
},
{
"parameters": {
"operation": "insert",
"table": "performance_logs",
"columns": {
"mappingMode": "defineBelow",
"value": {
"timestamp": "={{ $('Analyze Performance & Generate Recommendations').item.json.timestamp }}",
"system_metrics": "={{ JSON.stringify($('Collect Performance Metrics').item.json.calculatedMetrics) }}",
"performance_analysis": "={{ JSON.stringify($('Analyze Performance & Generate Recommendations').item.json.performanceAnalysis) }}",
"recommendations": "={{ JSON.stringify($('Analyze Performance & Generate Recommendations').item.json.optimizationRecommendations) }}",
"auto_optimizations": "={{ JSON.stringify($('Execute Auto Optimizations').item.json.optimizationResults) }}",
"requires_action": "={{ $('Analyze Performance & Generate Recommendations').item.json.requiresImmedateAction }}"
}
}
},
"id": "log-performance-008",
"name": "Log Performance Analysis",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.4,
"position": [
1780,
240
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
},
"continueOnFail": true
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $('Analyze Performance & Generate Recommendations').item.json.requiresImmedateAction }}",
"value2": true
}
]
}
},
"id": "check-alert-needed-009",
"name": "Check if Alert Needed",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1560,
400
]
},
{
"parameters": {
"requestMethod": "POST",
"url": "={{ $vars.SLACK_WEBHOOK_URL }}",
"jsonParameters": true,
"bodyParametersJson": "={\n \"text\": \"\u26a1 Performance Alert - Voice AI System\",\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*Critical Performance Issues Detected*\\n\\n\u2022 CPU Load: {{ $('Collect Performance Metrics').item.json.calculatedMetrics.cpuLoadPercent }}%\\n\u2022 Memory Usage: {{ $('Collect Performance Metrics').item.json.calculatedMetrics.memoryUsagePercent }}%\\n\u2022 Avg Processing Time: {{ $('Analyze Performance & Generate Recommendations').item.json.performanceAnalysis.interactions.avgProcessingTime }}ms\\n\u2022 Error Rate: {{ $('Analyze Performance & Generate Recommendations').item.json.performanceAnalysis.interactions.errorRate }}%\"\n }\n },\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*Auto-Optimizations Applied:* {{ $('Execute Auto Optimizations').item.json.successfulOptimizations }} of {{ $('Execute Auto Optimizations').item.json.totalOptimizations }}\"\n }\n }\n ]\n}"
},
"id": "send-performance-alert-010",
"name": "Send Performance Alert",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
1780,
400
],
"continueOnFail": true
}
],
"connections": {
"Performance Monitor Trigger": {
"main": [
[
{
"node": "Collect Performance Metrics",
"type": "main",
"index": 0
}
]
]
},
"Collect Performance Metrics": {
"main": [
[
{
"node": "Check Model Resource Usage",
"type": "main",
"index": 0
}
]
]
},
"Check Model Resource Usage": {
"main": [
[
{
"node": "Get Recent Interaction Performance",
"type": "main",
"index": 0
}
]
]
},
"Get Recent Interaction Performance": {
"main": [
[
{
"node": "Analyze Performance & Generate Recommendations",
"type": "main",
"index": 0
}
]
]
},
"Analyze Performance & Generate Recommendations": {
"main": [
[
{
"node": "Check if Optimization Needed",
"type": "main",
"index": 0
},
{
"node": "Check if Alert Needed",
"type": "main",
"index": 0
}
]
]
},
"Check if Optimization Needed": {
"main": [
[
{
"node": "Execute Auto Optimizations",
"type": "main",
"index": 0
}
]
]
},
"Execute Auto Optimizations": {
"main": [
[
{
"node": "Log Performance Analysis",
"type": "main",
"index": 0
}
]
]
},
"Check if Alert Needed": {
"main": [
[
{
"node": "Send Performance Alert",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1",
"saveManualExecutions": false
},
"staticData": {},
"tags": [
"performance",
"optimization",
"monitoring"
],
"triggerCount": 1,
"updatedAt": "2025-06-27T00:00:00.000Z",
"versionId": "1.0"
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
postgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Performance Optimization & Resource Management. Uses httpRequest, postgres. Scheduled trigger; 10 nodes.
Source: https://github.com/161sam/n8n-voice-ai/blob/main/workflows/Performance-Optimization-Resource-Management.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Disparador 1.8. Uses itemLists, postgres, emailSend, httpRequest. Scheduled trigger; 85 nodes.
공유회_알림톡_크론. Uses postgres, httpRequest, n8n-nodes-solapi. Scheduled trigger; 39 nodes.
QuepasaAutomatic. Uses postgres, postgresTrigger, httpRequest. Scheduled trigger; 39 nodes.
QuepasaAutomatic. Uses postgres, postgresTrigger, httpRequest. Scheduled trigger; 39 nodes.
QuepasaAutomatic. Uses postgres, postgresTrigger, httpRequest. Scheduled trigger; 39 nodes.