Last active
April 19, 2020 16:33
-
-
Save var23rav/fb8eace1390d39993878de663e1bdf51 to your computer and use it in GitHub Desktop.
Jmeter Test Result (jtl or csv extension) to Prometheus Metrics converter
This file contains hidden or 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
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,Latency,IdleTime,Connect | |
2018/07/13 12:48:03,262,359 /login,200,OK,Thread Group 1-1,text,true,,1356,411,1,1,261,0,244 | |
2018/07/13 12:48:03,19,360 /bundle.css,200,OK,Thread Group 1-1,text,true,,53006,435,1,1,12,0,0 | |
2018/07/13 12:48:03,2,361 /bundle.js,200,OK,Thread Group 1-1,text,true,,1998,419,1,1,2,0,0 | |
2018/07/13 12:48:03,3,368 /assets/config.json,200,OK,Thread Group 1-1,text,true,,451,462,1,1,3,0,0 | |
2018/07/13 12:48:03,286,359 /login,200,OK,"Number of samples in transaction : 4, number of failing samples : 0",Thread Group 1-1,TRUE,,56811,1727,1,1,278,0,244 |
This file contains hidden or 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
import random, time | |
import pandas as p | |
from prometheus_client import start_http_server, Summary | |
label_name_list = ('sampler_name', 'code', 'success') | |
jmeter_label_summary_dict = { | |
'elapsed': Summary('jmeter_samples_duration_seconds', 'jmeter_samples_duration_seconds Summary for sample duration in seconds', label_name_list), | |
'Latency': Summary('jmeter_samples_ttfb_seconds', 'jmeter_samples_ttfb_seconds Summary for sample latency(TTFB) in seconds', label_name_list), | |
'IdleTime': Summary('jmeter_samples_idle_time_seconds_count', 'jmeter_samples_idle_time_seconds Summary for sample idle time in seconds', label_name_list), | |
'Connect': Summary('jmeter_samples_connect_time_seconds', 'jmeter_samples_connect_time_seconds Summary for sample connect time in seconds', label_name_list) | |
} | |
jmeter_metrics_df = p.read_csv("JmeterResult.jtl") #JmeterResult.csv | |
jmeter_metrics_df = jmeter_metrics_df[:-1] # Skipping last line, since Jtl last line is agregation(sum) of all other line(eg: responseMessage = "Number of samples in transaction : 17, number of failing samples : 0") | |
for row in jmeter_metrics_df.to_dict(orient='records'): | |
label_value_dict = { | |
'sampler_name': str(row['label']).split("/", 1)[-1], | |
'code': row['responseCode'], | |
'success': str(row['success']).lower() | |
} | |
jmeter_label_summary_dict['elapsed'].labels(**label_value_dict).observe(row['elapsed'] / 1000) | |
jmeter_label_summary_dict['Latency'].labels(**label_value_dict).observe(row['Latency'] / 1000) | |
jmeter_label_summary_dict['IdleTime'].labels(**label_value_dict).observe(row['IdleTime'] / 1000) | |
jmeter_label_summary_dict['Connect'].labels(**label_value_dict).observe(row['Connect'] / 1000) | |
def process_request(t): | |
time.sleep(t) | |
if __name__ == '__main__': | |
start_http_server(2323) | |
print('http://localhost:2323') | |
while True: | |
process_request(random.random()) | |
This file contains hidden or 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
numpy==1.15.4 | |
pandas==0.23.4 | |
prometheus-client==0.5.0 | |
python-dateutil==2.7.5 | |
pytz==2018.7 | |
six==1.12.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment