Example #1
0
func getValue(m *dto.Metric) float64 {
	if m.Gauge != nil {
		return m.GetGauge().GetValue()
	}
	if m.Counter != nil {
		return m.GetCounter().GetValue()
	}
	if m.Untyped != nil {
		return m.GetUntyped().GetValue()
	}
	return 0.
}
Example #2
0
// Get name and value from metric
func getNameAndValue(m *dto.Metric) map[string]interface{} {
	fields := make(map[string]interface{})
	if m.Gauge != nil {
		if !math.IsNaN(m.GetGauge().GetValue()) {
			fields["gauge"] = float64(m.GetGauge().GetValue())
		}
	} else if m.Counter != nil {
		if !math.IsNaN(m.GetGauge().GetValue()) {
			fields["counter"] = float64(m.GetCounter().GetValue())
		}
	} else if m.Untyped != nil {
		if !math.IsNaN(m.GetGauge().GetValue()) {
			fields["value"] = float64(m.GetUntyped().GetValue())
		}
	}
	return fields
}
Example #3
0
func (t *UptimeSuite) TestUptimeReporting(c *gc.C) {
	now := time.Now()
	u, err := monitoring.NewUptimeCollector("test", "test", "test", time.Now)
	c.Assert(err, jc.ErrorIsNil)
	ch := make(chan prometheus.Metric, 1000)
	u.Collect(ch)
	var m prometheus.Metric
	select {
	case m = <-ch:
	default:
		c.Error("metric not provided by collector")
	}

	var raw prometheusinternal.Metric
	err = m.Write(&raw)
	c.Assert(err, jc.ErrorIsNil)

	cnt := raw.GetCounter()
	val := cnt.GetValue()
	c.Assert(val, gc.Equals, float64(now.Unix()))
}