本文整理汇总了Golang中github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin.Config.GetBool方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.GetBool方法的具体用法?Golang Config.GetBool怎么用?Golang Config.GetBool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin.Config
的用法示例。
在下文中一共展示了Config.GetBool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Publish
func (f *filePublisher) Publish(metrics []plugin.Metric, config plugin.Config) error {
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
if _, err := config.GetBool(debug); err == nil {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.Debug("publishing started")
filename, err := config.GetString("file")
if err != nil {
log.Error(err)
return err
}
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
defer file.Close()
if err != nil {
log.Error(err)
return err
}
log.WithFields(log.Fields{
"file": filename,
"metrics-published-count": len(metrics),
}).Debug("metrics published")
w := bufio.NewWriter(file)
for _, m := range metrics {
formattedTags := formatMetricTagsAsString(m.Tags)
w.WriteString(fmt.Sprintf("%v|%v|%v|%v\n", m.Timestamp, m.Namespace, m.Data, formattedTags))
}
w.Flush()
return nil
}
示例2: GetMetricTypes
// GetMetricTypes returns metric types for testing
func (f *Mock) GetMetricTypes(cfg plugin.Config) ([]plugin.Metric, error) {
mts := []plugin.Metric{}
if _, err := cfg.GetBool("test-fail"); err == nil {
return mts, fmt.Errorf("testing")
}
if _, err := cfg.GetBool("test"); err == nil {
mts = append(mts, plugin.Metric{
Namespace: plugin.NewNamespace("intel", "mock", "test"),
Description: "mock description",
Unit: "mock unit",
})
}
if _, err := cfg.GetBool("test-less"); err != nil {
mts = append(mts, plugin.Metric{
Namespace: plugin.NewNamespace("intel", "mock", "foo"),
Description: "mock description",
Unit: "mock unit",
})
}
mts = append(mts, plugin.Metric{
Namespace: plugin.NewNamespace("intel", "mock", "bar"),
Description: "mock description",
Unit: "mock unit",
})
mts = append(mts, plugin.Metric{
Namespace: plugin.NewNamespace("intel", "mock").
AddDynamicElement("host", "name of the host").
AddStaticElement("baz"),
Description: "mock description",
Unit: "mock unit",
})
return mts, nil
}
示例3: Process
func (p *passthruProcessor) Process(metrics []plugin.Metric, config plugin.Config) ([]plugin.Metric, error) {
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
if _, err := config.GetBool(debug); err == nil {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.Debug("processing started")
if _, err := config.GetBool("test"); err == nil {
log.Debug("test configuration found")
for idx, m := range metrics {
if m.Namespace.Strings()[0] == "foo" {
log.Print("found foo metric")
metrics[idx].Data = 2
}
}
}
return metrics, nil
}