当前位置: 首页>>代码示例>>Golang>>正文


Golang Metric.Timestamp方法代码示例

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


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

示例1: addStandardAndWorkflowTags

func addStandardAndWorkflowTags(m core.Metric, allTags map[string]map[string]string) core.Metric {
	hostname := hostnameReader.Hostname()

	tags := m.Tags()
	if tags == nil {
		tags = map[string]string{}
	}
	// apply tags from workflow
	for ns, nsTags := range allTags {
		if strings.HasPrefix(m.Namespace().String(), ns) {
			for k, v := range nsTags {
				tags[k] = v
			}
		}
	}
	// apply standard tag
	tags[core.STD_TAG_PLUGIN_RUNNING_ON] = hostname

	metric := plugin.MetricType{
		Namespace_:          m.Namespace(),
		Version_:            m.Version(),
		LastAdvertisedTime_: m.LastAdvertisedTime(),
		Config_:             m.Config(),
		Data_:               m.Data(),
		Tags_:               tags,
		Description_:        m.Description(),
		Unit_:               m.Unit(),
		Timestamp_:          m.Timestamp(),
	}
	return metric
}
开发者ID:IRCody,项目名称:snap,代码行数:31,代码来源:metrics.go

示例2: ToMetric

// Convert a core.Metric to common.Metric protobuf message
func ToMetric(co core.Metric) *Metric {
	cm := &Metric{
		Namespace: ToNamespace(co.Namespace()),
		Version:   int64(co.Version()),
		Tags:      co.Tags(),
		Timestamp: &Time{
			Sec:  co.Timestamp().Unix(),
			Nsec: int64(co.Timestamp().Nanosecond()),
		},
		LastAdvertisedTime: &Time{
			Sec:  time.Now().Unix(),
			Nsec: int64(time.Now().Nanosecond()),
		},
	}
	if co.Config() != nil {
		cm.Config = ConfigToConfigMap(co.Config())
	}
	switch t := co.Data().(type) {
	case string:
		cm.Data = &Metric_StringData{t}
	case float64:
		cm.Data = &Metric_Float64Data{t}
	case float32:
		cm.Data = &Metric_Float32Data{t}
	case int32:
		cm.Data = &Metric_Int32Data{t}
	case int:
		cm.Data = &Metric_Int64Data{int64(t)}
	case int64:
		cm.Data = &Metric_Int64Data{t}
	case []byte:
		cm.Data = &Metric_BytesData{t}
	case bool:
		cm.Data = &Metric_BoolData{t}
	case nil:
		cm.Data = nil
	default:
		panic(fmt.Sprintf("unsupported type: %s", t))
	}
	return cm
}
开发者ID:IRCody,项目名称:snap,代码行数:42,代码来源:common.go

示例3: addStandardAndWorkflowTags

func addStandardAndWorkflowTags(m core.Metric, allTags map[string]map[string]string) core.Metric {
	hostname, err := hostnameReader.Hostname()
	if err != nil {
		log.WithFields(log.Fields{
			"_module": "control",
			"_file":   "metrics.go,",
			"_block":  "addStandardAndWorkflowTags",
			"error":   err.Error(),
		}).Error("Unable to determine hostname")
	}
	tags := m.Tags()
	if tags == nil {
		tags = map[string]string{}
	}
	// apply tags from workflow
	for ns, nsTags := range allTags {
		if strings.HasPrefix(m.Namespace().String(), ns) {
			for k, v := range nsTags {
				tags[k] = v
			}
		}
	}
	// apply standard tag
	tags[core.STD_TAG_PLUGIN_RUNNING_ON] = hostname

	metric := plugin.MetricType{
		Namespace_:          m.Namespace(),
		Version_:            m.Version(),
		LastAdvertisedTime_: m.LastAdvertisedTime(),
		Config_:             m.Config(),
		Data_:               m.Data(),
		Tags_:               tags,
		Description_:        m.Description(),
		Unit_:               m.Unit(),
		Timestamp_:          m.Timestamp(),
	}
	return metric
}
开发者ID:yxzoro,项目名称:snap,代码行数:38,代码来源:metrics.go


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