/* returns last known location of metrics cache
550537
private synchronized String getCacheLocation() {
    if (metricsCacheLocation != null) {
      return metricsCacheLocation;
    }

    MetricsCacheLocation cacheLocation = stateManagerAdaptor.getMetricsCacheLocation(topologyName);
    metricsCacheLocation = String.format("http://%s:%s/%s", cacheLocation.getHost(),
        cacheLocation.getStatsPort(), PATH_STATS);
    return metricsCacheLocation;
  }
1075182
private static String getMasterMetricName(String name) {
    String result = CACHED_METRICS.get(name);
    if (result != null) {
      return result;
    }
    return CACHED_METRICS.computeIfAbsent(name, n -> InstanceType.MASTER.toString() + "." + name);
  }
42485
private List<Long> collectLongMetric(String metricGetterName) {
        List<Long> vals = new ArrayList<Long>();
        for(BdbEnvironmentStats envStats: environmentStatsTracked) {
            vals.add((Long) ReflectUtils.callMethod(envStats,
                                                    BdbEnvironmentStats.class,
                                                    metricGetterName,
                                                    new Class<?>[0],
                                                    new Object[0]));
        }
        return vals;
    }
1163713
@JmxGetter(name = "lastSwapped", description = "Time in milliseconds since the store was swapped")
    public long getLastSwapped() {
        long timeSinceLastSwap = System.currentTimeMillis() - lastSwapped;
        return timeSinceLastSwap > 0 ? timeSinceLastSwap : 0;
    }
649972
private double getMetricSampleCountValue(final String metricName) {
        int min = 0;
        int max = 1;

        if (metricName.equals(Constants.CPU_UTILIZATION)) {
            min = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.CPU_UTILIZATION_RANGE_SAMPLECOUNT)
                                    .split(",")[0]);
            max = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.CPU_UTILIZATION_RANGE_SAMPLECOUNT)
                                    .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_READ_BYTES)) {
            min = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.DISK_READ_BYTES_RANGE_SAMPLECOUNT)
                                    .split(",")[0]);
            max = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.DISK_READ_BYTES_RANGE_SAMPLECOUNT)
                                    .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_READ_OPS)) {
            min = Integer
                    .parseInt(PropertiesUtils.getProperty(Constants.DISK_READ_OPS_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils.getProperty(Constants.DISK_READ_OPS_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_WRITE_BYTES)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_BYTES_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_BYTES_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.DISK_WRITE_OPS)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_OPS_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.DISK_WRITE_OPS_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_IN)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_IN_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_IN_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_OUT)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_OUT_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_OUT_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_PACKETS_IN)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_IN_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_IN_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_PACKETS_OUT)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_OUT_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_OUT_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED_INSTANCE)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.STATUS_CHECK_FAILED_INSTANCE_RANGE_SAMPLECOUNT)
                    .split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.STATUS_CHECK_FAILED_INSTANCE_RANGE_SAMPLECOUNT)
                    .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED_SYSTEM)) {
            min = Integer.parseInt(
                    PropertiesUtils
                            .getProperty(Constants.STATUS_CHECK_FAILED_SYSTEM_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils
                            .getProperty(Constants.STATUS_CHECK_FAILED_SYSTEM_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.CPU_CREDIT_USAGE)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.CPU_CREDIT_USAGE_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.CPU_CREDIT_USAGE_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.ESTIMATED_CHARGES)) {
            min = Integer.parseInt(PropertiesUtils.getProperty(
                    Constants.ESTIMATED_CHARGES_RANGE_SAMPLECOUNT).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils.getProperty(
                    Constants.ESTIMATED_CHARGES_RANGE_SAMPLECOUNT).split(",")[1]);
        } else if (metricName.equals(Constants.CPU_CREDIT_BALANCE)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.CPU_CREDIT_BALANCE_RANGE_SAMPLECOUNT)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.CPU_CREDIT_BALANCE_RANGE_SAMPLECOUNT)
                            .split(",")[1]);
        }

        return new Random().nextInt((max - min) + 1) + min;
    }
1272172
@Override
    public String[] getAllCacheStatistics() {
        DCache cache = null;
        if (ServerCache.servletCacheEnabled) {
            cache = ServerCache.cache;
        }
        String stats[] = null;
        if (cache != null) {
            Map statistics = getCacheStatisticsMap(cache.getCacheStatistics());
            Iterator keys = statistics.keySet().iterator();
            Iterator values = statistics.values().iterator();
            stats = new String[statistics.size()];
            int i = 0;
            while (keys.hasNext()) {
                stats[i] = keys.next() + "=" + values.next();
                i++;
            }
        } else {
            stats = new String[0];
            // DYNA1059W=DYNA1059W: WebSphere Dynamic Cache instance named {0} cannot be used because of Dynamic Servlet cache service has not be started.
            Tr.error(tc, "DYNA1059W", new Object[] { DCacheBase.DEFAULT_CACHE_NAME });
        }

        return stats;
    }
566285
def log(self, name, val, **tags):
        """"""
        global _last_timestamp, _last_metrics

        # do not allow .log after closing
        assert not self.done.is_set(), "worker thread has been closed"
        # check if valid metric name
        assert all(c in _valid_metric_chars for c in name), "invalid metric name " + name

        val = float(val)  #Duck type to float/int, if possible.
        if int(val) == val:
            val = int(val)

        if self.host_tag and 'host' not in tags:
            tags['host'] = self.host_tag

        # get timestamp from system time, unless it's supplied as a tag
        timestamp = int(tags.pop('timestamp', time.time()))

        assert not self.done.is_set(), "tsdb object has been closed"
        assert tags != {}, "Need at least one tag"

        tagvals = ' '.join(['%s=%s' % (k, v) for k, v in tags.items()])

        # OpenTSDB has major problems if you insert a data point with the same
        # metric, timestamp and tags. So we keep a temporary set of what points
        # we have sent for the last timestamp value. If we encounter a duplicate,
        # it is dropped.
        unique_str = "%s, %s, %s, %s, %s" % (name, timestamp, tagvals, self.host, self.port)
        if timestamp == _last_timestamp or _last_timestamp == None:
            if unique_str in _last_metrics:
                return  # discard duplicate metrics
            else:
                _last_metrics.add(unique_str)
        else:
            _last_timestamp = timestamp
            _last_metrics.clear()

        line = "put %s %d %s %s\n" % (name, timestamp, val, tagvals)

        try:
            self.q.put(line, False)
            self.queued += 1
        except queue.Full:
            print("potsdb - Warning: dropping oldest metric because Queue is full. Size: %s" % self.q.qsize(), file=sys.stderr)
            self.q.get()  #Drop the oldest metric to make room
            self.q.put(line, False)
        return line
927721
private InMemoryMetricEmitter extractInMemoryMetricEmitter(
      final MetricReportManager metricManager) {
    InMemoryMetricEmitter memoryEmitter = null;
    for (final IMetricEmitter emitter : metricManager.getMetricEmitters()) {
      if (emitter instanceof InMemoryMetricEmitter) {
        memoryEmitter = (InMemoryMetricEmitter) emitter;
        break;
      }
    }
    return memoryEmitter;
  }
736968
def transmit_metrics(self):
        
        global _last_stats_transmit_time  # pylint: disable=global-statement
        with _STATS_LOCK:  # pylint: disable=not-context-manager
            if time.monotonic() - _last_stats_transmit_time < 10.0:
                return

            for site in self.state:
                for filetype, prop in self.state[site]["upload"].items():
                    if prop["last_success"]:
                        self.metrics.gauge(
                            "pghoard.last_upload_age",
                            time.monotonic() - prop["last_success"],
                            tags={
                                "site": site,
                                "type": filetype,
                            }
                        )
            _last_stats_transmit_time = time.monotonic()
1176315
function getLastLocationInTag(node) {
            const tagClose = node.tagClose
            const text = sourceCode.text.slice(node.range[0], tagClose.range[0])
            const index = text.search(/\S\s*$/gu) + node.range[0] + 1
            return {
                index,
                loc: sourceCode.getLocFromIndex(index),
            }
        }
700856
private Optional<DurationThresholdTracker> requestDurationThresholdTracker(MetricId id,
                                                                             String endpoint) {
    return durationThresholdConfig.getDurationThresholdForEndpoint(endpoint)
        .map(threshold -> Optional.of(new DurationThresholdTracker(id, metricRegistry, threshold)))
        .orElse(Optional.empty());
  }
441768
public String getReason() {
        if (lastExceededValue) {
            return String.format("Metric '%s' has aggregated-value=%d %s %d as threshold", metric.name(), lastAggregatedValue, operator.symbol, thresholdValue);
        } else {
            return String.format("Metric %s: aggregated-value=%d", metric.name(), lastAggregatedValue);
        }
    }
318074
def __get_metrics(self):
        
        esfilters_closed = None
        esfilters_opened = None
        if self.esfilters:
            esfilters_closed = self.esfilters.copy()
            esfilters_opened = self.esfilters.copy()

        closed = self.closed_class(self.es_url, self.es_index,
                                   start=self.start, end=self.end,
                                   esfilters=esfilters_closed, interval=self.interval)
        opened = self.opened_class(self.es_url, self.es_index,
                                   start=self.start, end=self.end,
                                   esfilters=esfilters_opened, interval=self.interval)
        return (closed, opened)
1092141
public TopologyMaster.MetricResponse getMetrics(TopologyMaster.MetricRequest request) {
    String componentName = request.getComponentName();
    if (!cache.componentInstanceExists(componentName, null)) {
      return buildResponseNotOk(
          String.format("Unknown component %s found in MetricRequest %s", componentName, request)
      ).build();
    }
    if (request.getInstanceIdCount() > 0) {
      for (String instanceId : request.getInstanceIdList()) {
        if (!cache.componentInstanceExists(componentName, instanceId)) {
          return buildResponseNotOk(
              String.format("Unknown instance %s found in MetricRequest %s", instanceId, request)
          ).build();
        }
      }
    }
    if (!request.hasInterval() && !request.hasExplicitInterval()) {
      return buildResponseNotOk("No purgeIntervalSec or explicit purgeIntervalSec set").build();
    }

    MetricRequest request1 = MetricsCacheQueryUtils.fromProtobuf(request);
    MetricResponse response1 = cache.getMetrics(request1, metricNameType);
    TopologyMaster.MetricResponse response = MetricsCacheQueryUtils.toProtobuf(response1, request1);
    return response;
  }
808128
public static Checkpoint lastCheckpoint(File rootDir){
        List<Checkpoint> all = availableCheckpoints(rootDir);
        if(all.isEmpty()){
            return null;
        }
        return all.get(all.size()-1);
    }
876464
public boolean deleteMetricAsync(String metricName)
      throws ExecutionException, InterruptedException {
    // [START deleteMetricAsync]
    Future<Boolean> future = logging.deleteMetricAsync(metricName);
    // ...
    boolean deleted = future.get();
    if (deleted) {
      // the metric was deleted
    } else {
      // the metric was not found
    }
    // [END deleteMetricAsync]
    return deleted;
  }
84066
private double getMetricAverageValue(final String metricName) {
        int min = 0;
        int max = 1;

        if (metricName.equals(Constants.CPU_UTILIZATION)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.CPU_UTILIZATION_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.CPU_UTILIZATION_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.DISK_READ_BYTES)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_READ_BYTES_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_READ_BYTES_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.DISK_READ_OPS)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_READ_OPS_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_READ_OPS_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.DISK_WRITE_BYTES)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_WRITE_BYTES_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_WRITE_BYTES_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.DISK_WRITE_OPS)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_WRITE_OPS_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.DISK_WRITE_OPS_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_IN)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_IN_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_IN_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_OUT)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_OUT_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.NETWORK_OUT_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_PACKETS_IN)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.NETWORK_PACKETS_IN_RANGE_AVERAGE).split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.NETWORK_PACKETS_IN_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.NETWORK_PACKETS_OUT)) {
            min = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_OUT_RANGE_AVERAGE)
                                    .split(",")[0]);
            max = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.NETWORK_PACKETS_OUT_RANGE_AVERAGE)
                                    .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED)) {
            min = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_RANGE_AVERAGE)
                                    .split(",")[0]);
            max = Integer
                    .parseInt(
                            PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_RANGE_AVERAGE)
                                    .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED_INSTANCE)) {
            min = Integer.parseInt(
                    PropertiesUtils
                            .getProperty(Constants.STATUS_CHECK_FAILED_INSTANCE_RANGE_AVERAGE)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils
                            .getProperty(Constants.STATUS_CHECK_FAILED_INSTANCE_RANGE_AVERAGE)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.STATUS_CHECK_FAILED_SYSTEM)) {
            min = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_SYSTEM_RANGE_AVERAGE)
                            .split(",")[0]);
            max = Integer.parseInt(
                    PropertiesUtils.getProperty(Constants.STATUS_CHECK_FAILED_SYSTEM_RANGE_AVERAGE)
                            .split(",")[1]);
        } else if (metricName.equals(Constants.CPU_CREDIT_USAGE)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.CPU_CREDIT_USAGE_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.CPU_CREDIT_USAGE_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.ESTIMATED_CHARGES)) {
            min = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.ESTIMATED_CHARGES_RANGE_AVERAGE).split(",")[0]);
            max = Integer.parseInt(PropertiesUtils
                    .getProperty(Constants.ESTIMATED_CHARGES_RANGE_AVERAGE).split(",")[1]);
        } else if (metricName.equals(Constants.CPU_CREDIT_BALANCE)) {
            min = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.CPU_CREDIT_BALANCE_RANGE_AVERAGE).split(",")[0]);
            max = Integer
                    .parseInt(PropertiesUtils
                            .getProperty(Constants.CPU_CREDIT_BALANCE_RANGE_AVERAGE).split(",")[1]);
        }

        return new Random().nextInt((max - min) + 1) + min;
    }