Return NTP stats (associations).
169910
def get_ntp_stats(self):
        """"""
        # NTP Peers does not have XML RPC defined
        # thus we need to retrieve raw text and parse...
        # :(

        ntp_stats = []

        REGEX = (
            r"^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)"
            r"\s+([a-zA-Z0-9\.]+)\s+([0-9]{1,2})"
            r"\s+(-|u)\s+([0-9h-]+)\s+([0-9]+)"
            r"\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.-]+)"
            r"\s+([0-9\.]+)\s?$"
        )

        ntp_assoc_output = self.device.cli("show ntp associations no-resolve")
        ntp_assoc_output_lines = ntp_assoc_output.splitlines()

        for ntp_assoc_output_line in ntp_assoc_output_lines[3:]:  # except last line
            line_search = re.search(REGEX, ntp_assoc_output_line, re.I)
            if not line_search:
                continue  # pattern not found
            line_groups = line_search.groups()
            try:
                ntp_stats.append(
                    {
                        "remote": napalm.base.helpers.ip(line_groups[1]),
                        "synchronized": (line_groups[0] == "*"),
                        "referenceid": py23_compat.text_type(line_groups[2]),
                        "stratum": int(line_groups[3]),
                        "type": py23_compat.text_type(line_groups[4]),
                        "when": py23_compat.text_type(line_groups[5]),
                        "hostpoll": int(line_groups[6]),
                        "reachability": int(line_groups[7]),
                        "delay": float(line_groups[8]),
                        "offset": float(line_groups[9]),
                        "jitter": float(line_groups[10]),
                    }
                )
            except Exception:
                continue  # jump to next line

        return ntp_stats
820446
def get_network_stats(self, tags):
        

        # FIXME: (aaditya) Check all networks defaults to true
        # until we can reliably assign agents to networks to monitor
        if is_affirmative(self.init_config.get('check_all_networks', True)):
            all_network_ids = set(self.get_all_network_ids())

            # Filter out excluded networks
            network_ids = [
                network_id
                for network_id in all_network_ids
                if not any([re.match(exclude_id, network_id) for exclude_id in self.exclude_network_id_rules])
            ]
        else:
            network_ids = self.init_config.get('network_ids', [])

        if not network_ids:
            self.warning(
                "Your check is not configured to monitor any networks.\n"
                + "Please list `network_ids` under your init_config"
            )

        for nid in network_ids:
            self.get_stats_for_single_network(nid, tags)
328170
def retrieveVals(self):
        """"""
        ntpinfo = NTPinfo()
        ntpstats = ntpinfo.getHostOffsets(self._remoteHosts)
        if ntpstats:
            for host in self._remoteHosts:
                hostkey = re.sub('\.', '_', host)
                hoststats = ntpstats.get(host)
                if hoststats:
                    if self.hasGraph('ntp_host_stratums'):
                        self.setGraphVal('ntp_host_stratums', hostkey, 
                                         hoststats.get('stratum'))
                    if self.hasGraph('ntp_host_offsets'):
                        self.setGraphVal('ntp_host_offsets', hostkey, 
                                         hoststats.get('offset'))
                    if self.hasGraph('ntp_host_delays'):
                        self.setGraphVal('ntp_host_delays', hostkey, 
                                         hoststats.get('delay'))
757932
def get_relations_cnt(self):
        """"""
        return cx.Counter([e.relation for es in self.exts for e in es])
532472
def stat(self):
        """"""
        return (self._opened_conns, len(self._free_conn), len(self._waitings))
1034202
def netstat():
    '''
    
    '''
    ret = []
    cmd = ['netstat', '-nao']
    lines = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
    for line in lines:
        comps = line.split()
        if line.startswith('  TCP'):
            ret.append({
                'local-address': comps[1],
                'proto': comps[0],
                'remote-address': comps[2],
                'state': comps[3],
                'program': comps[4]})
        if line.startswith('  UDP'):
            ret.append({
                'local-address': comps[1],
                'proto': comps[0],
                'remote-address': comps[2],
                'state': None,
                'program': comps[3]})
    return ret
229575
def get_relation_cnt(self):
        """"""
        ctr = cx.Counter()
        for ntgpad in self.associations:
            if ntgpad.Extension is not None:
                ctr += ntgpad.Extension.get_relations_cnt()
        return ctr
858986
def stats (self, antnames):
        """"""
        nbyant = np.zeros (self.nants, dtype=np.int)
        sum = np.zeros (self.nants, dtype=np.complex)
        sumsq = np.zeros (self.nants)
        q = np.abs (self.normvis - 1)

        for i in range (self.nsamps):
            i1, i2 = self.blidxs[i]
            nbyant[i1] += 1
            nbyant[i2] += 1
            sum[i1] += q[i]
            sum[i2] += q[i]
            sumsq[i1] += q[i]**2
            sumsq[i2] += q[i]**2

        avg = sum / nbyant
        std = np.sqrt (sumsq / nbyant - avg**2)
        navg = 1. / np.median (avg)
        nstd = 1. / np.median (std)

        for i in range (self.nants):
            print ('  %2d %10s %3d %f %f %f %f' %
                   (i, antnames[i], nbyant[i], avg[i], std[i], avg[i] * navg, std[i] * nstd))
692391
def get_statistics(self):
        
        stats = {
            "creation_time": self._creation_time_in_seconds,
            "evictions": self._evictions,
            "expirations": self._expirations,
            "misses": self._misses,
            "hits": self._hits,
            "invalidations": self._invalidations,
            "invalidation_requests": self._invalidation_requests,
            "owned_entry_count": self.__len__(),
            "owned_entry_memory_cost": getsizeof(self),
        }

        return stats
967
def getStats(self):
        
        stats = protocol.ReadStats()
        stats.aligned_read_count = self.getNumAlignedReads()
        stats.unaligned_read_count = self.getNumUnalignedReads()
        # TODO base_count requires iterating through all reads
        return stats
852375
def chk_associations(self, fout_err="gaf.err"):
        """"""
        obj = GafData("2.1")
        return obj.chk(self.associations, fout_err)
146250
def stats():
    '''
    
    '''
    ret = {}
    out = __salt__['cmd.run']('quotastats').splitlines()
    for line in out:
        if not line:
            continue
        comps = line.split(': ')
        ret[comps[0]] = comps[1]

    return ret
1233217
def retrieveVals(self):
        """"""
        for iface in self._ifaceList:
            stats = self._ifaceStats.get(iface)
            graph_name = 'netiface_traffic_%s' % iface
            if self.hasGraph(graph_name):
                self.setGraphVal(graph_name, 'rx', stats.get('rxbytes') * 8)
                self.setGraphVal(graph_name, 'tx', stats.get('txbytes') * 8)
            graph_name = 'netiface_errors_%s' % iface
            if self.hasGraph(graph_name):
                for field in ('rxerrs', 'txerrs', 'rxframe', 'txcarrier',
                    'rxdrop', 'txdrop', 'rxfifo', 'txfifo'):
                    self.setGraphVal(graph_name, field, stats.get(field))
554729
def update(self):
        """"""
        # Init new stats
        stats = self.get_init_value()

        # Grab per-CPU stats using psutil's cpu_percent(percpu=True) and
        # cpu_times_percent(percpu=True) methods
        if self.input_method == 'local':
            stats = cpu_percent.get(percpu=True)
        else:
            # Update stats using SNMP
            pass

        # Update the stats
        self.stats = stats

        return self.stats
619448
def getStats(self):
        
        stats = protocol.ReadStats()
        stats.aligned_read_count = self._numAlignedReads
        stats.unaligned_read_count = self._numUnalignedReads
        return stats
696309
def getPeerStats(self):
        
        info_dict = {}
        output = util.exec_command([ntpqCmd, '-n', '-c', 'peers'])
        for line in output.splitlines():
            mobj = re.match('\*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+', line)
            if mobj:
                info_dict['ip'] = mobj.group(1)
                cols = line.split()
                info_dict['stratum'] = int(cols[2])
                info_dict['delay'] = float(cols[7]) / 1000.0
                info_dict['offset'] = float(cols[8]) / 1000.0
                info_dict['jitter'] = float(cols[9]) / 1000.0
                return info_dict
        else:
            raise Exception("Execution of command failed: %s" % ntpqCmd)
        return info_dict
763834
def get_goea_nts_prt(self, fldnames=None, **usr_kws):
        """"""
        kws = usr_kws.copy()
        if 'not_fldnames' not in kws:
            kws['not_fldnames'] = ['goterm', 'parents', 'children', 'id']
        if 'rpt_fmt' not in kws:
            kws['rpt_fmt'] = True
        return self.get_goea_nts_all(fldnames, **kws)