當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MetricBatch.CharmURL方法代碼示例

本文整理匯總了Golang中github.com/juju/juju/state.MetricBatch.CharmURL方法的典型用法代碼示例。如果您正苦於以下問題:Golang MetricBatch.CharmURL方法的具體用法?Golang MetricBatch.CharmURL怎麽用?Golang MetricBatch.CharmURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/juju/juju/state.MetricBatch的用法示例。


在下文中一共展示了MetricBatch.CharmURL方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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.CharmURL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。