-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
970 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains 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,102 @@ | ||
import os | ||
|
||
import dash | ||
import pandas as pd | ||
import plotly.graph_objs as go | ||
import psycopg2 | ||
from dash import dcc, html | ||
from dash.dependencies import Input, Output | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
|
||
def get_db_connection(): | ||
connection = psycopg2.connect( | ||
dbname=os.getenv('DB_NAME', 'k6_dashboard'), | ||
user=os.getenv('DB_USER', 'k6_dashboard'), | ||
password=os.getenv('DB_PASSWORD', 'KrPPCHdYSXz6wMct5tUK'), | ||
host=os.getenv('DB_HOST', 'localhost') | ||
) | ||
return connection | ||
|
||
|
||
def fetch_data(query, params=None): | ||
connection = get_db_connection() | ||
cursor = connection.cursor() | ||
if params: | ||
cursor.execute(query, params) | ||
else: | ||
cursor.execute(query) | ||
result = cursor.fetchall() | ||
cursor.close() | ||
connection.close() | ||
return result | ||
|
||
|
||
# Fetch unique test run IDs for dropdown options | ||
test_run_ids_query = "SELECT DISTINCT tags->>'testid' AS testid FROM samples" | ||
test_run_ids = fetch_data(test_run_ids_query) | ||
test_run_id_options = [{'label': id[0], 'value': id[0]} for id in test_run_ids] | ||
|
||
app = dash.Dash('K6 Dashboard') | ||
|
||
app.layout = html.Div([ | ||
html.H1('K6 DASH Board'), | ||
dcc.Dropdown( | ||
id='test-run-dropdown', | ||
options=test_run_id_options, | ||
value=test_run_id_options[0]['value'] if test_run_id_options else None | ||
), | ||
dcc.Graph(id='response-time-graph') | ||
]) | ||
|
||
test_run_query = """ | ||
SELECT date_trunc('second', ts) AS time, | ||
avg(value) AS avg_rt, | ||
percentile_cont(0.95) WITHIN GROUP (ORDER BY value) AS perc_95_rt | ||
FROM samples | ||
WHERE metric = 'http_req_duration' | ||
AND (tags ->> 'status')::integer < 400 | ||
AND tags ->> 'testid' = 'BenZRz7' | ||
GROUP BY 1 | ||
ORDER BY 1; | ||
""" | ||
|
||
|
||
@app.callback( | ||
Output('response-time-graph', 'figure'), | ||
[Input('test-run-dropdown', 'value')] | ||
) | ||
def update_graph(selected_test_run_id): | ||
# Ensure your SQL query uses the selected_test_run_id placeholder correctly | ||
data = fetch_data(test_run_query, (selected_test_run_id,)) | ||
|
||
# Convert query results to a DataFrame | ||
agg_df = pd.DataFrame(data, columns=['time', 'avg_rt', 'perc_95_rt']) # Include perc_95_rt column | ||
|
||
# Create a Plotly graph object for both the average and 95th percentile response times | ||
figure = go.Figure() | ||
|
||
# Plot for average response time | ||
figure.add_trace( | ||
go.Scatter(x=agg_df['time'], y=agg_df['avg_rt'], mode='lines+markers', name='Avg Response Time (ms)') | ||
) | ||
|
||
# Plot for 95th percentile response time | ||
figure.add_trace( | ||
go.Scatter(x=agg_df['time'], y=agg_df['perc_95_rt'], mode='lines+markers', name='95th Percentile Response Time (ms)') | ||
) | ||
|
||
figure.update_layout( | ||
title='Response Times', | ||
xaxis_title='Timestamp', | ||
yaxis_title='Response Time (ms)', | ||
legend_title='Metric' | ||
) | ||
|
||
return figure | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run_server(debug=True) |
This file contains 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,10 @@ | ||
plugins { | ||
id "base" | ||
} | ||
|
||
|
||
group = "io.github.bbortt.k6.dashboard" | ||
|
||
|
||
dependencies { | ||
} |
Oops, something went wrong.