本文整理汇总了Golang中github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin.Config.GetInt方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.GetInt方法的具体用法?Golang Config.GetInt怎么用?Golang Config.GetInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin.Config
的用法示例。
在下文中一共展示了Config.GetInt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Publish
func (f *GraphitePublisher) Publish(metrics []plugin.Metric, cfg plugin.Config) error {
logger := getLogger(cfg)
logger.Debug("Publishing started")
var tagsForPrefix []string
logger.Debug("publishing %v metrics to %v", len(metrics), cfg)
server, err := cfg.GetString("server")
if err != nil {
return err
}
port, err := cfg.GetInt("port")
if err != nil {
return err
}
tagConfigs, err := cfg.GetString("prefix_tags")
if err == nil {
tagsForPrefix = strings.Split(tagConfigs, ",")
}
pre, err := cfg.GetString("prefix")
if err != nil {
pre = ""
}
logger.Debug("Attempting to connect to %s:%d", server, port)
gite, err := graphite.NewGraphiteWithMetricPrefix(server, int(port), pre)
if err != nil {
logger.Errorf("Error Connecting to graphite at %s:%d. Error: %v", server, port, err)
return fmt.Errorf("Error Connecting to graphite at %s:%d. Error: %v", server, port, err)
}
defer gite.Disconnect()
logger.Debug("Connected to %s:%s successfully", server, port)
giteMetrics := make([]graphite.Metric, len(metrics))
for i, m := range metrics {
key := strings.Join(m.Namespace.Strings(), ".")
for _, tag := range tagsForPrefix {
nextTag, ok := m.Tags[tag]
if ok {
key = nextTag + "." + key
}
}
data := fmt.Sprintf("%v", m.Data)
logger.Debug("Metric ready to send %s:%s", key, data)
giteMetrics[i] = graphite.NewMetric(key, data, m.Timestamp.Unix())
}
err = gite.SendMetrics(giteMetrics)
if err != nil {
logger.Errorf("Unable to send metrics. Error: %s", err)
return fmt.Errorf("Unable to send metrics. Error: %s", err)
}
logger.Debug("Metrics sent to Graphite.")
return nil
}