-
Notifications
You must be signed in to change notification settings - Fork 3
/
lustre-monthly-reports.py
executable file
·227 lines (160 loc) · 7.24 KB
/
lustre-monthly-reports.py
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
#!/usr/bin/env python3
#
# -*- coding: utf-8 -*-
#
# © Copyright 2023 GSI Helmholtzzentrum für Schwerionenforschung
#
# This software is distributed under
# the terms of the GNU General Public Licence version 3 (GPL Version 3),
# copied verbatim in the file "LICENCE".
import configparser
import datetime
import argparse
import logging
import os
import dateutil.relativedelta
from chart.trend_chart import TrendChart
from dataset.lfsdb_quota_history import QuotaHistoryTable
from utils.matplotlib_ import check_matplotlib_version
from utils.rsync_ import transfer_report
from utils.pandas_ import create_data_frame_weekly
from utils.getent_group import get_user_groups
import dataset.item_handler as ih
def create_usage_trend_chart(local_mode,
fs_long_name,
chart_dir,
start_date,
end_date,
threshold,
usage_trend_chart,
quota_history_table):
if local_mode:
item_list = ih.create_dummy_group_date_values(8, 1000)
else:
groups = get_user_groups()
filtered_groups = \
quota_history_table.filter_groups_at_threshold(start_date,
end_date,
threshold,
groups)
item_list = \
quota_history_table.get_time_series_group_sizes(
start_date,
end_date,
filtered_groups)
group_item_dict = ih.create_group_date_value_item_dict(item_list)
data_frame = create_data_frame_weekly(group_item_dict)
title = "Top Groups Usage Trend on %s" % fs_long_name
chart_path = chart_dir + os.path.sep + usage_trend_chart
chart = TrendChart(title,
data_frame,
chart_path,
'Time (Weeks)',
'Disk Space Used (TiB)')
chart.create()
return chart_path
def create_quota_trend_chart(local_mode,
fs_long_name,
chart_dir,
start_date,
end_date,
quota_trend_chart,
quota_history_table):
if local_mode:
item_list = ih.create_dummy_group_date_values(50, 200)
else:
groups = get_user_groups()
item_list = \
quota_history_table.get_time_series_group_quota_usage(start_date,
end_date,
groups)
group_item_dict = ih.create_group_date_value_item_dict(item_list)
data_frame = create_data_frame_weekly(group_item_dict)
title = "Group Quota Trend on %s" % fs_long_name
chart_path = chart_dir + os.path.sep + quota_trend_chart
chart = TrendChart(title,
data_frame,
chart_path,
'Time (Weeks)',
'Quota Used (%)')
chart.create()
return chart_path
def main():
parser = argparse.ArgumentParser(
description='Lustre Monthly Report Generator')
parser.add_argument('-f', '--config-file', dest='config_file', type=str,
required=True, help='Path of the config file.')
parser.add_argument('-D', '--enable-debug', dest='enable_debug',
required=False, action='store_true',
help='Enables logging of debug messages.')
parser.add_argument('-L', '--enable-local_mode', dest='enable_local',
required=False, action='store_true',
help='Enables local_mode program execution.')
args = parser.parse_args()
if not os.path.isfile(args.config_file):
raise IOError("The config file does not exist or is not a file: %s" %
args.config_file)
logging_level = logging.INFO
if args.enable_debug:
logging_level = logging.DEBUG
logging.basicConfig(
level=logging_level, format='%(asctime)s - %(levelname)s: %(message)s')
try:
logging.info('START')
date_now = datetime.datetime.now()
check_matplotlib_version()
local_mode = args.enable_local
logging.debug("Local mode enabled: %s" % local_mode)
config = configparser.ConfigParser(interpolation=None)
config.read(args.config_file)
transfer_mode = config.get('transfer', 'mode')
chart_dir = config.get('base_chart', 'report_dir')
fs_long_name = config.get('storage', 'fs_long_name')
date_format = config.get("time_series_chart", "date_format")
prev_months = config.getint("time_series_chart", "prev_months")
usage_trend_chart = config.get('usage_trend_chart', 'filename')
threshold = config.get('usage_trend_chart', 'threshold')
quota_trend_chart = config.get('quota_trend_chart', 'filename')
quota_history_table = \
QuotaHistoryTable(config.get('mysqld', 'host'),
config.get('mysqld', 'user'),
config.get('mysqld', 'passwd'),
config.get('mysqld', 'db'),
config.get('report', 'history_table'))
if prev_months <= 0:
raise RuntimeError( \
"Config parameter 'prev_months' must be greater than 0!")
prev_date = date_now - \
dateutil.relativedelta.relativedelta(months = prev_months)
start_date = prev_date.strftime(date_format)
end_date = date_now.strftime(date_format)
logging.debug("Time series start date: %s" % start_date)
chart_path_list = list()
chart_path = create_usage_trend_chart(local_mode,
fs_long_name,
chart_dir,
start_date,
end_date,
threshold,
usage_trend_chart,
quota_history_table)
logging.debug("Created chart: %s" % chart_path)
chart_path_list.append(chart_path)
chart_path = create_quota_trend_chart(local_mode,
fs_long_name,
chart_dir,
start_date,
end_date,
quota_trend_chart,
quota_history_table)
logging.debug("Created chart: %s" % chart_path)
chart_path_list.append(chart_path)
if transfer_mode == 'on':
for chart_path in chart_path_list:
transfer_report('monthly', date_now, chart_path, config)
logging.info('END')
return 0
except Exception:
logging.exception('Caught exception in main')
if __name__ == '__main__':
main()