Best Python code snippet using yandex-tank
plugin.py
Source:plugin.py  
...232        self.time = {}233        self.max_metric_len = 0234    def get_index(self):235        return 50236    def __handle_data_items(self, host, data):237        """ store metric in data tree and calc offset signs238        sign < 0 is CYAN, means metric value is lower then previous,239        sign > 1 is YELLOW, means metric value is higher then prevoius,240        sign == 0 is WHITE, means initial or equal metric value241        """242        for metric, value in data.iteritems():243            if value == '':244                self.sign[host][metric] = -1245                self.data[host][metric] = value246            else:247                if not self.data[host].get(metric, None):248                    self.sign[host][metric] = 1249                elif float(value) > float(self.data[host][metric]):250                    self.sign[host][metric] = 1251                elif float(value) < float(self.data[host][metric]):252                    self.sign[host][metric] = -1253                else:254                    self.sign[host][metric] = 0255                self.data[host][metric] = "%.2f" % float(value)256    def monitoring_data(self, block):257        # block sample :258        # [{'timestamp': 1480536634,259        #   'data': {260        #     'some.hostname.tld': {261        #       'comment': '',262        #       'metrics': {263        #         'custom:diskio_reads': 0,264        #         'Net_send': 9922,265        #         'CPU_steal': 0,266        #         'Net_recv': 8489267        #       }268        #     }269        #   },270        #   ...271        # }]272        for chunk in block:273            host = chunk['data'].keys()[0]274            self.time[host] = chunk['timestamp']275            # if initial call, we create dicts w/ data and `signs`276            # `signs` used later to paint metrics w/ different colors277            if not self.data.get(host, None):278                self.data[host] = {}279                self.sign[host] = {}280                for key, value in chunk['data'][host]['metrics'].iteritems():281                    self.sign[host][key] = 0282                    self.data[host][key] = value283            else:284                self.__handle_data_items(host, chunk['data'][host]['metrics'])285    def render(self, screen):286        if not self.owner.monitoring:287            return "Monitoring is " + screen.markup.RED + "offline" + screen.markup.RESET288        else:289            res = "Monitoring is " + screen.markup.GREEN + \290                  "online" + screen.markup.RESET + ":\n"291            for hostname, metrics in self.data.items():292                tm_stamp = datetime.datetime.fromtimestamp(293                    float(self.time[hostname])).strftime('%H:%M:%S')294                res += ("   " + screen.markup.CYAN + "%s" + screen.markup.RESET +295                        " at %s:\n") % (hostname, tm_stamp)296                for metric, value in sorted(metrics.iteritems()):297                    if self.sign[hostname][metric] > 0:298                        value = screen.markup.YELLOW + value + screen.markup.RESET...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
