Last active
December 14, 2019 15:24
-
-
Save anushiya-thevapalan/5f23df86b0d4175656f3afb6bd206714 to your computer and use it in GitHub Desktop.
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
import time, re, sys | |
import requests, schedule | |
import urllib | |
import datetime | |
from container_cpu_usage_time import * | |
from container_cpu_utilization_stats import * | |
from container_memory_bytes_total_stats import * | |
from container_memory_bytes_used_stats import * | |
from container_memory_page_fault_count_stats import * | |
from container_uptime_stats import * | |
output_folder = sys.argv[1] | |
start_time = sys.argv[2] | |
end_time = sys.argv[3] | |
size = sys.argv[4] | |
concurrency = sys.argv[5] | |
def query_metrics(output_folder, start_time, end_time, size, concurrency): | |
try: | |
start_time = urllib.parse.quote(start_time, safe='') | |
end_time = urllib.parse.quote(end_time, safe='') | |
filenames = [] | |
container_metrics_list = ["container/cpu/usage_time", "container/cpu/utilization", "container/memory/bytes_total", | |
"container/memory/bytes_used", "container/memory/page_fault_count", "container/uptime"] | |
headers = { | |
'Authorization': 'Bearer [OAuth 2.0 access token]'} | |
for metrics in container_metrics_list: | |
# file = open(str(time.time()), "a") | |
filename = output_folder+"/"+metrics.replace("/", "_")+"_"+size+"_"+concurrency+".json" | |
filenames.append(filename) | |
file = open(filename, "w+") | |
#Add the API key at the end of the URL | |
URL = "https://monitoring.googleapis.com/v3/projects/auto-scaling-springboot/timeSeries?filter=metric.type%20%3D%20%22container.googleapis.com%2F"+urllib.parse.quote(metrics, safe='')+"%22%20&interval.endTime=" + end_time + "Z&interval.startTime=" + start_time + "Z&key=[API key]" | |
response = requests.get(url=URL, headers=headers) | |
data = response.text | |
file.write(data) | |
file.close() | |
pod_name = "springboot-app" | |
get_container_cpu_usage(filename=filenames[0], size=size, querying_factor=pod_name) | |
get_container_cpu_utilization(filename=filenames[1], size=size, querying_factor=pod_name) | |
get_container_memory_bytes_total(filename=filenames[2], size=size, querying_factor=pod_name) | |
get_container_memory_bytes_used(filename=filenames[3], size=size, querying_factor=pod_name) | |
get_container_memory_page_fault_count(filename=filenames[4], size=size, querying_factor=pod_name) | |
get_container_uptime(filename=filenames[5], size=size, querying_factor=pod_name) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment