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


Golang Metric.UnixNano方法代碼示例

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


在下文中一共展示了Metric.UnixNano方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: serialize

func serialize(metric telegraf.Metric) ([]string, error) {
	out := []string{}

	m := make(map[string]interface{})
	m["version"] = "1.1"
	m["timestamp"] = metric.UnixNano() / 1000000000
	m["short_message"] = " "
	m["name"] = metric.Name()

	if host, ok := metric.Tags()["host"]; ok {
		m["host"] = host
	} else {
		host, err := os.Hostname()
		if err != nil {
			return []string{}, err
		}
		m["host"] = host
	}

	for key, value := range metric.Fields() {
		nkey := fmt.Sprintf("_%s", key)
		m[nkey] = value
	}

	serialized, err := ejson.Marshal(m)
	if err != nil {
		return []string{}, err
	}
	out = append(out, string(serialized))

	return out, nil
}
開發者ID:li-ang,項目名稱:telegraf,代碼行數:32,代碼來源:graylog.go

示例2: Serialize

func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
	out := []string{}
	// Get name
	name := metric.Name()
	// Convert UnixNano to Unix timestamps
	timestamp := metric.UnixNano() / 1000000000
	tag_str := buildTags(metric)

	for field_name, value := range metric.Fields() {
		// Convert value
		value_str := fmt.Sprintf("%#v", value)
		// Write graphite metric
		var graphitePoint string
		if name == field_name {
			graphitePoint = fmt.Sprintf("%s.%s %s %d",
				tag_str,
				strings.Replace(name, ".", "_", -1),
				value_str,
				timestamp)
		} else {
			graphitePoint = fmt.Sprintf("%s.%s.%s %s %d",
				tag_str,
				strings.Replace(name, ".", "_", -1),
				strings.Replace(field_name, ".", "_", -1),
				value_str,
				timestamp)
		}
		if s.Prefix != "" {
			graphitePoint = fmt.Sprintf("%s.%s", s.Prefix, graphitePoint)
		}
		out = append(out, graphitePoint)
	}
	return out, nil
}
開發者ID:NathanielMichael,項目名稱:telegraf,代碼行數:34,代碼來源:graphite.go

示例3: Serialize

func (s *JsonSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
	out := []string{}

	m := make(map[string]interface{})
	m["tags"] = metric.Tags()
	m["fields"] = metric.Fields()
	m["name"] = metric.Name()
	m["timestamp"] = metric.UnixNano() / 1000000000
	serialized, err := ejson.Marshal(m)
	if err != nil {
		return []string{}, err
	}
	out = append(out, string(serialized))

	return out, nil
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:16,代碼來源:json.go

示例4: Serialize

func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
	out := []string{}

	// Convert UnixNano to Unix timestamps
	timestamp := metric.UnixNano() / 1000000000

	for field_name, value := range metric.Fields() {
		// Convert value
		value_str := fmt.Sprintf("%#v", value)
		// Write graphite metric
		var graphitePoint string
		graphitePoint = fmt.Sprintf("%s %s %d",
			s.SerializeBucketName(metric, field_name),
			value_str,
			timestamp)
		out = append(out, graphitePoint)
	}
	return out, nil
}
開發者ID:ekini,項目名稱:telegraf,代碼行數:19,代碼來源:graphite.go

示例5: Serialize

func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
	out := []string{}

	// Convert UnixNano to Unix timestamps
	timestamp := metric.UnixNano() / 1000000000

	bucket := s.SerializeBucketName(metric.Name(), metric.Tags())

	for fieldName, value := range metric.Fields() {
		// Convert value to string
		valueS := fmt.Sprintf("%#v", value)
		point := fmt.Sprintf("%s %s %d",
			// insert "field" section of template
			InsertField(bucket, fieldName),
			valueS,
			timestamp)
		out = append(out, point)
	}
	return out, nil
}
開發者ID:lizaoreo,項目名稱:telegraf,代碼行數:20,代碼來源:graphite.go

示例6: Serialize

func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
	out := []string{}

	// Convert UnixNano to Unix timestamps
	timestamp := metric.UnixNano() / 1000000000

	bucket := SerializeBucketName(metric.Name(), metric.Tags(), s.Template, s.Prefix)
	if bucket == "" {
		return out, nil
	}

	for fieldName, value := range metric.Fields() {
		// Convert value to string
		valueS := fmt.Sprintf("%#v", value)
		point := fmt.Sprintf("%s %s %d",
			// insert "field" section of template
			sanitizedChars.Replace(InsertField(bucket, fieldName)),
			sanitizedChars.Replace(valueS),
			timestamp)
		out = append(out, point)
	}
	return out, nil
}
開發者ID:mkuzmin,項目名稱:telegraf,代碼行數:23,代碼來源:graphite.go


注:本文中的github.com/influxdata/telegraf.Metric.UnixNano方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。