本文整理汇总了Golang中github.com/prometheus/client_model/go.Metric.GetGauge方法的典型用法代码示例。如果您正苦于以下问题:Golang Metric.GetGauge方法的具体用法?Golang Metric.GetGauge怎么用?Golang Metric.GetGauge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/prometheus/client_model/go.Metric
的用法示例。
在下文中一共展示了Metric.GetGauge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getValue
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.
}
示例2: getNameAndValue
// 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
}
示例3: TestCollectionSizeReporting
func (s *collectionSizeSuite) TestCollectionSizeReporting(c *gc.C) {
collection := s.Session.DB("test").C("test_collection")
u := monitoring.NewCollectionSizeCollector("test", "test", "test", collection)
defer u.Close()
err := collection.Insert(bson.M{"test": true})
c.Assert(err, jc.ErrorIsNil)
ch := make(chan prometheus.Metric, 2)
u.Collect(ch)
var m prometheus.Metric
// read the size
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.GetGauge()
valueOne := cnt.GetValue()
// read the count
select {
case m = <-ch:
default:
c.Error("metric not provided by collector")
}
err = m.Write(&raw)
c.Assert(err, jc.ErrorIsNil)
cnt = raw.GetGauge()
val := cnt.GetValue()
c.Assert(val, gc.Equals, float64(1.0))
err = collection.Insert(bson.M{"test": true})
c.Assert(err, jc.ErrorIsNil)
u.Collect(ch)
// read the size
select {
case m = <-ch:
default:
c.Error("metric not provided by collector")
}
err = m.Write(&raw)
c.Assert(err, jc.ErrorIsNil)
cnt = raw.GetGauge()
valueTwo := cnt.GetValue()
c.Assert(2*valueOne, gc.Equals, valueTwo)
// read the count
select {
case m = <-ch:
default:
c.Error("metric not provided by collector")
}
err = m.Write(&raw)
c.Assert(err, jc.ErrorIsNil)
cnt = raw.GetGauge()
val = cnt.GetValue()
c.Assert(val, gc.Equals, float64(2.0))
}