-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
599 lines (504 loc) · 27 KB
/
report.py
File metadata and controls
599 lines (504 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
#io handling
import argparse
import json
import socket
import requests
import os
#Data Handling
import psycopg2
from psycopg2 import sql
from psycopg2 import OperationalError
import sqlite3
from datetime import datetime, timedelta
import pandas as pd
import re
import tempfile
import statistics
import statsmodels.formula.api as smf #type:ignore
from contextlib import contextmanager
#Plotting
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('dark')
#Typing
from typing import Union, Optional
import logging
#Stuff that needs to talk to canari
from canari import submit_benchmarking_pair, get_cluster_data
from canari import get_total_nodes
from canari import get_offline_node_objs
from canari import log_status
from canari import get_last_healthcheck
from canari import get_nodetype_from_host
from canari import get_all_nodes
### Global Variables Begin ###
health_check_apps = ['hpl', 'stream'] #Applications comprising a health check
hostname=socket.gethostname()
old_style=hostname.split('-')
cluster = old_style[0] if len(old_style) > 1 else hostname.split('.')[1]
#Directory that this script(that you are reading right now) is located in. Use to reference relative files
repo_dir:str = os.path.dirname(__file__)
### Global Variables End ###
################################# COMMON FUNCTIONS ###########################################333
def send_slack_message(message, channel_id="C068GC6QWCV", token_path="/home/rderue/.slack/token", blocks=None, debug=True):
"""
Utilizes the Slack API to send a message to the specified channel through the app whose token
is contained at token_path. The app must be installed on the workspace you intend to use it on.
You can use the blocks variable to craft richer messages by doing things like
using JSON strings to encode Markdown, etc.
message: The string you want to send in Slack.
channel_id: The ID of the channel you want to send the message to. A hack
for retrieving this value is to open the Slack channel in the
web-app version of Slack. The channel_id is the string in the
last /<>/ of the URL.
token_path: The path to the token for your Slack app. The token must have the
scope chat:write for this.
blocks: A Slack construct that allows rich formatting of messages using
Markdown.
"""
if debug:
channel_id="C068CJDV9V2"
token=None
with open(token_path, 'r') as f1:
token=f1.read()[:-1]
return requests.post('https://slack.com/api/chat.postMessage', {
'token': token,
'channel': channel_id,
'text': message,
'username': "Cluster Health Notifications",
'blocks': json.dumps(blocks) if blocks else None
}).json()
def upload_slack_file(f, ts, channel_id="C068GC6QWCV", token_path="/home/rderue/.slack/token", blocks=None, debug=False,
upload_file=None):
"""
Description: A helper function for uploading a file to slack. Be warned Slack's
API seems to be able to return 200 OK even when this fails.
f: The path to the file you want to upload.
ts: The id of the thread to attach this file to. If this is empty it
will send as its own thread. This value should reflect the id of
the thread for the oldest message in the thread.
channel_id: The ID of the channel you want to send the message to. A hack
for retrieving this value is to open the Slack channel in the
web-app version of Slack. The channel_id is the string in the
last /<>/ of the URL.
token_path: The path to the token for your Slack app. The token must have the
scope file:write for this
blocks: A Slack construct that allows rich formatting of messages using
Markdown.
"""
if debug:
channel_id="C068CJDV9V2"
token=None
with open(token_path, 'r') as f1:
token=f1.read()[:-1]
headers = {
"Authorization": f"Bearer {token}"
}
if upload_file is None:
upload_file = {
'file' : (f"{cluster}_health.log", open(f, 'rb'), 'text/plain')
}
payload={
'channels':channel_id,
'thread_ts':ts,
}
response = requests.post('https://slack.com/api/files.upload', headers=headers, params=payload, files=upload_file)
return response
################################# CLUSTER HEALTH FUNCTIONS ##########################################
def get_summary(debug=False, token_path="/home/rderue/.slack/token",
partition = "testpbs", slack_channel_id = "C068GC6QWCV"): #Only looks at current timepoint - Does not read/write any data - Put in report.py
"""
A function which reports the total percent of offlined nodes on the cluster and
attaches a chronologically sorted log containing a list of nodes that have been
down and why they were marked down. This function's intended use case is to be
ran every weekday for an end of day report.
"""
total_nodes:int=get_total_nodes(partition = partition)
offline_nodes:list=get_offline_node_objs()
percent_offline=100*(len(offline_nodes) / float(total_nodes))
response = send_slack_message("{:.2f}% of {} nodes are offline ({} nodes).".format(percent_offline, cluster.capitalize(), len(offline_nodes)),
debug=debug, token_path = token_path, channel_id = slack_channel_id)
message=""
for node in get_offline_node_objs(): #Returns list of "Node" objects
message += "{} has been offline for {} days for reported reason: {}.".format(node.name, (datetime.now() - node.get_datetime()).days, node.reason) + "\n" # type: ignore
with tempfile.NamedTemporaryFile(mode="w+") as tmp:
tmp.write(message)
tmp.read()
print(upload_slack_file(tmp.name, response['ts'], debug=debug,
token_path = token_path, channel_id = slack_channel_id))
def healthcheck(critical_percent=.025, debug=False, token_path="/home/rderue/.slack/token",
health_dir = "/depot/itap/verburgt/repos/cluster_health/cluster_health_data/",
partition = "testpbs",
slack_channel_id = "C068GC6QWCV"): #Retrieves previous data, logs current data, AND reports -- Split up?
"""
A check ran hourly which retrieves the currently offlined nodes, logs that
information, and reports in Slack if the difference between the currently
offlined nodes and those logged in the previous healthcheck are more than
critical_percent different than one another.
"""
total_nodes:int = get_total_nodes(partition = partition)
offline_nodes:list = get_offline_node_objs()
last_offline_nodes=get_last_healthcheck(filepath = health_dir)
# If last healthcheck ran more than 90 minutes ago, then the cronjob
# probably died. Skip reporting the stale data.
if last_offline_nodes == None:
print("Data is stale. Logging current status and exiting...")
log_status(filepath = health_dir)
return
curr_offline=set([str(n) for n in offline_nodes])
last_offline=set([str(n) for n in last_offline_nodes])
onlined_nodes = list(last_offline.difference(curr_offline))
offlined_nodes = list(curr_offline.difference(last_offline))
reason_offlined_nodes = [x.reason for x in offline_nodes if x.name in offlined_nodes]
onlined_nodes.sort()
offlined_nodes.sort()
if len(onlined_nodes) != 0:
print(f"Nodes: {onlined_nodes} brought back online since last check.")
else:
print("No new nodes brought online since the last check.")
if len(offlined_nodes) != 0:
print(f"Nodes: {offlined_nodes} went down since last check.")
else:
print("No new nodes went down since the last check.")
log_status(filepath = health_dir)
# If the total number of nodes onlined and offlined were more than
# the "critical_percent" of the cluster, we should report this.
if float(len(offlined_nodes) + len(onlined_nodes)) / float(total_nodes) > critical_percent:
if len(offlined_nodes) == 0:
warning_message="There has been a change in node availabilty on {} affecting more than {:.2f}% of the cluster in the past hour. {} nodes brought back online ({}).".format(cluster, 100*critical_percent, len(onlined_nodes), onlined_nodes)
elif len(onlined_nodes) == 0:
warning_message="There has been a change in node availabilty on {} affecting more than {:.2f}% of the cluster in the past hour. {} nodes have gone offline ({}). Most common reason for newly offlined nodes is '{}'.".format(cluster, 100*critical_percent, len(offlined_nodes), offlined_nodes, statistics.mode(reason_offlined_nodes))
else:
warning_message="There has been a change in node availabilty on {} affecting more than {:.2f}% of the cluster in the past hour. {} nodes brought back online ({}). {} nodes have gone offline ({}). Most common reason for newly offlined nodes is '{}'.".format(cluster, 100*critical_percent, len(onlined_nodes), onlined_nodes, len(offlined_nodes), offlined_nodes, statistics.mode(reason_offlined_nodes))
send_slack_message(warning_message, debug=debug, token_path = token_path, channel_id = slack_channel_id)
########################################### CLUSTER BENCHMARK FUNCTIONS #################################################
@contextmanager
def get_db_connection(**kwargs):
conn = None
try:
conn = psycopg2.connect(
dbname=kwargs.get('dbname'),
user=kwargs.get('user'),
password=kwargs.get('password'),
host=kwargs.get('host'),
port=kwargs.get('port')
)
logging.debug("Connected to Postgres database!")
yield conn
except OperationalError as e:
logging.warning("Unable to connect to Postgres database - Falling back to SQLite3")
conn = sqlite3.connect(kwargs.get('sqlitefile')) #type: ignore
yield conn
except Exception as e:
raise ConnectionError("Unable to connect to database")
finally:
if conn is not None:
conn.close()
def query_database(db_params:dict, query:str) -> pd.DataFrame:
with get_db_connection(**db_params) as conn:
logging.debug(f"query is '{query}'") #query.as_string(conn)
df = pd.read_sql_query(query, conn)
df["nodetype"] = df.node.map(get_nodetype_from_host)
df["outlier"] = df.performance < (df.performance.mean() - df.performance.std() * 3)
logging.debug(f"fetched {df.shape[0]} rows!")
return df
def get_query(cluster:str, application:str,
timespan:Optional[str] = "week",
date:Optional[Union[str, datetime]] = None,
table:str = "benchmark_results_simple") -> str:
#If a specific date was provided, use that as the base start time
if date:
if isinstance(date, str):
try:
date = datetime.strptime(date, '%Y-%m-%d') #Ensure that valid string date was given
except ValueError as e:
logging.error("Datetime strings must be provided in a '%Y-%m-%d' format!")
raise e
base_time = date
else: #Otherwise just use current time
base_time = datetime.now()
assert timespan in ['week', 'month', 'year', 'day']
time_deltas = {'week': 7,'month': 30,'year': 365, 'day':1}
# Calculate end and begin datetimes
end_datetime = base_time + timedelta(days=1)
begin_datetime = end_datetime - timedelta(days=time_deltas[timespan])
end_date_str = end_datetime.strftime('%Y-%m-%d')
begin_date_str = begin_datetime.strftime('%Y-%m-%d')
query = f"""
SELECT * FROM {table}
WHERE cluster = '{cluster}'
AND application = '{application}'
AND datetime BETWEEN '{begin_date_str}' AND '{end_date_str}';
"""
return query
def generate_stream_graph(stream_df: pd.DataFrame, bynodetype:Optional[bool] = True) -> str:
stream_df['datetime'] = pd.to_datetime(stream_df['datetime'])
stream_df['datetime'] = stream_df['datetime'].dt.floor('12H') #Floor to the nearest half day
#Set up Figure
fig, ax = plt.subplots(1, 1, figsize=(15,8))
fig.set_tight_layout(True) #type:ignore
ax.set_title('Average STREAM Performance Over Time')
ax.set_ylabel('STREAM Performance (MB/s)')
ax.set_xlabel('Time of Run')
#Plot overall data
sns.lineplot(data=stream_df, x='datetime', y='performance', ax=ax, label = "overall")#, marker="o")
#sns.scatterplot(data= stream_df, x='datetime', y='performance', ax=ax, color="black", marker=".")
#Plot by node type
if bynodetype:
node_groups = stream_df.groupby("nodetype")
for nodetype, node_df in node_groups:
sns.lineplot(data=node_df, x='datetime', y='performance', ax=ax, label = nodetype)
#sns.lineplot overrides this, keep after plotting
ax.set_xticklabels(ax.get_xticklabels(), rotation=45)
#Annotate outliers on graph
outlier_df = stream_df.loc[stream_df.outlier]
ax.scatter(x=outlier_df['datetime'], y=outlier_df['performance'], color='r')
for _, row in outlier_df.iterrows():
ax.annotate(row['node'], (row['datetime'], row['performance']))
filename='/tmp/stream.png'
#filename='stream.png'
fig.savefig(filename)
return filename
def generate_hpl_graph(hpl_df: pd.DataFrame, bynodetype:Optional[bool] = True) -> str:
hpl_df['datetime'] = pd.to_datetime(hpl_df['datetime'])
hpl_df['datetime'] = hpl_df['datetime'].dt.floor('12H') #Floor to the nearest half day
# hpl_df = hpl_df.loc[hpl_df.datetime < '2024-07-25']
#Set up Figure
fig, ax = plt.subplots(1, 1, figsize=(15,8))
fig.set_tight_layout(True) #type:ignore
ax.set_title('Average HPL Performance Over Time')
ax.set_ylabel('HPL Performance (GFLOPs)')
ax.set_xlabel('Time of Run')
#Plot overall data
sns.lineplot(data=hpl_df, x='datetime', y='performance', ax=ax, label = "overall")#, marker="o")
# sns.scatterplot(data=hpl_df, x='datetime', y='performance', ax=ax, color="black", marker=".")
#Plot by node type
if bynodetype:
node_groups = hpl_df.groupby("nodetype")
for nodetype, node_df in node_groups:
sns.lineplot(data=node_df, x='datetime', y='performance', ax=ax, label = nodetype)
#sns.lineplot overrides this, keep after plotting
ax.set_xticklabels(ax.get_xticklabels(), rotation=45)
#Annotate outliers on graph
outlier_df = hpl_df.loc[hpl_df.outlier]
ax.scatter(x=outlier_df['datetime'], y=outlier_df['performance'], color='r')
for _, row in outlier_df.iterrows():
ax.annotate(row['node'], (row['datetime'], row['performance']))
filename='/tmp/hpl.png'
#filename='hpl.png'
fig.savefig(filename)
# exit()
return filename
def report_performance(timespan:str, database_login_file:str, debug:bool=True,
token_path:str = f"{repo_dir}/tokens/.slack/token", cluster:str = cluster,
resubmit:bool = True,
slack_channel_id = "C068GC6QWCV") -> None:
with open(database_login_file, 'r') as file:
db_params = json.load(file)["database"]
response = send_slack_message(f"{cluster.capitalize()} performance report for the last {timespan}.",
debug=debug, token_path = token_path, channel_id = slack_channel_id)
assert response["ok"]
ts = response["ts"]
logging.debug(f"ts is {ts}")
graph_function_map = {
"stream": generate_stream_graph,
"hpl": generate_hpl_graph,
}
for application in health_check_apps:
#Get the data
query = get_query(cluster = cluster, application=application, timespan = timespan)
application_df = query_database(db_params, query)
#Create the image
application_pngpath = graph_function_map[application](application_df) #Create different image based on application
graph_file = {'file' : (f"{application}.png", open(application_pngpath, 'rb'), 'image/png')}
#Upload to slack
upload_response = upload_slack_file(application_pngpath,
channel_id = slack_channel_id,
upload_file = graph_file,
ts = ts,
token_path = token_path,
debug = debug)
#Resubmit poor performing nodes
if resubmit:
outlier_nodes = set(application_df.loc[application_df.outlier, "node"])
for host in outlier_nodes:
resubmit_node(application = application, host = host, database_login_file = database_login_file)
def resubmit_node(application, database_login_file, host):
print(application, host)
cluster_data = get_cluster_data(cluster=cluster)
account = cluster_data["account"]
partition = cluster_data["partition"]
logging.info(f"Resubmitting {application} on node {host}")
submit_benchmarking_pair(application, database_login_file = database_login_file, host = host, account = account, partition=partition)
############################## maintenence report functions #####################################
def run_model(data:pd.DataFrame, alpha:float = 0.05) -> pd.DataFrame:
'''Runs an ANOVA based on node-type on data. Returns prediction intervals for each node type
data:pd.DataFrame - data with performance and nodetype columns
alpha:float Alpha vlaue for calculating prediction and confidence intervals
returns: pd.DataFrame - index: node_type
columns: mean mean_se mean_ci_lower mean_ci_upper obs_ci_lower obs_ci_upper
'''
model = smf.ols('performance ~ C(nodetype)', data=data).fit()
unique_node_types = data['nodetype'].unique()
predictions = model.get_prediction({'nodetype': unique_node_types})
summary_frame = predictions.summary_frame(alpha=alpha)
summary_frame["nodetype"] = unique_node_types
summary_frame = summary_frame.set_index("nodetype")
# print(model.summary())
# anova_table = anova_lm(model)
return summary_frame
def make_maintenence_graph(data:pd.DataFrame, application:str = "STREAM", alpha:float=0.05) -> str:
'''Takes a dataframe of performance data and returns the filepath to a performance graph
data:pd.DataFrame - Pandas datafrmae with performance, node, and nodetype columns
application:str - "stream" or "hpl"
alpha=0.9 - alpha value for calculating prediction intervals
returns str: filepath of generated figure
'''
#Get prediction intervals
model_results = run_model(data, alpha=alpha)
data["ci_lower"] = data.nodetype.apply(lambda x: model_results.loc[x, "mean_ci_lower"])
data["ci_upper"] = data.nodetype.apply(lambda x: model_results.loc[x, "mean_ci_upper"])
data["pi_lower"] = data.nodetype.apply(lambda x: model_results.loc[x, "obs_ci_lower"])
data["pi_upper"] = data.nodetype.apply(lambda x: model_results.loc[x, "obs_ci_upper"])
data["pi_outlier"] = data.apply(lambda x: (x.performance < x.pi_lower) or (x.performance > x.pi_upper), axis=1)
fig, ax = plt.subplots(1, 1, figsize=(14, 7))
fig.set_tight_layout(True) #type:ignore
#Plot the data and prediction intervals
sns.lineplot(data = data, x = "node", y = "performance", hue="nodetype", ax = ax)
ax.fill_between(data['node'], data['pi_lower'], data['pi_upper'], color='gray', alpha=0.2)#, label = "Prediction Interval")
#Plot outliers
for idx, row in data.loc[data["pi_outlier"]].iterrows():
ax.scatter(row["node"], row["performance"], color = "red")
ax.annotate(row["node"],(row["node"], row["performance"]))
#Clean up
ax.set_xticks(range(0, len(data.node), 5))
ax.set_xticklabels(data.node[::5], rotation=90)
ax.set_xlabel("Node", size=14)
ax.set_ylabel(f"{application} Performance", size=14)
ax.legend()
filename=f'/tmp/{application}_maintenence.png'
#filename=f'{application}_maintenence.png'
fig.savefig(filename)
return filename
def report_maintenance(database_login_file,
slack_channel_id,
token_path,
date:Union[datetime, str] = datetime.now(),
partition:str="testpbs",
timespan = "day",
debug = False) -> None:
#Send Base slack message
if isinstance(date, str):
try:
date = datetime.strptime(date, '%Y-%m-%d') #Ensure that valid string date was given
except ValueError as e:
logging.error("Datetime strings must be provided in a '%Y-%m-%d' format!")
raise e
response = send_slack_message(f"{cluster.capitalize()} Maintenance Report for {date.strftime('%Y-%m-%d')}",
debug=debug, token_path = token_path, channel_id = slack_channel_id)
try:
assert response["ok"]
except AssertionError as e:
logging.error("response not okay!")
raise e
ts = response["ts"]
#ts = 1728236369.946879
logging.debug(f"ts is {ts}")
#Get db creds
with open(database_login_file, 'r') as file:
db_params = json.load(file)["database"]
#Get all nodes for this cluster
all_nodes = get_all_nodes(partition=partition)
for application in health_check_apps:
#Get all data from most recent date
query:str = get_query(cluster=cluster, application = application, date = date, timespan=timespan) #TODO change this to day
data:pd.DataFrame = query_database(db_params = db_params, query = query).sort_values(by="datetime", ascending = True)
data = data.drop_duplicates(keep = "first", subset = "node") #Keep only the most recent if there are multiple
data = data.sort_values(by="node")
application_pngpath = make_maintenence_graph(data, application)
graph_file = {'file' : (f"{application}.png", open(application_pngpath, 'rb'), 'image/png')}
undocumented_nodes:list = list(set(all_nodes) - set(data.node))
# Upload image to slack
upload_response = upload_slack_file(application_pngpath,
channel_id = slack_channel_id,
upload_file = graph_file,
ts = ts,
token_path = token_path,
debug = debug)
# Upload undocumented nodes
message = f"Undocumented {application} nodes: {' '.join(undocumented_nodes)}"
with tempfile.NamedTemporaryFile(mode="w+") as tmp:
tmp.write(message)
tmp.read()
upload_slack_file(tmp.name, ts, debug=debug,
token_path = token_path, channel_id = slack_channel_id)
############################################# ARGUMENT PARSING ################################################
def main():
parser = argparse.ArgumentParser()
#Arguments for configurations
parser.add_argument("--slack_channel_id", type = str, default= "C068GC6QWCV", help = "Slack channedl ID to send messages to")
parser.add_argument('--debug', action="store_true", help='Will report to the "cluster_health_debug" channel if provided')
parser.add_argument('--log_level', type=str,
choices=['debug', 'info', "warning", "error", "critical"], default = "warning", help='Set the logging level')
#Arguments for cluster_benchmarking reporting
parser.add_argument('--benchmark', action="store_true", help='Will report the behcnmark reusult for a specified timespan')
parser.add_argument('--timespan', type=str,
choices=["day","week", "month", "year"], default = "week", help='Timespan to report for --benchmark option')
parser.add_argument('--resubmit', action="store_true", help='Will resubmit nodes with outlier performance if provided')
parser.add_argument('--maintenancecheck', action="store_true", help='Will report benchmark_results for all nodes after a maintenence')
#Arguments for cluster_health reporting
parser.add_argument('--healthcheck', action="store_true", help='Will run a healthcheck and log to Slack')
parser.add_argument('--healthsum', action="store_true", help='WWill print the EOD Health summary to Slack')
parser.add_argument('-t', '--tolerance', metavar='%', type=float, default=0.025,
help='A float representing the percent (as a decimal) change in node availability we can silently ignore.')
parser.add_argument('--health_dir',type=str, default="/depot/itap/verburgt/repos/cluster_benchmarking/cluster_health_data/",
help='Default path for storing health_data JSON files')
cluster_data = get_cluster_data(cluster=cluster)
token_path = cluster_data["slack_token_path"]
database_login_file = cluster_data["database_login_file"]
health_data_dir = cluster_data["health_data_dir"]
partition = cluster_data["partition"]
#Process arguments
args = parser.parse_args()
#Set up logging
log_level_info = {'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'CRITICAL':logging.CRITICAL
}
log_level = log_level_info.get(args.log_level.upper(), logging.INFO)
logging.basicConfig(level=log_level,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
#Run
if not any([args.healthcheck, args.healthsum, args.benchmark, args.maintenancecheck]):
raise ValueError("one of healthcheck, healthsum, or benchmark, or maintenancecheck must be set!")
if args.benchmark:
report_performance(timespan=args.timespan,
cluster = cluster,
token_path=token_path,
debug = args.debug,
database_login_file = database_login_file,
resubmit=args.resubmit,
slack_channel_id = args.slack_channel_id)
if args.maintenancecheck:
report_maintenance(database_login_file = database_login_file,
slack_channel_id = args.slack_channel_id,
token_path=token_path,
timespan=args.timespan,
debug = args.debug)
if args.healthcheck:
healthcheck(critical_percent=args.tolerance,
debug=args.debug,
health_dir = health_data_dir,
token_path = token_path,
partition = partition,
slack_channel_id = args.slack_channel_id)
if args.healthsum:
get_summary(debug=args.debug,
token_path = token_path,
partition = partition,
slack_channel_id = args.slack_channel_id)
if __name__ == "__main__":
main()