-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding hooks to add custom metrics in locust like token calculations * fix bug * fix readme * fix readme * make csv_upload_frequency a variable * fix readm * fix readm * fix readm * fix readme * terraform fmt * add csv_upload_frequency as a tf variable
- Loading branch information
1 parent
c0ac689
commit 1ae0f31
Showing
9 changed files
with
234 additions
and
11 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
42 changes: 42 additions & 0 deletions
42
...chmark/tools/locust-load-inference/locust-docker/locust-tasks/custom_metric_aggregator.py
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,42 @@ | ||
import datetime | ||
import logging | ||
|
||
class TokenMetricCollector: | ||
def __init__(self): | ||
self.tokens_sent = [] | ||
self.tokens_received = [] | ||
self.test_time = [] | ||
self.success_count = 0 | ||
self.failure_count = 0 | ||
|
||
|
||
def add_metric(self, sent, received, test_time, request_successful_bool): | ||
if request_successful_bool==1: | ||
self.tokens_sent.append(sent) | ||
self.tokens_received.append(received) | ||
self.test_time.append(test_time) | ||
self.success_count += 1 | ||
else: | ||
self.failure_count += 1 | ||
|
||
|
||
def calculate_average_tokens(self): | ||
avg_sent = sum(self.tokens_sent) / len(self.tokens_sent) if self.tokens_sent else 0 | ||
avg_received = sum(self.tokens_received) / len(self.tokens_received) if self.tokens_received else 0 | ||
avg_test_time = sum(self.test_time) / len(self.test_time) if self.tokens_sent else 0 | ||
|
||
return avg_sent, avg_received, avg_test_time | ||
|
||
def write_to_csv(self, file_path='custom_metrics.csv'): | ||
import csv | ||
avg_sent, avg_received, avg_test_time = self.calculate_average_tokens() | ||
with open(file_path, mode='w', newline='') as file: | ||
writer = csv.writer(file) | ||
writer.writerow(['Metric', 'Average Value']) | ||
writer.writerow(['# of Successful Req', self.success_count]) | ||
writer.writerow(['# of Failed Req', self.failure_count]) | ||
writer.writerow(['Avg Tokens Sent Per Req', avg_sent]) | ||
writer.writerow(['Avg Tokens Received Per Req', avg_received]) | ||
writer.writerow(['Avg Test Time', avg_test_time]) | ||
writer.writerow(['Timestamp', datetime.datetime.now()]) | ||
|
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 |
---|---|---|
|
@@ -31,4 +31,4 @@ Werkzeug==2.3.8 | |
zipp==3.8.0 | ||
zope.event==4.5.0 | ||
zope.interface==5.4.0 | ||
TensorFlow >= 2.0 | ||
TensorFlow >= 2.0 |
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
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
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
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
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
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