Accumulate per-host information and return as a table.
This function does the real work. Everything else is
boilerplate sysproc stuff.
513327
static public VoltTable populateOverviewTable()
    {
        VoltTable vt = constructOverviewTable();
        int hostId = VoltDB.instance().getHostMessenger().getHostId();

        // try to get the external interface first, if none was set, use local addresses
        InetAddress addr = null;
        String clientInterface = null;
        int clientPort = VoltDB.DEFAULT_PORT;
        String adminInterface = null;
        int adminPort = VoltDB.DEFAULT_ADMIN_PORT;
        String httpInterface = null;
        int httpPort = VoltDB.DEFAULT_HTTP_PORT;
        String internalInterface = null;
        int internalPort = Constants.DEFAULT_INTERNAL_PORT;
        String zkInterface = null;
        int zkPort = Constants.DEFAULT_ZK_PORT;
        String drInterface = null;
        int drPort = VoltDB.DEFAULT_DR_PORT;
        String publicInterface = null;
        String drPublicInterface = null;
        int drPublicPort = 0;
        try {
            String localMetadata = VoltDB.instance().getLocalMetadata();
            JSONObject jsObj = new JSONObject(localMetadata);
            JSONArray interfaces = jsObj.getJSONArray("interfaces");
            String iface = interfaces.getString(0);
            addr = InetAddress.getByName(iface);
            clientPort = jsObj.getInt("clientPort");
            clientInterface = jsObj.getString("clientInterface");
            adminPort = jsObj.getInt("adminPort");
            adminInterface = jsObj.getString("adminInterface");
            httpPort = jsObj.getInt("httpPort");
            httpInterface = jsObj.getString("httpInterface");
            internalPort = jsObj.getInt("internalPort");
            internalInterface = jsObj.getString("internalInterface");
            zkPort = jsObj.getInt("zkPort");
            zkInterface = jsObj.getString("zkInterface");
            drPort = jsObj.getInt("drPort");
            drInterface = jsObj.getString("drInterface");
            publicInterface = jsObj.getString("publicInterface");
            drPublicInterface = jsObj.getString(VoltZK.drPublicHostProp);
            drPublicPort = jsObj.getInt(VoltZK.drPublicPortProp);
        } catch (JSONException e) {
            hostLog.info("Failed to get local metadata, falling back to first resolvable IP address.");
        } catch (UnknownHostException e) {
            hostLog.info("Failed to determine hostname, falling back to first resolvable IP address.");
        }

        // host name and IP address.
        if (addr == null) {
            addr = org.voltcore.utils.CoreUtils.getLocalAddress();
        }
        vt.addRow(hostId, "IPADDRESS", addr.getHostAddress());
        vt.addRow(hostId, "HOSTNAME", CoreUtils.getHostnameOrAddress());
        vt.addRow(hostId, "CLIENTINTERFACE", clientInterface);
        vt.addRow(hostId, "CLIENTPORT", Integer.toString(clientPort));
        vt.addRow(hostId, "ADMININTERFACE", adminInterface);
        vt.addRow(hostId, "ADMINPORT", Integer.toString(adminPort));
        vt.addRow(hostId, "HTTPINTERFACE", httpInterface);
        vt.addRow(hostId, "HTTPPORT", Integer.toString(httpPort));
        vt.addRow(hostId, "INTERNALINTERFACE", internalInterface);
        vt.addRow(hostId, "INTERNALPORT", Integer.toString(internalPort));
        vt.addRow(hostId, "ZKINTERFACE", zkInterface);
        vt.addRow(hostId, "ZKPORT", Integer.toString(zkPort));
        vt.addRow(hostId, "DRINTERFACE", drInterface);
        vt.addRow(hostId, "DRPORT", Integer.toString(drPort));
        vt.addRow(hostId, "PUBLICINTERFACE", publicInterface);
        vt.addRow(hostId, DR_PUBLIC_INTF_COL, drPublicInterface);
        vt.addRow(hostId, DR_PUBLIC_PORT_COL, Integer.toString(drPublicPort));

        // build string
        vt.addRow(hostId, "BUILDSTRING", VoltDB.instance().getBuildString());

        // version
        vt.addRow(hostId, "VERSION", VoltDB.instance().getVersionString());
        // catalog path
        String path = VoltDB.instance().getConfig().m_pathToCatalog;
        if (path != null && !path.startsWith("http")) {
            path = (new File(path)).getAbsolutePath();
        }
        vt.addRow(hostId, "CATALOG", path);

        // deployment path
        path = VoltDB.instance().getConfig().m_pathToDeployment;
        if (path != null && !path.startsWith("http")) {
            path = (new File(path)).getAbsolutePath();
        }
        vt.addRow(hostId, "DEPLOYMENT", path);

        String cluster_state = VoltDB.instance().getMode().toString();
        vt.addRow(hostId, "CLUSTERSTATE", cluster_state);
        // INITIALIZED, used by VEM to determine the spinny icon state.
        org.voltdb.OperationMode mode = VoltDB.instance().getMode();
        String areInitialized = Boolean.toString(!VoltDB.instance().rejoining() &&
                (mode == org.voltdb.OperationMode.RUNNING ||
                        mode == org.voltdb.OperationMode.PAUSED));
        vt.addRow(hostId, "INITIALIZED", areInitialized);

        String replication_role = VoltDB.instance().getReplicationRole().toString();
        vt.addRow(hostId, "REPLICATIONROLE", replication_role);

        vt.addRow(hostId, "CATALOGCRC",
                Long.toString(VoltDB.instance().getCatalogContext().getCatalogCRC()));

        vt.addRow(hostId, "IV2ENABLED", "true");
        long startTimeMs = VoltDB.instance().getHostMessenger().getInstanceId().getTimestamp();
        vt.addRow(hostId, "STARTTIME", Long.toString(startTimeMs));
        vt.addRow(hostId, "UPTIME", MiscUtils.formatUptime(VoltDB.instance().getClusterUptime()));

        vt.addRow(hostId, "LAST_UPDATECORE_DURATION",
                Long.toString(VoltDB.instance().getCatalogContext().m_lastUpdateCoreDuration));

        SocketHubAppender hubAppender =
            (SocketHubAppender) Logger.getRootLogger().getAppender("hub");
        int port = 0;
        if (hubAppender != null) {
            port = hubAppender.getPort();
        }
        vt.addRow(hostId, "LOG4JPORT", Integer.toString(port));
        //Add license information
        if (MiscUtils.isPro()) {
            vt.addRow(hostId, "LICENSE", VoltDB.instance().getLicenseInformation());
        }
        populatePartitionGroups(hostId, vt);

        // root path
        vt.addRow(hostId, "VOLTDBROOT", VoltDB.instance().getVoltDBRootPath());
        vt.addRow(hostId, "FULLCLUSTERSIZE", Integer.toString(VoltDB.instance().getCatalogContext().getClusterSettings().hostcount()));
        vt.addRow(hostId, "CLUSTERID", Integer.toString(VoltDB.instance().getCatalogContext().getCluster().getDrclusterid()));
        return vt;
    }
699121
def _system(self, *args, **kwargs):
        '''
        
        '''
        sysinfo = SysInfo(__grains__.get("kernel"))

        data = dict()
        data['cpu'] = sysinfo._get_cpu()
        data['disks'] = sysinfo._get_fs()
        data['mounts'] = sysinfo._get_mounts()
        data['memory'] = sysinfo._get_mem()
        data['network'] = sysinfo._get_network()
        data['os'] = sysinfo._get_os()

        return data
1281795
def _process_data(
        self,
        data,
        collect_aggregates_only,
        process_events,
        url=None,
        collect_status_metrics=False,
        collect_status_metrics_by_host=False,
        tag_service_check_by_host=False,
        services_incl_filter=None,
        services_excl_filter=None,
        collate_status_tags_per_host=False,
        count_status_by_service=True,
        custom_tags=None,
        tags_regex=None,
        active_tag=None,
        enable_service_check=False,
    ):
        '''  '''

        # Split the first line into an index of fields
        # The line looks like (broken up onto multiple lines)
        # "# pxname,svname,qcur,qmax,scur,smax,slim,
        # stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,
        # wredis,status,weight,act,bck,chkfail,chkdown,lastchg,
        # downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,
        # type,rate,rate_lim,rate_max,"
        fields = []
        for f in data[0].split(','):
            if f:
                f = f.replace('# ', '')
                fields.append(f.strip())

        self.hosts_statuses = defaultdict(int)

        back_or_front = None

        # Sanitize CSV, handle line breaks
        data = self._sanitize_lines(data)
        custom_tags = [] if custom_tags is None else custom_tags
        active_tag = [] if active_tag is None else active_tag

        # First initialize here so that it is defined whether or not we enter the for loop
        line_tags = list(custom_tags)

        # Skip the first line, go backwards to set back_or_front
        for line in data[:0:-1]:
            if not line.strip():
                continue

            # Store each line's values in a dictionary
            data_dict = self._line_to_dict(fields, line)

            if self._is_aggregate(data_dict):
                back_or_front = data_dict['svname']

            self._update_data_dict(data_dict, back_or_front)

            self._update_hosts_statuses_if_needed(
                collect_status_metrics, collect_status_metrics_by_host, data_dict, self.hosts_statuses
            )

            # Clone the list to avoid extending the original
            # which would carry over previous iteration tags
            line_tags = list(custom_tags)

            regex_tags = self._tag_from_regex(tags_regex, data_dict['pxname'])
            if regex_tags:
                line_tags.extend(regex_tags)

            if self._should_process(data_dict, collect_aggregates_only):
                # update status
                # Send the list of data to the metric and event callbacks
                self._process_metrics(
                    data_dict,
                    url,
                    services_incl_filter=services_incl_filter,
                    services_excl_filter=services_excl_filter,
                    custom_tags=line_tags,
                    active_tag=active_tag,
                )
            if process_events:
                self._process_event(
                    data_dict,
                    url,
                    services_incl_filter=services_incl_filter,
                    services_excl_filter=services_excl_filter,
                    custom_tags=line_tags,
                )
            if enable_service_check:
                self._process_service_check(
                    data_dict,
                    url,
                    tag_by_host=tag_service_check_by_host,
                    services_incl_filter=services_incl_filter,
                    services_excl_filter=services_excl_filter,
                    custom_tags=line_tags,
                )

        if collect_status_metrics:
            self._process_status_metric(
                self.hosts_statuses,
                collect_status_metrics_by_host,
                services_incl_filter=services_incl_filter,
                services_excl_filter=services_excl_filter,
                collate_status_tags_per_host=collate_status_tags_per_host,
                count_status_by_service=count_status_by_service,
                custom_tags=line_tags,
                active_tag=active_tag,
            )

            self._process_backend_hosts_metric(
                self.hosts_statuses,
                services_incl_filter=services_incl_filter,
                services_excl_filter=services_excl_filter,
                custom_tags=line_tags,
                active_tag=active_tag,
            )

        return data
429218
def get_hosts(self):
        
        limited_hosts = {}
        if self.limit is not None:
            # Find hosts and groups of hosts to include
            for include in self.limit['include']:
                # Include whole group
                for hostname in self.hosts_in_group(include):
                    limited_hosts[hostname] = self.hosts[hostname]
                # Include individual host
                if include in self.hosts:
                    limited_hosts[include] = self.hosts[include]
            # Find hosts and groups of hosts to exclude
            for exclude in self.limit["exclude"]:
                # Exclude whole group
                for hostname in self.hosts_in_group(exclude):
                    if hostname in limited_hosts:
                        limited_hosts.pop(hostname)
                # Exclude individual host
                if exclude in limited_hosts:
                    limited_hosts.pop(exclude)

            return limited_hosts
        else:
            # Return all hosts
            return self.hosts
1044913
def _get_info(self, host, port, unix_socket, auth):
        

        client = self._client(host, port, unix_socket, auth)
        if client is None:
            return None

        info = client.info()
        del client
        return info
1468
def _increment(self, what, host):
        '''  '''

        self.processed[host] = 1
        prev = (getattr(self, what)).get(host, 0)
        getattr(self, what)[host] = prev+1
50850
def pool(self, host, port, db, pools={}, **options):
        '''
        
        '''
        key = (host, port, db)
        rval = pools.get(key)
        if not isinstance(rval, ConnectionPool):
            rval = ConnectionPool(host=host, port=port, db=db, **options)
            pools[key] = rval

        return rval
161154
def get_by_ip(cls, ip):
        ''
        ret = cls.hosts_by_ip.get(ip)
        if ret is None:
            ret = cls.hosts_by_ip[ip] = [Host(ip)]
        return ret
1288907
def sessions_info(self, hosts):
        
        info_by_id = {}

        for server_endpoint, dump in self.dump_by_server(hosts).items():
            server_ip, server_port = server_endpoint
            for line in dump.split("\n"):
                mat = self.IP_PORT_REGEX.match(line)
                if mat is None:
                    continue
                ip, port, sid = mat.groups()
                info_by_id[sid] = ClientInfo(sid, ip, port, server_ip, server_port)

        return info_by_id
1243674
def ephemerals_info(self, hosts):
        
        info_by_path, info_by_id = {}, {}

        for server_endpoint, dump in self.dump_by_server(hosts).items():
            server_ip, server_port = server_endpoint
            sid = None
            for line in dump.split("\n"):
                mat = self.SESSION_REGEX.match(line)
                if mat:
                    sid = mat.group(1)
                    continue

                mat = self.PATH_REGEX.match(line)
                if mat:
                    info = info_by_id.get(sid, None)
                    if info is None:
                        info = info_by_id[sid] = ClientInfo(sid)
                    info_by_path[mat.group(1)] = info
                    continue

                mat = self.IP_PORT_REGEX.match(line)
                if mat:
                    ip, port, sid = mat.groups()
                    if sid not in info_by_id:
                        continue
                    info_by_id[sid](ip, int(port), server_ip, server_port)

        return info_by_path
795668
def show_table(name, table, i, total):
    
    return '[%d/%d, %s] %s' % (i+1, total, table.__appname__, name)
838672
def count(self) -> int:
        ''''''
        counter = 0

        for pool in self._host_pools.values():
            counter += pool.count()

        return counter
824490
def gather_data(registry):
    """"""

    # Get the host name of the machine
    host = socket.gethostname()

    # Create our collectors
    ram_metric = Gauge("memory_usage_bytes", "Memory usage in bytes.",
                       {'host': host})
    cpu_metric = Gauge("cpu_usage_percent", "CPU usage percent.",
                       {'host': host})

    # register the metric collectors
    registry.register(ram_metric)
    registry.register(cpu_metric)

    # Start gathering metrics every second
    while True:
        time.sleep(1)

        # Add ram metrics
        ram = psutil.virtual_memory()
        swap = psutil.swap_memory()

        ram_metric.set({'type': "virtual", }, ram.used)
        ram_metric.set({'type': "virtual", 'status': "cached"}, ram.cached)
        ram_metric.set({'type': "swap"}, swap.used)

        # Add cpu metrics
        for c, p in enumerate(psutil.cpu_percent(interval=1, percpu=True)):
            cpu_metric.set({'core': c}, p)
491466
def dump_by_server(self, hosts):
        
        dump_by_endpoint = {}

        for endpoint in self._to_endpoints(hosts):
            try:
                out = self.cmd([endpoint], "dump")
            except self.CmdFailed as ex:
                out = ""
            dump_by_endpoint[endpoint] = out

        return dump_by_endpoint
63325
def hosting_history(self, query, **kwargs):
        """"""
        return self._results('hosting-history', '/v1/{0}/hosting-history'.format(query), cls=GroupedIterable, **kwargs)
989924
def _get_sz_info(self):
        
        if 'None' == self._state:
            return None

        cmd = 'show virtual-service detail name guestshell+'
        got = self.cli(cmd)
        got = got['TABLE_detail']['ROW_detail']

        sz_cpu = int(got['cpu_reservation'])
        sz_disk = int(got['disk_reservation'])
        sz_memory = int(got['memory_reservation'])

        self.sz_has = _guestshell.Resources(
            cpu=sz_cpu, memory=sz_memory, disk=sz_disk)
827575
def linkify_es_by_h(self, hosts):
        
        for escal in self:
            # If no host, no hope of having a service
            if (not hasattr(escal, 'host_name') or escal.host_name.strip() == '' or
                    (hasattr(escal, 'service_description')
                     and escal.service_description.strip() != '')):
                continue
            # I must be NOT a escalation on for service
            for hname in strip_and_uniq(escal.host_name.split(',')):
                host = hosts.find_by_name(hname)
                if host is not None:
                    host.escalations.append(escal.uuid)