(self, output, varnishstat_format, tags=None)
The text option (-1) is not reliable enough when counters get large.
        VBE.media_video_prd_services_01(10.93.67.16,,8080).happy18446744073709551615

        2 types of data, "a" for counter ("c" in newer versions of varnish), "i" for gauge ("g")
        https://github.com/varnish/Varnish-Cache/blob/master/include/tbl/vsc_fields.h

        Bitmaps are not supported.
The text option (-1) is not reliable enough when counters get large.
        VBE.media_video_prd_services_01(10.93.67.16,,8080).happy18446744073709551615
The text option ( - 1 ) is not reliable enough when counters get large . VBE . media_video_prd_services_01 ( 10 . 93 . 67 . 16 8080 ) . happy18446744073709551615
def _parse_varnishstat(self, output, varnishstat_format, tags=None):
        """
        The text option (-1) is not reliable enough when counters get large.
        VBE.media_video_prd_services_01(10.93.67.16,,8080).happy18446744073709551615

        2 types of data, "a" for counter ("c" in newer versions of varnish), "i" for gauge ("g")
        https://github.com/varnish/Varnish-Cache/blob/master/include/tbl/vsc_fields.h

        Bitmaps are not supported.
        """
        tags = tags or []
        # FIXME: this check is processing an unbounded amount of data
        # we should explicitly list the metrics we want to get from the check
        if varnishstat_format == "xml":
            p = xml.parsers.expat.ParserCreate()
            p.StartElementHandler = self._start_element
            p.EndElementHandler = lambda name: self._end_element(name, tags)
            p.CharacterDataHandler = self._char_data
            self._reset()
            p.Parse(output, True)
        elif varnishstat_format == "json":
            json_output = json.loads(output)
            if "counters" in json_output:
                json_output = json_output["counters"]
            for name, metric in iteritems(json_output):
                if not isinstance(metric, dict):  # skip 'timestamp' field
                    continue

                if name.startswith("MAIN."):
                    name = name.split('.', 1)[1]

                metric_name = self.normalize(name, prefix="varnish")
                value = metric.get("value", 0)

                if metric.get("flag") in ("a", "c"):
                    self.rate(metric_name, long(value), tags=tags)
                elif metric.get("flag") in ("g", "i"):
                    self.gauge(metric_name, long(value), tags=tags)
                    if 'n_purges' in self.normalize(name, prefix="varnish"):
                        self.rate('varnish.n_purgesps', long(value), tags=tags)
                elif 'flag' not in metric:
                    self.log.warning("Could not determine the type of metric %s, skipping submission", metric_name)
                    self.log.debug("Raw metric %s is missing the `flag` field", str(metric))
        elif varnishstat_format == "text":
            for line in output.split("\n"):
                self.log.debug("Parsing varnish results: %s", line)
                fields = line.split()
                if len(fields) < 3:
                    break
                name, gauge_val, rate_val = fields[0], fields[1], fields[2]
                metric_name = self.normalize(name, prefix="varnish")

                # Now figure out which value to pick
                if rate_val.lower() in ("nan", "."):
                    # col 2 matters
                    self.log.debug("Varnish (gauge) %s %d", metric_name, int(gauge_val))
                    self.gauge(metric_name, int(gauge_val), tags=tags)
                    if 'n_purges' in metric_name:
                        self.rate('varnish.n_purgesps', float(gauge_val), tags=tags)
                else:
                    # col 3 has a rate (since restart)
                    self.log.debug("Varnish (rate) %s %d", metric_name, int(gauge_val))
                    self.rate(metric_name, float(gauge_val), tags=tags)
def _parse_varnishstat ( self , output , varnishstat_format , tags = None ) : tags = tags or [ ] # FIXME: this check is processing an unbounded amount of data # we should explicitly list the metrics we want to get from the check if varnishstat_format == "xml" : p = xml . parsers . expat . ParserCreate ( ) p . StartElementHandler = self . _start_element p . EndElementHandler = lambda name : self . _end_element ( name , tags ) p . CharacterDataHandler = self . _char_data self . _reset ( ) p . Parse ( output , True ) elif varnishstat_format == "json" : json_output = json . loads ( output ) if "counters" in json_output : json_output = json_output [ "counters" ] for name , metric in iteritems ( json_output ) : if not isinstance ( metric , dict ) : # skip 'timestamp' field continue if name . startswith ( "MAIN." ) : name = name . split ( '.' , 1 ) [ 1 ] metric_name = self . normalize ( name , prefix = "varnish" ) value = metric . get ( "value" , 0 ) if metric . get ( "flag" ) in ( "a" , "c" ) : self . rate ( metric_name , long ( value ) , tags = tags ) elif metric . get ( "flag" ) in ( "g" , "i" ) : self . gauge ( metric_name , long ( value ) , tags = tags ) if 'n_purges' in self . normalize ( name , prefix = "varnish" ) : self . rate ( 'varnish.n_purgesps' , long ( value ) , tags = tags ) elif 'flag' not in metric : self . log . warning ( "Could not determine the type of metric %s, skipping submission" , metric_name ) self . log . debug ( "Raw metric %s is missing the `flag` field" , str ( metric ) ) elif varnishstat_format == "text" : for line in output . split ( "\n" ) : self . log . debug ( "Parsing varnish results: %s" , line ) fields = line . split ( ) if len ( fields ) < 3 : break name , gauge_val , rate_val = fields [ 0 ] , fields [ 1 ] , fields [ 2 ] metric_name = self . normalize ( name , prefix = "varnish" ) # Now figure out which value to pick if rate_val . lower ( ) in ( "nan" , "." ) : # col 2 matters self . log . debug ( "Varnish (gauge) %s %d" , metric_name , int ( gauge_val ) ) self . gauge ( metric_name , int ( gauge_val ) , tags = tags ) if 'n_purges' in metric_name : self . rate ( 'varnish.n_purgesps' , float ( gauge_val ) , tags = tags ) else : # col 3 has a rate (since restart) self . log . debug ( "Varnish (rate) %s %d" , metric_name , int ( gauge_val ) ) self . rate ( metric_name , float ( gauge_val ) , tags = tags )