• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang core.NewNamespace函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/intelsdi-x/snap/core.NewNamespace函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNamespace函数的具体用法?Golang NewNamespace怎么用?Golang NewNamespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewNamespace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetMetricTypes

// GetMetricTypes returns metric types for testing
func (f *AnotherMock) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	mts := []plugin.MetricType{}
	if _, ok := cfg.Table()["test-fail"]; ok {
		return mts, fmt.Errorf("testing")
	}
	if _, ok := cfg.Table()["test"]; ok {
		mts = append(mts, plugin.MetricType{
			Namespace_:   core.NewNamespace("intel", "anothermock", "test"),
			Description_: "anothermock description",
			Unit_:        "anothermock unit",
		})
	}
	mts = append(mts, plugin.MetricType{
		Namespace_:   core.NewNamespace("intel", "anothermock", "foo"),
		Description_: "anothermock description",
		Unit_:        "anothermock unit",
	})
	mts = append(mts, plugin.MetricType{
		Namespace_:   core.NewNamespace("intel", "anothermock", "bar"),
		Description_: "anothermock description",
		Unit_:        "anothermock unit",
	})
	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("intel", "anothermock").
			AddDynamicElement("host", "name of the host").
			AddStaticElement("baz"),
		Description_: "anothermock description",
		Unit_:        "anothermock unit",
	})
	return mts, nil
}
开发者ID:IRCody,项目名称:snap,代码行数:32,代码来源:anothermock.go


示例2: TestPsutilCollectMetrics

func TestPsutilCollectMetrics(t *testing.T) {
	Convey("psutil collector", t, func() {
		p := &Psutil{}
		Convey("collect metrics", func() {
			mts := []plugin.MetricType{
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "psutil", "load", "load1"),
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "psutil", "load", "load5"),
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "psutil", "load", "load15"),
				},
				plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "psutil", "vm", "total"),
				},
			}
			if runtime.GOOS != "darwin" {
				mts = append(mts, plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "psutil", "cpu", "cpu0", "user"),
				})
			}
			metrics, err := p.CollectMetrics(mts)
			So(err, ShouldBeNil)
			So(metrics, ShouldNotBeNil)
		})
		Convey("get metric types", func() {
			mts, err := p.GetMetricTypes(plugin.ConfigType{})
			So(err, ShouldBeNil)
			So(mts, ShouldNotBeNil)
		})

	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-psutil,代码行数:35,代码来源:psutil_integration_test.go


示例3: TestHANAPublish

func TestHANAPublish(t *testing.T) {
	var buf bytes.Buffer
	metrics := []plugin.MetricType{
		*plugin.NewMetricType(core.NewNamespace("test_string"), time.Now(), nil, "", "example_string"),
		*plugin.NewMetricType(core.NewNamespace("test_int"), time.Now(), nil, "", 1),
		*plugin.NewMetricType(core.NewNamespace("test_string_slice"), time.Now(), nil, "", []string{"str1", "str2"}),
		*plugin.NewMetricType(core.NewNamespace("test_string_slice"), time.Now(), nil, "", []int{1, 2}),
		*plugin.NewMetricType(core.NewNamespace("test_uint8"), time.Now(), nil, "", uint8(1)),
	}
	config := make(map[string]ctypes.ConfigValue)
	enc := gob.NewEncoder(&buf)
	enc.Encode(metrics)

	Convey("TestHANAPublish", t, func() {
		config["username"] = ctypes.ConfigValueStr{Value: "root"}
		config["password"] = ctypes.ConfigValueStr{Value: "root"}
		config["database"] = ctypes.ConfigValueStr{Value: "SNAP_TEST"}
		config["host"] = ctypes.ConfigValueStr{Value: "localhost"}
		config["port"] = ctypes.ConfigValueStr{Value: "1433"}
		config["tablename"] = ctypes.ConfigValueStr{Value: "info"}
		sp := NewHANAPublisher()
		cp, _ := sp.GetConfigPolicy()
		cfg, _ := cp.Get([]string{""}).Process(config)
		err := sp.Publish("", buf.Bytes(), *cfg)
		Convey("So not passing in a content type should result in an error", func() {
			So(err, ShouldResemble, errors.New("Unknown content type ''"))
		})
		err = sp.Publish(plugin.SnapGOBContentType, buf.Bytes(), *cfg)
		Convey("So publishing metrics should not result in an error", func() {
			So(err, ShouldBeNil)
		})
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-publisher-hana,代码行数:33,代码来源:hana_integration_test.go


示例4: TestSubscribe

func TestSubscribe(t *testing.T) {
	ns := []core.Namespace{
		core.NewNamespace("test1"),
		core.NewNamespace("test2"),
		core.NewNamespace("test3"),
	}
	lp := new(loadedPlugin)
	ts := time.Now()
	mt := []*metricType{
		newMetricType(ns[0], ts, lp),
		newMetricType(ns[1], ts, lp),
		newMetricType(ns[2], ts, lp),
	}
	mc := newMetricCatalog()
	for _, v := range mt {
		mc.Add(v)
	}
	Convey("when the metric is not in the table", t, func() {
		Convey("then it returns an error", func() {
			err := mc.Subscribe([]string{"test4"}, -1)
			So(err.Error(), ShouldContainSubstring, "Metric not found:")
		})
	})
	Convey("when the metric is in the table", t, func() {
		Convey("then it gets correctly increments the count", func() {
			err := mc.Subscribe([]string{"test1"}, -1)
			So(err, ShouldBeNil)
			m, err2 := mc.Get(core.NewNamespace("test1"), -1)
			So(err2, ShouldBeNil)
			So(m.subscriptions, ShouldEqual, 1)
		})
	})
}
开发者ID:Collinux,项目名称:snap,代码行数:33,代码来源:metrics_test.go


示例5: GetMetricTypes

//GetMetricTypes returns metric types for testing
func (n *Ns1) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	mts := []plugin.MetricType{}

	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("raintank", "apps", "ns1", "zones", "*", "qps"),
		Config_:    cfg.ConfigDataNode,
	})
	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", "*", "*", "state"),
		Config_:    cfg.ConfigDataNode,
	})
	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", "*", "*", "rtt"),
		Config_:    cfg.ConfigDataNode,
	})
	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", "*", "*", "loss"),
		Config_:    cfg.ConfigDataNode,
	})
	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", "*", "*", "connect"),
		Config_:    cfg.ConfigDataNode,
	})

	return mts, nil
}
开发者ID:ChihChaoChang,项目名称:raintank-apps,代码行数:27,代码来源:ns1.go


示例6: TestMetricStaticDynamicNamespace

func TestMetricStaticDynamicNamespace(t *testing.T) {
	Convey("validateStaticDynamic()", t, func() {
		Convey("has static elements only", func() {
			ns := core.NewNamespace("mock", "foo", "bar")
			err := validateMetricNamespace(ns)
			So(err, ShouldBeNil)
		})
		Convey("had both static and dynamic elements", func() {
			ns := core.NewNamespace("mock", "foo", "*", "bar")
			ns[2].Name = "dynamic element"
			err := validateMetricNamespace(ns)
			So(err, ShouldBeNil)
		})
		Convey("has name for a static element", func() {
			ns := core.NewNamespace("mock", "foo")
			ns[0].Name = "static element"
			err := validateMetricNamespace(ns)
			So(err, ShouldNotBeNil)
		})
		Convey("has * but no name", func() {
			ns := core.NewNamespace("mock", "foo", "*", "bar")
			err := validateMetricNamespace(ns)
			So(err, ShouldNotBeNil)
		})
	})
}
开发者ID:yxzoro,项目名称:snap,代码行数:26,代码来源:metrics_test.go


示例7: prepareTestCases

func prepareTestCases() []testCase {
	hostname, _ := hostnameReader.Hostname()
	fooTags := map[string]string{
		"foo_tag": "foo_val",
	}
	barTags := map[string]string{
		"foobar_tag": "foobar_val",
	}
	tarTags := map[string]string{
		"tarqaz_tag": "tarqaz_val",
	}

	allTags := map[string]map[string]string{
		foo: fooTags,
		bar: barTags,
		tar: tarTags,
	}

	foobazMetric := plugin.MetricType{
		Namespace_: core.NewNamespace("intel", "foo", "baz"),
	}
	foobarMetric := plugin.MetricType{
		Namespace_: core.NewNamespace("intel", "foo", "bar"),
	}
	tarqazMetric := plugin.MetricType{
		Namespace_: core.NewNamespace("intel", "tar", "qaz"),
	}

	stdMetric := plugin.MetricType{
		Namespace_: core.NewNamespace("intel", "std"),
	}

	foobazExpected := map[string]string{
		core.STD_TAG_PLUGIN_RUNNING_ON: hostname,
		"foo_tag":                      "foo_val",
	}
	foobarExpected := map[string]string{
		core.STD_TAG_PLUGIN_RUNNING_ON: hostname,
		"foo_tag":                      "foo_val",
		"foobar_tag":                   "foobar_val",
	}
	tarqazExpected := map[string]string{
		core.STD_TAG_PLUGIN_RUNNING_ON: hostname,
		"tarqaz_tag":                   "tarqaz_val",
	}
	stdExpected := map[string]string{
		core.STD_TAG_PLUGIN_RUNNING_ON: hostname,
	}

	testCases := []testCase{
		{foobazMetric, allTags, foobazExpected},
		{foobarMetric, allTags, foobarExpected},
		{tarqazMetric, allTags, tarqazExpected},
		{stdMetric, allTags, stdExpected},
		{foobazMetric, nil, stdExpected},
	}

	return testCases
}
开发者ID:jcooklin,项目名称:snap,代码行数:59,代码来源:metrics_small_test.go


示例8: TestMatchQueryToNamespaces

func TestMatchQueryToNamespaces(t *testing.T) {
	Convey("RPC client errors", t, func() {
		input := core.NewNamespace("testing", "this")

		proxy := ControlProxy{Client: mockClient{RpcErr: true}}
		ns, err := proxy.ExpandWildcards(input)

		Convey("So the error should be passed through", func() {
			So(err.Error(), ShouldResemble, rpcErr.Error())
		})
		Convey("So The namespace ShouldBeNil", func() {
			So(ns, ShouldBeNil)
		})
	})

	Convey("call to Control.MatchQueryToNamespaces returns error", t, func() {
		input := core.NewNamespace("testing", "this")
		reply := &rpc.ExpandWildcardsReply{
			Error: &common.SnapError{
				ErrorFields: map[string]string{},
				ErrorString: "Error from control",
			},
		}

		proxy := ControlProxy{Client: mockClient{MatchReply: reply}}
		ns, err := proxy.MatchQueryToNamespaces(input)

		Convey("So the err should be: "+reply.Error.ErrorString, func() {
			So(err.Error(), ShouldResemble, common.ToSnapError(reply.Error).Error())
		})
		Convey("So Namespaces should be nil", func() {
			So(ns, ShouldBeNil)
		})
	})

	Convey("Control.MatchQueryToNamespaces returns successfully", t, func() {
		input := core.NewNamespace("testing", "this")
		a := core.NewNamespace("testing", "this")
		b := core.NewNamespace("stuff", "more")
		proto_a := &rpc.ArrString{S: common.ToNamespace(a)}
		proto_b := &rpc.ArrString{S: common.ToNamespace(b)}
		reply := &rpc.ExpandWildcardsReply{
			Error: nil,
			NSS:   []*rpc.ArrString{proto_a, proto_b},
		}

		proxy := ControlProxy{Client: mockClient{MatchReply: reply}}
		ns, err := proxy.MatchQueryToNamespaces(input)

		Convey("so the err Should be nil", func() {
			So(err, ShouldBeNil)
		})
		Convey("So namespaces should resemble:"+a.String()+","+b.String(), func() {
			So(ns, ShouldResemble, []core.Namespace{a, b})
		})

	})

}
开发者ID:yxzoro,项目名称:snap,代码行数:59,代码来源:controlproxy_medium_test.go


示例9: getMetrics

func getMetrics(webserver string, metrics []string) ([]plugin.MetricType, error) {
	tr := &http.Transport{}
	client := &http.Client{Transport: tr}
	resp, err := client.Get(webserver)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != 200 {
		defer resp.Body.Close()
		return nil, errReqFailed
	}
	defer resp.Body.Close()

	mtsmap := make(map[string]plugin.MetricType)
	scanner := bufio.NewScanner(resp.Body)
	for scanner.Scan() {
		var ns string
		line := scanner.Text()
		lineslice := strings.Split(line, ": ")
		if strings.Contains(line, "Scoreboard") {
			line = strings.Trim(line, "Scoreboard")
			for ns := range workers {
				data := strings.Count(line, workers[ns])
				mtsmap[ns] = plugin.MetricType{
					Namespace_: core.NewNamespace("intel", "apache", "workers", ns),
					Data_:      data,
					Timestamp_: time.Now(),
				}
			}
		} else {
			ns = strings.Replace(lineslice[0], " ", "_", -1)
			data, err := strconv.ParseFloat(lineslice[1], 64)
			if err != nil {
				return nil, err
			}
			mtsmap[ns] = plugin.MetricType{
				Namespace_: core.NewNamespace("intel", "apache", ns),
				Data_:      data,
				Timestamp_: time.Now(),
			}
		}
	}
	if len(metrics) == 0 {
		mts := make([]plugin.MetricType, 0, len(mtsmap))
		for _, v := range mtsmap {
			mts = append(mts, v)
		}
		return mts, nil
	}
	mts := make([]plugin.MetricType, 0, len(metrics))
	for _, v := range metrics {
		mt, ok := mtsmap[v]
		if ok {
			mts = append(mts, mt)
		}
	}
	return mts, nil
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-apache,代码行数:58,代码来源:apache.go


示例10: TestCreateMetricNamespace

func TestCreateMetricNamespace(t *testing.T) {
	Convey("create metric namespace", t, func() {
		nscreator := nsCreator{}

		Convey("return an error when metric name is empty", func() {
			ns, err := nscreator.createMetricNamespace(core.NewNamespace(), "")
			So(err, ShouldNotBeNil)
			So(ns, ShouldBeNil)
		})

		Convey("when metric name contains only static elements", func() {
			ns, err := nscreator.createMetricNamespace(core.NewNamespace("vendor", "plugin"), "disk/total_usage")
			So(err, ShouldBeNil)
			So(ns, ShouldNotBeNil)
			So(ns.String(), ShouldEqual, "/vendor/plugin/disk/total_usage")
		})

		Convey("when metric name contains dynamic element", func() {

			Convey("return an error for unknown dynamic element", func() {
				ns, err := nscreator.createMetricNamespace(core.NewNamespace("vendor", "plugin"), "disk/*/usage")
				So(err, ShouldNotBeNil)
				So(ns, ShouldBeNil)
				So(err.Error(), ShouldEqual, "Unknown dynamic element in metric `disk/*/usage` under index 1")
			})

			Convey("successful create metric namespace with dynamic element", func() {
				// set definition of dynamic element (its name and description)
				nscreator.dynamicElements = map[string]dynamicElement{
					"disk": dynamicElement{"disk_id", "id of disk"},
				}
				ns, err := nscreator.createMetricNamespace(core.NewNamespace("vendor", "plugin"), "disk/*/usage")
				So(err, ShouldBeNil)
				So(ns, ShouldNotBeEmpty)
				So(ns.String(), ShouldEqual, "/vendor/plugin/disk/*/usage")
				So(ns.Element(3).Description, ShouldEqual, nscreator.dynamicElements["disk"].description)
				So(ns.Element(3).Name, ShouldEqual, nscreator.dynamicElements["disk"].name)
			})

			Convey("successful create metric namespace with dynamic element at the end of metric name", func() {
				nscreator.dynamicElements = map[string]dynamicElement{
					"percpu_usage": dynamicElement{"cpu_id", "id of cpu"},
				}
				ns, err := nscreator.createMetricNamespace(core.NewNamespace("vendor", "plugin"), "percpu_usage/*")
				So(err, ShouldBeNil)
				So(ns, ShouldNotBeEmpty)
				// metric namespace should not end with an asterisk,
				// so element `value` is expected to be added
				So(ns.String(), ShouldEqual, "/vendor/plugin/percpu_usage/*/value")
				So(ns.Element(3).Description, ShouldEqual, nscreator.dynamicElements["percpu_usage"].description)
				So(ns.Element(3).Name, ShouldEqual, nscreator.dynamicElements["percpu_usage"].name)
			})

		})

	})

}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-docker,代码行数:58,代码来源:docker_test.go


示例11: MonitorsMetrics

func (n *Ns1) MonitorsMetrics(client *Client, mts []plugin.MetricType) ([]plugin.MetricType, error) {
	metrics := make([]plugin.MetricType, 0)
	conf := mts[0].Config().Table()
	jobId, ok := conf["jobId"]
	if !ok || jobId.(ctypes.ConfigValueStr).Value == "" {
		LogError("jobId missing from config.")
		return metrics, nil
	}
	jobName, ok := conf["jobName"]
	if !ok || jobName.(ctypes.ConfigValueStr).Value == "" {
		LogError("jobName missing from config.")
		return metrics, nil
	}

	jSlug := slug.Make(jobName.(ctypes.ConfigValueStr).Value)

	j, err := client.MonitoringJobById(jobId.(ctypes.ConfigValueStr).Value)
	if err != nil {
		LogError("failed to query for job.", err)
		return nil, err
	}

	for region, status := range j.Status {
		data, ok := statusMap[status.Status]
		if !ok {
			return nil, fmt.Errorf("Unknown monitor status")
		}

		metrics = append(metrics, plugin.MetricType{
			Data_:      data,
			Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", jSlug, region, "state"),
			Timestamp_: time.Now(),
			Version_:   mts[0].Version(),
		})

	}

	jobMetrics, err := client.MonitoringMetics(j.Id)
	if err != nil {
		return nil, err
	}
	for _, jm := range jobMetrics {
		for stat, m := range jm.Metrics {
			metrics = append(metrics, plugin.MetricType{
				Data_:      m.Avg,
				Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", jSlug, jm.Region, stat),
				Timestamp_: time.Now(),
				Version_:   mts[0].Version(),
			})
		}
	}

	return metrics, nil
}
开发者ID:ChihChaoChang,项目名称:raintank-apps,代码行数:54,代码来源:ns1.go


示例12: TestCollectMetrics

func (s *CollectorSuite) TestCollectMetrics() {

	Convey("Given set of metric types", s.T(), func() {
		cfg := setupCfg(s.server.URL, "me", "secret", "admin")
		m1 := plugin.MetricType{
			Namespace_: core.NewNamespace("intel", "openstack", "cinder", "demo", "limits", "MaxTotalVolumeGigabytes"),
			Config_:    cfg.ConfigDataNode}
		m2 := plugin.MetricType{
			Namespace_: core.NewNamespace("intel", "openstack", "cinder", "demo", "volumes", "count"),
			Config_:    cfg.ConfigDataNode}
		m3 := plugin.MetricType{
			Namespace_: core.NewNamespace("intel", "openstack", "cinder", "demo", "snapshots", "bytes"),
			Config_:    cfg.ConfigDataNode}

		Convey("When ColelctMetrics() is called", func() {
			collector := New()

			mts, err := collector.CollectMetrics([]plugin.MetricType{m1, m2, m3})

			Convey("Then no error should be reported", func() {
				So(err, ShouldBeNil)
			})

			Convey("and proper metric types are returned", func() {
				metricNames := map[string]interface{}{}
				for _, m := range mts {
					ns := m.Namespace().String()
					metricNames[ns] = m.Data()
					fmt.Println(ns, "=", m.Data())
				}

				So(len(mts), ShouldEqual, 3)

				val, ok := metricNames["/intel/openstack/cinder/demo/limits/MaxTotalVolumeGigabytes"]
				So(ok, ShouldBeTrue)
				So(val, ShouldEqual, s.MaxTotalVolumeGigabytes)

				val, ok = metricNames["/intel/openstack/cinder/demo/volumes/count"]
				So(ok, ShouldBeTrue)
				So(val, ShouldEqual, 1)

				val, ok = metricNames["/intel/openstack/cinder/demo/snapshots/bytes"]
				So(ok, ShouldBeTrue)
				So(val, ShouldEqual, s.SnapShotSize*1024*1024*1024)

			})
		})
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-cinder,代码行数:49,代码来源:collector_test.go


示例13: GetMetricTypes

//GetMetricTypes returns metric types for testing
func (f *Mock) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	mts := []plugin.MetricType{}
	if _, ok := cfg.Table()["test-fail"]; ok {
		return mts, fmt.Errorf("missing on-load plugin config entry 'test'")
	}
	if _, ok := cfg.Table()["test"]; ok {
		mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock", "test")})
	}
	mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock", "foo")})
	mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock", "bar")})
	mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock").
		AddDynamicElement("host", "name of the host").
		AddStaticElement("baz")})
	return mts, nil
}
开发者ID:lynxbat,项目名称:snap,代码行数:16,代码来源:mock.go


示例14: GetMetricTypes

// GetMetricTypes returns list of available metric types
// It returns error in case retrieval was not successful
func (c *collector) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	mts := []plugin.MetricType{}

	var err error
	c.allTenants, err = getTenants(cfg)
	if err != nil {
		return nil, err
	}

	// Generate available namespace for limits
	namespaces := []string{}
	for _, tenantName := range c.allTenants {
		// Construct temporary struct to generate namespace based on tags
		var metrics struct {
			S types.Snapshots `json:"snapshots"`
			V types.Volumes   `json:"volumes"`
			L types.Limits    `json:"limits"`
		}
		current := strings.Join([]string{vendor, fs, name, tenantName}, "/")
		ns.FromCompositionTags(metrics, current, &namespaces)
	}

	for _, namespace := range namespaces {
		mts = append(mts, plugin.MetricType{
			Namespace_: core.NewNamespace(strings.Split(namespace, "/")...),
			Config_:    cfg.ConfigDataNode,
		})
	}

	return mts, nil
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-cinder,代码行数:33,代码来源:collector.go


示例15: TestRiemannPublish

// integration test
func TestRiemannPublish(t *testing.T) {
	// This integration test requires a Riemann Server
	broker := os.Getenv("SNAP_TEST_RIEMANN")
	if broker == "" {
		fmt.Println("Skipping integration tests")
		return
	}

	var buf bytes.Buffer
	buf.Reset()
	r := NewRiemannPublisher()
	config := make(map[string]ctypes.ConfigValue)
	config["broker"] = ctypes.ConfigValueStr{Value: broker}
	cp, _ := r.GetConfigPolicy()
	cfg, _ := cp.Get([]string{""}).Process(config)
	tags := map[string]string{}
	tags[core.STD_TAG_PLUGIN_RUNNING_ON] = "bacon-powered"
	metrics := []plugin.MetricType{
		*plugin.NewMetricType(core.NewNamespace("intel", "cpu", "temp"), time.Now(), tags, "some unit", 100),
	}
	enc := gob.NewEncoder(&buf)
	enc.Encode(metrics)
	err := r.Publish(plugin.SnapGOBContentType, buf.Bytes(), *cfg)
	Convey("Publish metric to Riemann", t, func() {
		Convey("So err should not be returned", func() {
			So(err, ShouldBeNil)
		})
		Convey("So metric retrieved equals metric published", func() {
			c, _ := raidman.Dial("tcp", broker)
			events, _ := c.Query("host = \"bacon-powered\"")
			So(len(events), ShouldBeGreaterThan, 0)
		})
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-publisher-riemann,代码行数:35,代码来源:riemann_integration_test.go


示例16: buildMetricTypes

func buildMetricTypes(pct plugin.ConfigType) {
	host := getServer(pct)
	mMap, err := getNodeMetrics(host)
	handleErr(err)

	mts := []plugin.MetricType{}
	for _, n := range mMap {
		for ns := range n {
			namespace := strings.Split(ns, "/")
			namespace[3] = "*"
			nss := core.NewNamespace(namespace...)
			nss[3].Name = "host ID"
			nss[3].Description = "ID of ES host"
			mts = append(mts, plugin.MetricType{Namespace_: nss})
		}
		break
	}

	metrics, err := getClusterMetrics(host)
	handleErr(err)

	for _, m := range metrics {
		mts = append(mts, plugin.MetricType{Namespace_: m.Namespace()})
	}
	writeMetricTypes(mts)
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-elasticsearch,代码行数:26,代码来源:elasticsearch.go


示例17: TestCpuPlugin

func TestCpuPlugin(t *testing.T) {
	httpmock.Mock = true

	Convey("getcpuTime Should return cputime value", t, func() {

		defer httpmock.ResetResponders()
		httpmock.RegisterResponder("GET", "http://192.168.192.200:8000/trace/count", `{"time_ms": 144123232, "list": []}`, 200)

		cpuTime, err := getCPUTime("http://192.168.192.200:8000")
		So(err, ShouldBeNil)
		So(cpuTime, ShouldEqual, 144123232)

	})
	Convey("CpuStat Should return pluginMetricType Data", t, func() {

		defer httpmock.ResetResponders()
		httpmock.RegisterResponder("GET", "http://192.168.192.200:8000/trace/count", `{"time_ms": 144123232, "list": []}`, 200)

		ns := core.NewNamespace("intel", "osv", "cpu", "cputime")
		cpuTime, err := cpuStat(ns, "http://192.168.192.200:8000")
		So(err, ShouldBeNil)
		So(cpuTime.Namespace(), ShouldResemble, ns)
		So(cpuTime.Data_, ShouldEqual, 144123232)

	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-osv,代码行数:26,代码来源:cpu_test.go


示例18: getCPUMetricTypes

func getCPUMetricTypes() ([]plugin.MetricType, error) {
	var mts []plugin.MetricType
	for _, metricType := range cpuMetrics {
		mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace(Vendor, Name, "cpu", metricType)})
	}
	return mts, nil
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-osv,代码行数:7,代码来源:cpu.go


示例19: GetMetricTypes

// GetMetricTypes returns list of available metrics
func (d *docker) GetMetricTypes(_ plugin.ConfigType) ([]plugin.MetricType, error) {
	var metricTypes []plugin.MetricType
	var err error

	// initialize containerData struct
	data := containerData{
		Stats: wrapper.NewStatistics(),
	}

	// generate available namespace for data container structure
	dockerMetrics := []string{}
	utils.FromCompositeObject(data, "", &dockerMetrics)
	nscreator := nsCreator{dynamicElements: definedDynamicElements}

	for _, metricName := range dockerMetrics {

		ns := core.NewNamespace(NS_VENDOR, NS_PLUGIN).
			AddDynamicElement("docker_id", "an id of docker container")

		if ns, err = nscreator.createMetricNamespace(ns, metricName); err != nil {
			// skip this metric name which is not supported
			// fmt.Fprintf(os.Stderr, "Error in creating metric namespace: %v\n", err)
			continue
		}
		metricType := plugin.MetricType{
			Namespace_: ns,
			Version_:   VERSION,
		}
		metricTypes = append(metricTypes, metricType)
	}

	return metricTypes, nil
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-docker,代码行数:34,代码来源:docker.go


示例20: extractFromNamespace

// extractFromNamespace extracts element of index i from namespace string
func extractFromNamespace(namespace string, i int) (string, error) {
	ns := core.NewNamespace(strings.Split(strings.TrimPrefix(namespace, "/"), "/")...)
	if len(ns) < i+1 {
		return "", fmt.Errorf("Cannot extract element from namespace, index out of range (i = %d)", i)
	}
	return ns[i].Value, nil
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-iostat,代码行数:8,代码来源:iostat.go



注:本文中的github.com/intelsdi-x/snap/core.NewNamespace函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang core.NewRequestedPlugin函数代码示例发布时间:2022-05-23
下一篇:
Golang core.JoinNamespace函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap