Add failed execution count and average execution time to home page stats
This commit is contained in:
@@ -12,48 +12,58 @@ def index():
|
|||||||
# Fetch user statistics
|
# Fetch user statistics
|
||||||
stats = db.execute("""
|
stats = db.execute("""
|
||||||
WITH timer_stats AS (
|
WITH timer_stats AS (
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) as total_timer_functions,
|
COUNT(*) as total_timer_functions,
|
||||||
COUNT(*) FILTER (WHERE enabled = true) as active_timer_functions,
|
COUNT(*) FILTER (WHERE enabled = true) as active_timer_functions,
|
||||||
(SELECT COUNT(*) FROM timer_function_invocations tfi
|
(SELECT COUNT(*) FROM timer_function_invocations tfi
|
||||||
JOIN timer_functions tf ON tf.id = tfi.timer_function_id
|
JOIN timer_functions tf ON tf.id = tfi.timer_function_id
|
||||||
WHERE tf.user_id = %s) as timer_invocations,
|
WHERE tf.user_id = %s) as timer_invocations,
|
||||||
(SELECT COUNT(*) FROM timer_function_invocations tfi
|
(SELECT COUNT(*) FROM timer_function_invocations tfi
|
||||||
JOIN timer_functions tf ON tf.id = tfi.timer_function_id
|
JOIN timer_functions tf ON tf.id = tfi.timer_function_id
|
||||||
WHERE tf.user_id = %s AND tfi.status = 'SUCCESS') as timer_successful_invocations,
|
WHERE tf.user_id = %s AND tfi.status = 'SUCCESS') as timer_successful_invocations,
|
||||||
|
(SELECT AVG(tfi.execution_time) FROM timer_function_invocations tfi
|
||||||
|
JOIN timer_functions tf ON tf.id = tfi.timer_function_id
|
||||||
|
WHERE tf.user_id = %s) as avg_timer_execution_time,
|
||||||
MAX(last_run) as last_timer_invocation
|
MAX(last_run) as last_timer_invocation
|
||||||
FROM timer_functions
|
FROM timer_functions
|
||||||
WHERE user_id = %s
|
WHERE user_id = %s
|
||||||
),
|
),
|
||||||
http_stats AS (
|
http_stats AS (
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) as total_http_functions,
|
COUNT(*) as total_http_functions,
|
||||||
COUNT(*) FILTER (WHERE is_public = true) as public_http_functions,
|
COUNT(*) FILTER (WHERE is_public = true) as public_http_functions,
|
||||||
SUM(invoked_count) as http_invocations,
|
(SELECT COUNT(*) FROM http_function_invocations hfi
|
||||||
(SELECT COUNT(*) FROM http_function_invocations hfi
|
JOIN http_functions hf ON hf.id = hfi.http_function_id
|
||||||
JOIN http_functions hf ON hf.id = hfi.http_function_id
|
WHERE hf.user_id = %s) as http_invocations,
|
||||||
|
(SELECT COUNT(*) FROM http_function_invocations hfi
|
||||||
|
JOIN http_functions hf ON hf.id = hfi.http_function_id
|
||||||
WHERE hf.user_id = %s AND hfi.status = 'SUCCESS') as http_successful_invocations,
|
WHERE hf.user_id = %s AND hfi.status = 'SUCCESS') as http_successful_invocations,
|
||||||
(SELECT MAX(invocation_time)
|
(SELECT AVG(hfi.execution_time) FROM http_function_invocations hfi
|
||||||
FROM http_function_invocations hfi
|
JOIN http_functions hf ON hf.id = hfi.http_function_id
|
||||||
JOIN http_functions hf ON hf.id = hfi.http_function_id
|
WHERE hf.user_id = %s) as avg_http_execution_time,
|
||||||
|
(SELECT MAX(invocation_time)
|
||||||
|
FROM http_function_invocations hfi
|
||||||
|
JOIN http_functions hf ON hf.id = hfi.http_function_id
|
||||||
WHERE hf.user_id = %s) as last_http_invocation
|
WHERE hf.user_id = %s) as last_http_invocation
|
||||||
FROM http_functions
|
FROM http_functions
|
||||||
WHERE user_id = %s
|
WHERE user_id = %s
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
*,
|
*,
|
||||||
CASE
|
(timer_invocations - timer_successful_invocations) as timer_failed_invocations,
|
||||||
WHEN timer_invocations > 0 THEN
|
(http_invocations - http_successful_invocations) as http_failed_invocations,
|
||||||
|
CASE
|
||||||
|
WHEN timer_invocations > 0 THEN
|
||||||
(timer_successful_invocations * 100.0 / timer_invocations)::numeric(5,1)
|
(timer_successful_invocations * 100.0 / timer_invocations)::numeric(5,1)
|
||||||
ELSE 0.0
|
ELSE 0.0
|
||||||
END as timer_success_rate,
|
END as timer_success_rate,
|
||||||
CASE
|
CASE
|
||||||
WHEN http_invocations > 0 THEN
|
WHEN http_invocations > 0 THEN
|
||||||
(http_successful_invocations * 100.0 / http_invocations)::numeric(5,1)
|
(http_successful_invocations * 100.0 / http_invocations)::numeric(5,1)
|
||||||
ELSE 0.0
|
ELSE 0.0
|
||||||
END as http_success_rate
|
END as http_success_rate
|
||||||
FROM timer_stats, http_stats
|
FROM timer_stats, http_stats
|
||||||
""", [current_user.id, current_user.id, current_user.id, current_user.id, current_user.id, current_user.id], one=True)
|
""", [current_user.id, current_user.id, current_user.id, current_user.id, current_user.id, current_user.id, current_user.id, current_user.id, current_user.id], one=True)
|
||||||
|
|
||||||
# Get 24-hour distribution
|
# Get 24-hour distribution
|
||||||
hour_distribution = db.execute("""
|
hour_distribution = db.execute("""
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<!-- Timer Functions Stats -->
|
<!-- Timer Functions Stats -->
|
||||||
<div class="mb-4 sm:mb-8">
|
<div class="mb-4 sm:mb-8">
|
||||||
<h2 class="text-lg font-semibold text-gray-700 mb-2 sm:mb-4">Timer Functions</h2>
|
<h2 class="text-lg font-semibold text-gray-700 mb-2 sm:mb-4">Timer Functions</h2>
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-6">
|
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-6">
|
||||||
<!-- Total Timer Functions Card -->
|
<!-- Total Timer Functions Card -->
|
||||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
@@ -81,13 +81,49 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Failed Invocations -->
|
||||||
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="p-3 rounded-full bg-red-100">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-red-600" fill="none"
|
||||||
|
viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-4">
|
||||||
|
<h2 class="text-sm font-medium text-gray-500">Failed Invocations</h2>
|
||||||
|
<p class="text-2xl font-semibold text-gray-900">{{ stats.timer_failed_invocations }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Average Execution Time -->
|
||||||
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="p-3 rounded-full bg-yellow-100">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-yellow-600" fill="none"
|
||||||
|
viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-4">
|
||||||
|
<h2 class="text-sm font-medium text-gray-500">Avg. Execution Time</h2>
|
||||||
|
<p class="text-2xl font-semibold text-gray-900">
|
||||||
|
{{ "%.2f"|format(stats.avg_timer_execution_time|default(0)) }}s
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- HTTP Functions Stats -->
|
<!-- HTTP Functions Stats -->
|
||||||
<div class="mb-4 sm:mb-8">
|
<div class="mb-4 sm:mb-8">
|
||||||
<h2 class="text-lg font-semibold text-gray-700 mb-2 sm:mb-4">HTTP Functions</h2>
|
<h2 class="text-lg font-semibold text-gray-700 mb-2 sm:mb-4">HTTP Functions</h2>
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-6">
|
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-6">
|
||||||
<!-- Total HTTP Functions Card -->
|
<!-- Total HTTP Functions Card -->
|
||||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
@@ -159,6 +195,42 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Failed Invocations -->
|
||||||
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="p-3 rounded-full bg-red-100">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-red-600" fill="none"
|
||||||
|
viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-4">
|
||||||
|
<h2 class="text-sm font-medium text-gray-500">Failed Invocations</h2>
|
||||||
|
<p class="text-2xl font-semibold text-gray-900">{{ stats.http_failed_invocations }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Average Execution Time -->
|
||||||
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="p-3 rounded-full bg-yellow-100">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-yellow-600" fill="none"
|
||||||
|
viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-4">
|
||||||
|
<h2 class="text-sm font-medium text-gray-500">Avg. Execution Time</h2>
|
||||||
|
<p class="text-2xl font-semibold text-gray-900">
|
||||||
|
{{ "%.2f"|format(stats.avg_http_execution_time|default(0)) }}s
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user