Get important performance data and metadata from rTorrent.
19235
def engine_data(engine):
    
    views = ("default", "main", "started", "stopped", "complete",
             "incomplete", "seeding", "leeching", "active", "messages")
    methods = [
        "throttle.global_up.rate", "throttle.global_up.max_rate",
        "throttle.global_down.rate", "throttle.global_down.max_rate",
    ]

    # Get data via multicall
    proxy = engine.open()
    calls = [dict(methodName=method, params=[]) for method in methods] \
          + [dict(methodName="view.size", params=['', view]) for view in views]
    result = proxy.system.multicall(calls, flatten=True)

    # Build result object
    data = dict(
        now         = time.time(),
        engine_id   = engine.engine_id,
        versions    = engine.versions,
        uptime      = engine.uptime,
        upload      = [result[0], result[1]],
        download    = [result[2], result[3]],
        views       = dict([(name, result[4+i])
            for i, name in enumerate(views)
        ]),
    )

    return data
88607
def get_data(context, resource, **kwargs):
    """"""

    url_suffix = ''
    if 'keys' in kwargs and kwargs['keys']:
        url_suffix = '/?keys=%s' % ','.join(kwargs.pop('keys'))

    uri = '%s/%s/%s/data%s' % (context.dci_cs_api, resource,
                               kwargs.pop('id'), url_suffix)

    r = context.session.get(uri, timeout=HTTP_TIMEOUT, params=kwargs)
    return r
138722
def get_requests(self):
        
        self.download_list = []
        for data_name in [band for band in self.bands if self._band_exists(band)] + self.metafiles:
            if data_name in AwsConstants.TILE_FILES:
                url = self.get_url(data_name)
                filename = self.get_filepath(data_name)
                self.download_list.append(DownloadRequest(url=url, filename=filename,
                                                          data_type=AwsConstants.AWS_FILES[data_name],
                                                          data_name=data_name))
        self.sort_download_list()
        return self.download_list, self.folder_list
630436
def metrics(self):
        
        masterThrp, backupThrp = self.getThroughputs(self.instances.masterId)
        r = self.instance_throughput_ratio(self.instances.masterId)
        m = [
            ("{} Monitor metrics:".format(self), None),
            ("Delta", self.Delta),
            ("Lambda", self.Lambda),
            ("Omega", self.Omega),
            ("instances started", self.instances.started),
            ("ordered request counts",
             {i: r[0] for i, r in self.numOrderedRequests.items()}),
            ("ordered request durations",
             {i: r[1] for i, r in self.numOrderedRequests.items()}),
            ("master request latencies", self.masterReqLatencies),
            ("client avg request latencies", {i: self.getLatency(i)
                                              for i in self.instances.ids}),
            ("throughput", {i: self.getThroughput(i)
                            for i in self.instances.ids}),
            ("master throughput", masterThrp),
            ("total requests", self.totalRequests),
            ("avg backup throughput", backupThrp),
            ("master throughput ratio", r)]
        return m
444094
def initTorrent(torrentData)
      # If we already have the metainfo info for this torrent, we can begin checking the pieces. 
      # If we don't have the metainfo info then we need to get the metainfo first.
      if ! torrentData.info
        torrentData.info = MetainfoPieceState.downloaded(@baseDirectory, torrentData.infoHash)
      end

      if torrentData.info
        startCheckingPieces torrentData
      else
        # Request the metainfo from peers.
        torrentData.state = :downloading_metainfo

        @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Downloading metainfo"

        # Schedule peer connection management. Recurring and immediate 
        torrentData.managePeersTimer = 
          @reactor.scheduleTimer(@managePeersPeriod, [:manage_peers, torrentData.infoHash], true, true)

        # Schedule a timer for requesting metadata pieces from peers.
        torrentData.metainfoRequestTimer = 
          @reactor.scheduleTimer(@requestBlocksPeriod, [:request_metadata_pieces, torrentData.infoHash], true, false)

        # Schedule checking for metainfo PieceManager results (including when piece reading completes)
        torrentData.checkMetadataPieceManagerTimer =
          @reactor.scheduleTimer(@requestBlocksPeriod, [:check_metadata_piece_manager, torrentData.infoHash], true, false)
      end
    end
731646
def collect_metrics(self):
        
        try:
            g = None
            u = resource.getrusage(resource.RUSAGE_SELF)
            if gc_.isenabled():
                c = list(gc_.get_count())
                th = list(gc_.get_threshold())
                g = GC(collect0=c[0] if not self.last_collect else c[0] - self.last_collect[0],
                       collect1=c[1] if not self.last_collect else c[
                           1] - self.last_collect[1],
                       collect2=c[2] if not self.last_collect else c[
                           2] - self.last_collect[2],
                       threshold0=th[0],
                       threshold1=th[1],
                       threshold2=th[2])

            thr = threading.enumerate()
            daemon_threads = [tr.daemon is True for tr in thr].count(True)
            alive_threads = [tr.daemon is False for tr in thr].count(True)
            dummy_threads = [type(tr) is threading._DummyThread for tr in thr].count(True)

            m = Metrics(ru_utime=u[0] if not self.last_usage else u[0] - self.last_usage[0],
                        ru_stime=u[1] if not self.last_usage else u[1] - self.last_usage[1],
                        ru_maxrss=u[2],
                        ru_ixrss=u[3],
                        ru_idrss=u[4],
                        ru_isrss=u[5],
                        ru_minflt=u[6] if not self.last_usage else u[6] - self.last_usage[6],
                        ru_majflt=u[7] if not self.last_usage else u[7] - self.last_usage[7],
                        ru_nswap=u[8] if not self.last_usage else u[8] - self.last_usage[8],
                        ru_inblock=u[9] if not self.last_usage else u[9] - self.last_usage[9],
                        ru_oublock=u[10] if not self.last_usage else u[10] - self.last_usage[10],
                        ru_msgsnd=u[11] if not self.last_usage else u[11] - self.last_usage[11],
                        ru_msgrcv=u[12] if not self.last_usage else u[12] - self.last_usage[12],
                        ru_nsignals=u[13] if not self.last_usage else u[13] - self.last_usage[13],
                        ru_nvcs=u[14] if not self.last_usage else u[14] - self.last_usage[14],
                        ru_nivcsw=u[15] if not self.last_usage else u[15] - self.last_usage[15],
                        alive_threads=alive_threads,
                        dummy_threads=dummy_threads,
                        daemon_threads=daemon_threads,
                        gc=g)

            self.last_usage = u
            if gc_.isenabled():
                self.last_collect = c

            return m
        except:
            logger.debug("collect_metrics", exc_info=True)
974878
def getMeta(self, uri):
        """"""

        action = urlparse(uri).path

        mediaKey = self.cacheKey + '_meta_' + action
        mediaKey = mediaKey.replace(' ', '__')

        meta = cache.get(mediaKey, None)

        # Nothing found -> Retrieve it from the server and cache it
        if not meta:

            r = self.doQuery('meta/' + uri)

            if r.status_code == 200:  # Get the content if there is not problem. If there is, template will stay to None
                meta = r.json()

            if 'expire' not in r.headers:
                expire = 5 * 60  # 5 minutes of cache if the server didn't specified anything
            else:
                expire = int((parser.parse(r.headers['expire']) - datetime.datetime.now(tzutc())).total_seconds())  # Use the server value for cache

            if expire > 0:  # Do the server want us to cache ?
                cache.set(mediaKey, meta, expire)

        return meta
263933
async def getStats(self):
        
        self.__stats.add(RTCOutboundRtpStreamStats(
            # RTCStats
            timestamp=clock.current_datetime(),
            type='outbound-rtp',
            id='outbound-rtp_' + str(id(self)),
            # RTCStreamStats
            ssrc=self._ssrc,
            kind=self.__kind,
            transportId=self.transport._stats_id,
            # RTCSentRtpStreamStats
            packetsSent=self.__packet_count,
            bytesSent=self.__octet_count,
            # RTCOutboundRtpStreamStats
            trackId=str(id(self.track)),
        ))
        self.__stats.update(self.transport._get_stats())

        return self.__stats
306574
def ReadHuntClientResourcesStats(self, hunt_id):
    """"""

    result = rdf_stats.ClientResourcesStats()
    for f in self._GetHuntFlows(hunt_id):
      cr = rdf_client_stats.ClientResources(
          session_id="%s/%s" % (f.client_id, f.flow_id),
          client_id=f.client_id,
          cpu_usage=f.cpu_time_used,
          network_bytes_sent=f.network_bytes_sent)
      result.RegisterResources(cr)

    # TODO(user): remove this hack when compatibility with AFF4 is not
    # important.
    return rdf_stats.ClientResourcesStats.FromSerializedString(
        result.SerializeToString())
702762
def to_h
      result = {}

      ## Extra fields added by this method:
      # Length of the torrent
      result[:dataLength] = @info ? @info.dataLength : 0
      # Percent complete
      pct = withCurrentAndTotalBytes{ |cur, total| (cur.to_f / total.to_f * 100.0).round 1 }
      result[:percentComplete] = pct
      # Time left
      secondsLeft = withCurrentAndTotalBytes do |cur, total|
        if @downloadRateDataOnly && @downloadRateDataOnly > 0
          (total.to_f - cur.to_f) / @downloadRateDataOnly 
        else
          0
        end
      end
      # Cap estimated time at 9999 hours
      secondsLeft = 35996400 if secondsLeft > 35996400
      result[:timeLeft] = Formatter.formatTime(secondsLeft)

      ## Regular fields
      result[:info] = @info ? @info.to_h : nil
      result[:infoHash] = @infoHash
      result[:recommendedName] = @recommendedName
      result[:downloadRate] = @downloadRate
      result[:uploadRate] = @uploadRate
      result[:downloadRateDataOnly] = @downloadRateDataOnly
      result[:uploadRateDataOnly] = @uploadRateDataOnly
      result[:completedBytes] = @completedBytes
      result[:peers] = @peers.collect{ |p| p.to_h }
      result[:state] = @state
      #result[:completePieceBitfield] = @completePieceBitfield
      result[:metainfoLength] = @metainfoLength
      result[:metainfoCompletedLength] = @metainfoCompletedLength
      result[:paused] = @paused
      result[:queued] = @queued
      result[:uploadRateLimit] = @uploadRateLimit
      result[:downloadRateLimit] = @downloadRateLimit
      result[:ratio] = @ratio
      result[:uploadDuration] = @uploadDuration
      result[:bytesUploaded] = @bytesUploaded
      result[:bytesDownloaded] = @bytesDownloaded
      result[:alarms] = @alarms.collect{ |a| a.to_h }

      result
    end
1132397
def GetMetadata(client_id, client_full_info):
  """"""

  metadata = ExportedMetadata()

  last_snapshot = None
  if client_full_info.HasField("last_snapshot"):
    last_snapshot = client_full_info.last_snapshot

  metadata.client_urn = client_id
  metadata.client_age = client_full_info.metadata.first_seen

  if last_snapshot is not None:
    kb = client_full_info.last_snapshot.knowledge_base

    metadata.hostname = kb.fqdn
    metadata.os = kb.os
    metadata.uname = last_snapshot.Uname()
    metadata.os_release = last_snapshot.os_release
    metadata.os_version = last_snapshot.os_version
    metadata.usernames = ",".join(user.username for user in kb.users)

    addresses = last_snapshot.GetMacAddresses()
    if addresses:
      metadata.mac_address = last_snapshot.GetMacAddresses().pop()
    metadata.hardware_info = last_snapshot.hardware_info
    metadata.kernel_version = last_snapshot.kernel

    ci = last_snapshot.cloud_instance
    if ci is not None:
      if ci.cloud_type == ci.InstanceType.AMAZON:
        metadata.cloud_instance_type = metadata.CloudInstanceType.AMAZON
        metadata.cloud_instance_id = ci.amazon.instance_id
      elif ci.cloud_type == ci.InstanceType.GOOGLE:
        metadata.cloud_instance_type = metadata.CloudInstanceType.GOOGLE
        metadata.cloud_instance_id = ci.google.unique_id

  system_labels = set()
  user_labels = set()
  for l in client_full_info.labels:
    if l.owner == "GRR":
      system_labels.add(l.name)
    else:
      user_labels.add(l.name)

  metadata.labels = ",".join(sorted(system_labels | user_labels))
  metadata.system_labels = ",".join(sorted(system_labels))
  metadata.user_labels = ",".join(sorted(user_labels))

  return metadata
978794
def get_stats(self, service_id, stat_type=FastlyStatsType.ALL):
		""""""
		content = self._fetch("/service/%s/stats/%s" % (service_id, stat_type))
		return content
787203
def gather_data(registry):
    """"""

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

    # Create our collectors
    trig_metric = Gauge("trigonometry_example",
                        "Various trigonometry examples.",
                        {'host': host})

    # register the metric collectors
    registry.register(trig_metric)

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

        sine = math.sin(math.radians(counter % 360))
        cosine = math.cos(math.radians(counter % 360))
        trig_metric.set({'type': "sine"}, sine)
        trig_metric.set({'type': "cosine"}, cosine)

        counter += 1
539587
def get_data(conn_objs, providers):
    """"""
    cld_svc_map = {"aws": nodes_aws,
                   "azure": nodes_az,
                   "gcp": nodes_gcp,
                   "alicloud": nodes_ali}
    sys.stdout.write("\rCollecting Info:  ")
    sys.stdout.flush()
    busy_obj = busy_disp_on()
    collec_fn = [[cld_svc_map[x.rstrip('1234567890')], conn_objs[x]]
                 for x in providers]
    ngroup = Group()
    node_list = []
    node_list = ngroup.map(get_nodes, collec_fn)
    ngroup.join()
    busy_disp_off(dobj=busy_obj)
    sys.stdout.write("\r                                                 \r")
    sys.stdout.write("\033[?25h")  # cursor back on
    sys.stdout.flush()
    return node_list
507955
def retrieveVals(self):
        """"""
        apacheInfo = ApacheInfo(self._host, self._port,
                                self._user, self._password, 
                                self._statuspath, self._ssl)
        stats = apacheInfo.getServerStats()
        if self.hasGraph('apache_access'):
            self.setGraphVal('apache_access', 'reqs', stats['Total Accesses'])
        if self.hasGraph('apache_bytes'):
            self.setGraphVal('apache_bytes', 'bytes', 
                             stats['Total kBytes'] * 1000)
        if self.hasGraph('apache_workers'):
            self.setGraphVal('apache_workers', 'busy', stats['BusyWorkers'])
            self.setGraphVal('apache_workers', 'idle', stats['IdleWorkers'])
            self.setGraphVal('apache_workers', 'max', stats['MaxWorkers'])
1317927
def get_conn_info(self):
        """"""
        return session.ConnectionInfo(self.request.remote_ip,
                                      self.request.cookies,
                                      self.request.arguments,
                                      self.request.headers,
                                      self.request.path)
766726
def http_meta_data(self):
        """"""

        # For each flow process the contents
        for flow in self.input_stream:

            # Client to Server
            if flow['direction'] == 'CTS':
                try:
                    request = dpkt.http.Request(flow['payload'])
                    request_data = data_utils.make_dict(request)
                    request_data['uri'] = self._clean_uri(request['uri'])
                    flow['http'] = {'type':'HTTP_REQUEST', 'data':request_data}
                except (dpkt.dpkt.NeedData, dpkt.dpkt.UnpackError):
                    flow['http'] = None

            # Server to Client
            else:
                try:
                    response = dpkt.http.Response(flow['payload'])
                    flow['http'] = {'type': 'HTTP_RESPONSE', 'data': data_utils.make_dict(response)}
                except (dpkt.dpkt.NeedData, dpkt.dpkt.UnpackError):
                    flow['http'] = None

            # Mark non-TCP HTTP
            if flow['http'] and flow['protocol'] != 'TCP':
                flow['http'].update({'weird': 'UDP-HTTP'})

            # All done
            yield flow