Export gauge as a prometheus gauge.
425700
MetricFamilySamples fromGauge(String dropwizardName, Gauge gauge) {
        Object obj = gauge.getValue();
        double value;
        if (obj instanceof Number) {
            value = ((Number) obj).doubleValue();
        } else if (obj instanceof Boolean) {
            value = ((Boolean) obj) ? 1 : 0;
        } else {
            LOGGER.log(Level.FINE, String.format("Invalid type for Gauge %s: %s", sanitizeMetricName(dropwizardName),
                    obj == null ? "null" : obj.getClass().getName()));
            return null;
        }
        MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "",
                new ArrayList<String>(), new ArrayList<String>(), value);
        return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, gauge), Arrays.asList(sample));
    }
581830
public static Stream<PrometheusMetric> filteredMetrics(PullProcessorPipeline registry) throws Exception {
        Stream <PrometheusMetric> m = registry.get().stream()
                .flatMap((TimeSeriesValue i) -> {
                    Map<MetricName, MetricValue> metrics = i.getMetrics();
                    GroupName group = i.getGroup();
                    return metrics.entrySet().stream()
                            .filter((kv) -> kv.getValue().value().isPresent())
                            .map((kv) -> {
                                final String metric_group = toPrometheusString_(group.getPath().getPath());
                                final Map<String, String> tags = group.getTags().stream()
                                        .filter(tag -> tag.getValue().asString().isPresent())
                                        .collect(Collectors.toMap(
                                                tag -> escapeprometheus(tag.getKey()),
                                                tag -> escapeLabelValue_(tag.getValue().asString().get())));
                                final String metric_name = toPrometheusString_(kv.getKey().getPath());
                                final Number metric_value = kv.getValue().value().get();
                                return new PrometheusMetric(metric_group, tags, metric_name, metric_value);
                            });
                }
1255372
def gauge(self, slug, current_value):
        
        k = self._gauge_key(slug)
        self.r.sadd(self._gauge_slugs_key, slug)  # keep track of all Gauges
        self.r.set(k, current_value)
1098476
static OcAgentMetricsServiceExportRpcHandler create(MetricsServiceStub stub) {
    OcAgentMetricsServiceExportRpcHandler exportRpcHandler =
        new OcAgentMetricsServiceExportRpcHandler();
    ExportResponseObserver exportResponseObserver = new ExportResponseObserver(exportRpcHandler);
    try {
      StreamObserver<ExportMetricsServiceRequest> exportRequestObserver =
          stub.export(exportResponseObserver);
      exportRpcHandler.setExportRequestObserver(exportRequestObserver);
    } catch (StatusRuntimeException e) {
      exportRpcHandler.onComplete(e);
    }
    return exportRpcHandler;
  }
440172
Stream<DynatraceCustomMetric> writeMeter(Meter meter) {
        final long wallTime = clock.wallTime();
        return StreamSupport.stream(meter.measure().spliterator(), false)
                .map(Measurement::getValue)
                .filter(Double::isFinite)
                .map(value -> createCustomMetric(meter.getId(), wallTime, value));
    }
1131066
function Metric(key, value, ts) {
  var m = this;
  this.key = key;
  this.value = value;
  this.ts = ts;

  // return a string representation of this metric appropriate 
  // for sending to the graphite collector. does not include
  // a trailing newline.
  this.toText = function() {
    return m.key + " " + m.value + " " + m.ts;
  };

  this.toPickle = function() {
    return MARK + STRING + '\'' + m.key + '\'\n' + MARK + LONG + m.ts + 'L\n' + STRING + '\'' + m.value + '\'\n' + TUPLE + TUPLE + APPEND;
  };
}
554021
def create_from_flux(cls, params, emin, emax, flux, scale=1.0):
        """"""
        params = params.copy()
        params[0] = 1.0
        params[0] = flux / cls.eval_flux(emin, emax, params, scale=scale)
        return cls(params, scale)
472231
def collect(self):
        """"""
        def traverse(d, metric_name=''):
            """
            Traverse the given nested dict using depth-first search.

            If a value is reached it will be published with a metric name
            consisting of the hierarchically concatenated keys
            of its branch.
            """
            for key, value in d.iteritems():
                if isinstance(value, dict):
                    if metric_name == '':
                        metric_name_next = key
                    else:
                        metric_name_next = metric_name + '.' + key
                    traverse(value, metric_name_next)
                else:
                    metric_name_finished = metric_name + '.' + key
                    self.publish_gauge(
                        name=metric_name_finished,
                        value=value,
                        precision=1
                    )

        md_state = self._parse_mdstat()

        traverse(md_state, '')
734735
def _send_picklemetrics(metrics):
    '''
    
    '''

    metrics = [(metric_name, (timestamp, value))
               for (metric_name, value, timestamp) in metrics]

    data = cPickle.dumps(metrics, -1)
    payload = struct.pack(b'!L', len(data)) + data

    return payload
481955
def get_context_data(self, **kwargs):
        """"""
        data = super(GaugesView, self).get_context_data(**kwargs)
        data.update({'gauges': get_r().gauge_slugs()})
        return data
689355
private GaugeMetricFamily fromGauge(List<Map.Entry<MetricName, Gauge>> gaugesWithSameName) {
		final Map.Entry<MetricName, Gauge> first = gaugesWithSameName.get(0);
		final MetricName firstName = first.getKey();
		final GaugeMetricFamily gaugeMetricFamily = new GaugeMetricFamily(firstName.getName(), getHelpMessage(first.getKey(), first.getValue()), first.getKey().getTagKeys());
		for (Map.Entry<MetricName, Gauge> entry : gaugesWithSameName) {
			gaugeMetricFamily.addMetric(entry.getKey().getTagValues(), getDoubleFromGauge(entry.getValue()));
		}
		return gaugeMetricFamily;
	}
837919
def export_module_spec_with_checkpoint(module_spec,
                                       checkpoint_path,
                                       export_path,
                                       scope_prefix=""):
  """"""

  # The main requirement is that it is possible to know how to map from
  # module variable name to checkpoint variable name.
  # This is trivial if the original code used variable scopes,
  # but can be messy if the variables to export are interwined
  # with variables not export.
  with tf.Graph().as_default():
    m = hub.Module(module_spec)
    assign_map = {
        scope_prefix + name: value for name, value in m.variable_map.items()
    }
    tf.train.init_from_checkpoint(checkpoint_path, assign_map)
    init_op = tf.initializers.global_variables()
    with tf.Session() as session:
      session.run(init_op)
      m.export(export_path, session)
473399
def gauge(self, key, gauge=None, default=float("nan"), **dims):
        """"""
        return super(MetricsRegistry, self).gauge(
            self.metadata.register(key, **dims), gauge=gauge, default=default)
382731
def export_module_spec(spec, path, checkpoint_path, name_transform_fn):
  """"""
  with tf.Graph().as_default():
    m = Module(spec)
    assign_map = {
        name_transform_fn(name): value for name, value in m.variable_map.items()
    }
    tf_v1.train.init_from_checkpoint(checkpoint_path, assign_map)
    init_op = tf_v1.initializers.global_variables()
    with tf_v1.Session() as session:
      session.run(init_op)
      m.export(path, session)
486394
def get_gauge(self, name=None):
        '''
        '''
        return self.get_client(name=name, class_=statsd.Gauge)
961669
def is_gauge(md_type):
    
    if md_type not in metric_descriptor.MetricDescriptorType:
        raise ValueError  # pragma: NO COVER

    return md_type in {
        metric_descriptor.MetricDescriptorType.GAUGE_INT64,
        metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE,
        metric_descriptor.MetricDescriptorType.GAUGE_DISTRIBUTION
    }
294572
def _process_metric(self, data, metric, xtype, path, xform=None, tags=None, hostname=None):
        
        value = data

        # Traverse the nested dictionaries
        for key in path.split('.'):
            if value is not None:
                value = value.get(key)
            else:
                break

        if value is not None:
            if xform:
                value = xform(value)
            if xtype == "gauge":
                self.gauge(metric, value, tags=tags, hostname=hostname)
            else:
                self.rate(metric, value, tags=tags, hostname=hostname)
        else:
            self.log.debug("Metric not found: %s -> %s", path, metric)