def get_grafana_screenshot(self, node, local_dst): """ Take screenshot of the Grafana per-server-metrics dashboard and upload to S3 """ _, _, monitoring_version = self.get_monitoring_version(node) if not monitoring_version: LOGGER.warning("Monitoring version was not found") return [] version = monitoring_version.replace('.', '-') try: screenshots = [] remote_browser = RemoteBrowser(node) for screenshot in self.grafana_entity_names: dashboard_exists = MonitoringStack.dashboard_exists( grafana_ip=node.grafana_address, uid="-".join([screenshot['name'], version])) if not dashboard_exists: version = "master" path = screenshot['path'].format( version=version, dashboard_name=screenshot['name']) grafana_url = self.grafana_entity_url_tmpl.format( node_ip=node.grafana_address, grafana_port=self.grafana_port, path=path, st=self.start_time) screenshot_path = os.path.join( local_dst, "%s-%s-%s-%s.png" % (self.name, screenshot['name'], datetime.datetime.now().strftime("%Y%m%d_%H%M%S"), node.name)) LOGGER.debug("Get screenshot for url %s, save to %s", grafana_url, screenshot_path) remote_browser.get_screenshot( grafana_url, screenshot_path, screenshot['resolution'], load_page_screenshot_delay=self.collect_timeout) screenshots.append(screenshot_path) return screenshots except Exception as details: # pylint: disable=broad-except LOGGER.error( f'Error taking monitor screenshot: {str(details)}, traceback: {traceback.format_exc()}' ) return []
def get_grafana_snapshot(self, node): """ Take snapshot of the Grafana per-server-metrics dashboard and upload to S3 """ _, _, monitoring_version = MonitoringStack.get_monitoring_version(node) webdriver_container = RemoteWebDriverContainer(node) try: if not webdriver_container.is_running(): webdriver_container.run() remote_browser = RemoteBrowser(webdriver_container) snapshots = [] for snapshot in self.grafana_entity_names: version = monitoring_version.replace('.', '-') dashboard_exists = MonitoringStack.dashboard_exists( node, uid="-".join([snapshot['name'], version])) if not dashboard_exists: version = "master" path = snapshot['path'].format(version=version, dashboard_name=snapshot['name']) grafana_url = self.grafana_entity_url_tmpl.format( node_ip=node.external_address, grafana_port=self.grafana_port, path=path, st=self.start_time) LOGGER.info("Get snapshot link for url %s", grafana_url) snapshots.append( self._get_shared_snapshot_link(remote_browser.browser, grafana_url)) return snapshots except Exception as details: # pylint: disable=broad-except LOGGER.error('Error taking monitor snapshot: %s', str(details)) return []
def get_grafana_screenshot(self, node, local_dst): """ Take screenshot of the Grafana per-server-metrics dashboard and upload to S3 """ _, _, monitoring_version = MonitoringStack.get_monitoring_version(node) version = monitoring_version.replace('.', '-') webdriver_container = RemoteWebDriverContainer(node) try: screenshots = [] if not webdriver_container.is_running(): webdriver_container.run() remote_browser = RemoteBrowser(webdriver_container) for screenshot in self.grafana_entity_names: dashboard_exists = MonitoringStack.dashboard_exists( node, uid="-".join([screenshot['name'], version])) if not dashboard_exists: version = "master" path = screenshot['path'].format( version=version, dashboard_name=screenshot['name']) grafana_url = self.grafana_entity_url_tmpl.format( node_ip=node.external_address, grafana_port=self.grafana_port, path=path, st=self.start_time) if not os.path.exists(local_dst): os.makedirs(local_dst, exist_ok=True) screenshot_path = os.path.join( local_dst, "%s-%s-%s-%s.png" % (self.name, screenshot['name'], datetime.datetime.now().strftime("%Y%m%d_%H%M%S"), node.name)) LOGGER.debug("Get screenshot for url %s, save to %s", grafana_url, screenshot_path) remote_browser.get_screenshot(grafana_url, screenshot_path, screenshot['resolution']) screenshots.append(screenshot_path) return screenshots except Exception as details: # pylint: disable=broad-except LOGGER.error('Error taking monitor screenshot: %s', str(details)) return []
def get_grafana_snapshot(self, node): """ Take snapshot of the Grafana per-server-metrics dashboard and upload to S3 """ _, _, monitoring_version = self.get_monitoring_version(node) if not monitoring_version: LOGGER.warning("Monitoring version was not found") return [] try: remote_browser = RemoteBrowser(node) snapshots = [] for snapshot in self.grafana_entity_names: version = monitoring_version.replace('.', '-') dashboard_exists = MonitoringStack.dashboard_exists( grafana_ip=node.grafana_address, uid="-".join([snapshot['name'], version])) if not dashboard_exists: version = "master" path = snapshot['path'].format(version=version, dashboard_name=snapshot['name']) grafana_url = self.grafana_entity_url_tmpl.format( node_ip=node.grafana_address, grafana_port=self.grafana_port, path=path, st=self.start_time) LOGGER.info("Get snapshot link for url %s", grafana_url) snapshots.append( self._get_shared_snapshot_link(remote_browser.browser, grafana_url)) return snapshots except Exception as details: # pylint: disable=broad-except LOGGER.error( f'Error taking monitor snapshot: {str(details)}, traceback: {traceback.format_exc()}' ) return []