def write(self, html_format=False): if (not html_format): wdata = self.__get_text(colorize=False) if (wdata): filename = "%s.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message) else: bdata = "" if (self.__pids_in_snapshots): bdata += generate_table(self.__pids_in_snapshots, ["Filesystem", "Pid", "Command", "Number of Snapshots Appeared in"], title="Pids Appearing in Multiple Snapshots", description="The pids that appeared in multiple snapshots.") if (self.__pids_using_multiple_glocks): bdata += generate_table(self.__pids_using_multiple_glocks, ["Filesystem", "Pid", "Command", "Number of Glocks Appeared in", "Glock Type/Inode"], title="Pids that Appeared in Multiple Glocks.", description="The pids that appeared in multiple glocks.") if (bdata): wdata = "%s\n%s\n%s" %(generate_css_header(include_css_table=True), bdata, generate_footer()) filename = "%s.html" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def write(self, html_format=False): wdata = "" path_to_output_file = "" if (not html_format): wdata = self.__get_text(colorize=False) filename = "%s.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) else: filename = "%s.html" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) bdata = self.__get_html(colorize=True) if (bdata): wdata = "%s\n%s\n<BR/><HR/><BR/>%s" %(generate_css_header(), bdata, generate_footer()) if (wdata): if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message) raw_data = self.__get_raw() if (raw_data): filename = "%s-raw.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) if (not write_to_file(path_to_output_file, "%s\n" %(raw_data), append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def write(self, html_format=False): wdata = "" filename = "" if (not html_format): filename = "%s.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) wdata = self.__get_text(colorize=False) else: bdata = "" filename = "%s.html" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) if ((not self.__gs_glocks_total_lowest == None) or (not self.__gs_glocks_total_highest == None)): glocks_stats_totals_table = self.__get_glocks_count_table() if (len(glocks_stats_totals_table)): title = "The lowest and highest total count of glocks in all the snapshots." bdata += generate_table(glocks_stats_totals_table, ["Hostname", "Filesystem", "Time Occurred", "Glock Total Count"], title=title, description="") for snapshot in self.get_snapshots(): glocks_stats = snapshot.get_glocks_stats() title = "Glock stats at %s for filesystem: %s" %(glocks_stats.get_date_time().strftime("%Y-%m-%d %H:%M:%S"), self.get_filesystem_name()) bdata += generate_table(glocks_stats.get_table(), ["-"] + GLOCK_TYPES, title=title, description="") if (bdata): wdata = "%s\n%s\n%s" %(generate_css_header(include_css_table=True), bdata, generate_footer()) if (wdata): path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def write(self, html_format=False): if (self.__glocks_high_demote_seconds): wdata = "" path_to_output_file = "" if (not html_format): filename = "%s.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) wdata = self.__get_text(colorize=False) else: filename = "%s.html" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) table = [] for hashkey in self.__glocks_high_demote_seconds.keys(): table.append([self.get_filesystem_name(), hashkey, self.__glocks_high_demote_seconds.get(hashkey).strip()]) bdata = generate_table(table, ["Filesystem", "Glock", "Demote Seconds"], title=self.get_title(), description="Glocks that took longer than 0 seconds to demote a glock") wdata = "%s\n%s\n%s" %(generate_css_header(include_css_table=True), bdata, generate_footer()) if (wdata): if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def write(self, html_format=False): if (self.__glocks_in_snapshots): wdata = "" path_to_output_file = "" if (not html_format): filename = "%s.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) wdata = self.__get_text(colorize=False) else: filename = "%s.html" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) table = [] for pair in sorted(self.__glocks_in_snapshots.items(), key=itemgetter(1), reverse=True): if (pair[1] >= self.__minimum_glocks_in_snapshots): table.append([self.get_hostname(), self.get_filesystem_name(), pair[0], pair[1]]) bdata = generate_table(table, ["Hostname", "Filesystem Name", "Glock Type/Glocks Inode", "Number of Snapshots Appeared in"], title=self.get_title(), description="The number of times that a glock appeared in a snapshot.") wdata = "%s\n%s\n%s" %(generate_css_header(include_css_table=True), bdata, generate_footer()) if (wdata): if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def write(self, html_format=False): wdata ="" path_to_output_file = "" if (not html_format): filename = "%s.txt" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) wdata = self.__get_text(colorize=False) else: bdata = "" if (self.__snapshot_count > 0): bdata += generate_table([[self.get_hostname(), self.get_filesystem_name(), str(self.__snapshot_count), self.__start_time, self.__stop_time]], ["Hostname", "Filesystem", "Snapshots", "Start Time", "Stop Time"], title="Snapshots Taken", description="The number of snapshots taken and the time that first and the last snapshot taken.") if (self.__dlm_activity): bdata += generate_table(self.__dlm_activity, ["Hostname", "Filesystem", "Snapshot Time", "Number of DLM Waiters"], title="DLM Waiter Count", description="The number of DLM waiters for a snapshot. Only snapshots with DLM waiter count higher than 0 displayed.") if (bdata): wdata = "%s\n%s\n%s" %(generate_css_header(include_css_table=True), bdata, generate_footer()) filename = "%s.html" %(self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join(os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename) if (wdata): if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing to the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def write(self, html_format=False): wdata = "" path_to_output_file = "" if not html_format: summary = self.__get_text(colorize=False) if summary: wdata = "%s: %s\n%s\n" % (self.get_title(), self.get_description(), summary.strip()) filename = "%s.txt" % (self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join( os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename ) else: message = "This plugin does not currently have HTML format. Only text format." logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).info(message) summary = self.__get_text(colorize=False) if summary: wdata = "%s: %s\n%s\n" % (self.get_title(), self.get_description(), summary.strip()) filename = "%s.txt" % (self.get_title().lower().replace(" - ", "-").replace(" ", "_")) path_to_output_file = os.path.join( os.path.join(self.get_path_to_output_dir(), self.get_filesystem_name()), filename ) if wdata: if not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True): message = "An error occurred writing to the file: %s" % (path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def merge_glock_dumps(self, path_to_output_dir): path_to_merged_files = [] for gfs2_name in gsds.get_gfs2_names(): list_of_gsd = gsds.get_glocks_dumps(gfs2_name) message = "Merging %d glocks dumps for the host \"%s\" for the filesystem \"%s\"." %(len(list_of_gsd), self.get_hostname(), gfs2_name) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).info(message) path_to_merged_file = os.path.join(path_to_output_dir, "glock_dump-%s-%s.txt" %(self.get_hostname(), gfs2_name)) if (os.path.exists(path_to_merged_file)): try: os.remove(path_to_merged_file) except IOError: message = "There was an error removing the file: %s." %(path_to_merged_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).error(message) for gsd in list_of_gsd: glocks_dump_data = "" for line in get_data_from_file(gsd.get_path_to_glockfile(), strip_leading_character=False): glocks_dump_data += "%s\n" %(line) if (glocks_dump_data): glocks_dump_data = "%s\n%s\n" %(gsd.get_header(), glocks_dump_data) if (not write_to_file(path_to_merged_file, glocks_dump_data, append_to_file=True, create_file=True)): message = "There was an error writing to the file: %s" %(path_to_merged_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).error(message) if (os.path.exists(path_to_merged_file)): path_to_merged_files.append(path_to_merged_file) return path_to_merged_files
def __output_warnings(warnings, path_to_output_dir, disable_std_out=True, html_format=False): if (warnings): sorted_warnings = [] # Remove the duplicates that are found. for warning in warnings: if (not warning in sorted_warnings): sorted_warnings.append(warning) sorted_warnings = sorted(sorted_warnings, key=lambda x: x.get_filesystem_name(), reverse=False) def get_warning_text(warnings, colorize=False): warnings_table = [] for warning in warnings: uri = "-" if (warning.get_uri()): uri = warning.get_uri() warnings_table += [[warning.get_hostname(), warning.get_filesystem_name(), warning.get_type(), warning.get_description(), uri]] header = "Warnings Found:" if (warnings_table and colorize): header = ColorizeConsoleText.red("%s" %(header)) return "\n\n%s\n%s\n" %(header, tableize(warnings_table, ["Hostname", "Filesystem", "Type", "Description", "Link to Article"], colorize=colorize).strip()) if (not disable_std_out): print get_warning_text(sorted_warnings, colorize=True) # Write warnings to text file or html file wdata = "%s\n" %(get_warning_text(sorted_warnings, colorize=False).strip()) path_to_output_file = os.path.join(path_to_output_dir, "warnings.txt") if (html_format): path_to_output_file = os.path.join(path_to_output_dir, "warnings.html") bdata = "" warnings_table = [] for warning in sorted_warnings: uri = "-" if (warning.get_uri()): uri = warning.get_uri() warnings_table += [[warning.get_hostname(), warning.get_filesystem_name(), warning.get_type(), warning.get_description(), uri]] bdata = generate_table(warnings_table, ["Hostname", "Filesystem", "Type", "Description", "Link to Article"], title="Warnings", description="The following is a list of potential issues found:") wdata = "%s\n%s\n%s" %(generate_css_header(include_css_table=True), bdata, generate_footer()) if (wdata): if (not write_to_file(path_to_output_file, wdata, append_to_file=False, create_file=True)): message = "An error occurred writing the file: %s" %(path_to_output_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)
def generate_graph_index_page(path_to_output_dir, path_to_graphs, title): # Need to create a space instead of using tabs. figure_code_pre_svg = '\t\t<figure> <embed type="image/svg+xml" src="' figure_code_pre_png = '\t\t<figure> <embed type="image/png" src="' figure_code_post = '"/></figure><BR/><BR/><HR/><BR/>' figure_code = "" for path_to_image_file in path_to_graphs: # Need code to check if png or svg. if path_to_image_file.endswith("svg"): figure_code += figure_code_pre_svg elif path_to_image_file.endswith("png"): figure_code += figure_code_pre_png figure_code += "graphs/%s%s" % (os.path.split(path_to_image_file)[1], figure_code_post) html_data = "%s%s%s" % (generate_header(), figure_code, generate_footer_graphs()) path_to_html_file = os.path.join( path_to_output_dir, "%s.html" % (title.replace(" - ", "-").replace(" ", "_").lower()) ) if write_to_file(path_to_html_file, html_data, append_to_file=False, create_file=True): message = "The html page containing the graphs was written to: %s" % (path_to_html_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message) else: message = "There was an error writing the html page containing the graphs to: %s" % (path_to_html_file) logging.getLogger(glocktop_analyze.MAIN_LOGGER_NAME).debug(message)