本文整理汇总了Golang中github.com/juju/juju/state.MetricBatch类的典型用法代码示例。如果您正苦于以下问题:Golang MetricBatch类的具体用法?Golang MetricBatch怎么用?Golang MetricBatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetricBatch类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ToWire
// ToWire converts the state.MetricBatch into a type
// that can be sent over the wire to the collector.
func ToWire(mb *state.MetricBatch) *wireformat.MetricBatch {
metrics := make([]wireformat.Metric, len(mb.Metrics()))
for i, m := range mb.Metrics() {
metrics[i] = wireformat.Metric{
Key: m.Key,
Value: m.Value,
Time: m.Time.UTC(),
}
}
return &wireformat.MetricBatch{
UUID: mb.UUID(),
ModelUUID: mb.ModelUUID(),
UnitName: mb.Unit(),
CharmUrl: mb.CharmURL(),
Created: mb.Created().UTC(),
Metrics: metrics,
Credentials: mb.Credentials(),
}
}
开发者ID:kat-co,项目名称:juju,代码行数:21,代码来源:metricsender.go
示例2: assertSameMetric
func assertSameMetric(c *gc.C, a params.MetricResult, b *state.MetricBatch) {
c.Assert(a.Key, gc.Equals, b.Metrics()[0].Key)
c.Assert(a.Value, gc.Equals, b.Metrics()[0].Value)
c.Assert(a.Time, jc.TimeBetween(b.Metrics()[0].Time, b.Metrics()[0].Time))
}
开发者ID:exekias,项目名称:juju,代码行数:5,代码来源:client_test.go
示例3: TestModelMetricBatches
func (s *MetricLocalCharmSuite) TestModelMetricBatches(c *gc.C) {
now := s.State.NowToTheSecond()
// Add 2 metric batches to a single unit.
m := state.Metric{"pings", "5", now}
m2 := state.Metric{"pings", "10", now}
_, err := s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: s.unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
newUnit, err := s.application.AddUnit()
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now.Add(time.Second),
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m2},
Unit: newUnit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
// Create a new model and add a metric batch.
st := s.Factory.MakeModel(c, nil)
defer st.Close()
f := factory.NewFactory(st)
meteredCharm := f.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "cs:quantal/metered"})
service := f.MakeApplication(c, &factory.ApplicationParams{Charm: meteredCharm})
unit := f.MakeUnit(c, &factory.UnitParams{Application: service, SetCharmURL: true})
_, err = st.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
// We expect 2 metric batches in our first model.
metricBatches, err := s.State.MetricBatchesForModel()
c.Assert(err, jc.ErrorIsNil)
c.Assert(metricBatches, gc.HasLen, 2)
var first, second state.MetricBatch
for _, m := range metricBatches {
if m.Unit() == "metered/0" {
first = m
}
if m.Unit() == "metered/1" {
second = m
}
}
c.Assert(first, gc.NotNil)
c.Assert(second, gc.NotNil)
c.Check(first.Unit(), gc.Equals, "metered/0")
c.Check(first.CharmURL(), gc.Equals, "local:quantal/metered")
c.Check(first.ModelUUID(), gc.Equals, s.State.ModelUUID())
c.Check(first.Sent(), jc.IsFalse)
c.Assert(first.Metrics(), gc.HasLen, 1)
c.Check(first.Metrics()[0].Value, gc.Equals, "5")
c.Check(second.Unit(), gc.Equals, "metered/1")
c.Check(second.CharmURL(), gc.Equals, "local:quantal/metered")
c.Check(second.ModelUUID(), gc.Equals, s.State.ModelUUID())
c.Check(second.Sent(), jc.IsFalse)
c.Assert(second.Metrics(), gc.HasLen, 1)
c.Check(second.Metrics()[0].Value, gc.Equals, "10")
// And a single metric batch in the second model.
metricBatches, err = st.MetricBatchesForModel()
c.Assert(err, jc.ErrorIsNil)
c.Assert(metricBatches, gc.HasLen, 1)
}
开发者ID:bac,项目名称:juju,代码行数:82,代码来源:metrics_test.go
注:本文中的github.com/juju/juju/state.MetricBatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论