本文整理匯總了Golang中fullerite/config.ReadConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadConfig函數的具體用法?Golang ReadConfig怎麽用?Golang ReadConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ReadConfig函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: start
func start(ctx *cli.Context) {
if ctx.Bool("profile") {
pcfg := profile.Config{
CPUProfile: true,
MemProfile: true,
BlockProfile: true,
ProfilePath: ".",
}
p := profile.Start(&pcfg)
defer p.Stop()
}
initLogrus(ctx)
log.Info("Starting fullerite...")
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
collectors := startCollectors(c)
handlers := startHandlers(c)
internalServer := internalserver.New(c, &handlers)
go internalServer.Run()
metrics := make(chan metric.Metric)
readFromCollectors(collectors, metrics)
hook := NewLogErrorHook(metrics)
log.Logger.Hooks.Add(hook)
relayMetricsToHandlers(handlers, metrics)
}
示例2: start
func start(ctx *cli.Context) {
if ctx.Bool("profile") {
defer profile.Start(profile.CPUProfile).Stop()
defer profile.Start(profile.MemProfile).Stop()
defer profile.Start(profile.BlockProfile).Stop()
defer profile.Start(profile.ProfilePath("."))
}
quit := make(chan bool)
initLogrus(ctx)
log.Info("Starting fullerite...")
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
handlers := createHandlers(c)
hook := NewLogErrorHook(handlers)
log.Logger.Hooks.Add(hook)
startHandlers(handlers)
collectors := startCollectors(c)
collectorStatChan := make(chan metric.CollectorEmission)
internalServer := internalserver.New(c,
handlerStatFunc(handlers),
readCollectorStat(collectorStatChan))
go internalServer.Run()
readFromCollectors(collectors, handlers, collectorStatChan)
<-quit
}
示例3: start
func start(ctx *cli.Context) {
if ctx.Bool("profile") {
pcfg := profile.Config{
CPUProfile: true,
MemProfile: true,
BlockProfile: true,
ProfilePath: ".",
}
p := profile.Start(&pcfg)
defer p.Stop()
}
initLogrus(ctx)
log.Info("Starting fullerite...")
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
collectors := startCollectors(c)
handlers := startHandlers(c)
metrics := make(chan metric.Metric)
readFromCollectors(collectors, metrics)
for metric := range metrics {
// Writing to handlers' channels. Sending metrics is
// handled asynchronously in handlers' Run functions.
writeToHandlers(handlers, metric)
}
}
示例4: TestStartCollectorsMixedConfig
func TestStartCollectorsMixedConfig(t *testing.T) {
logrus.SetLevel(logrus.ErrorLevel)
conf, _ := config.ReadConfig(tmpTestFakeFile)
collectors := startCollectors(conf)
for _, c := range collectors {
assert.Equal(t, c.Name(), "Test", "Only create valid collectors")
}
}
示例5: visualize
func visualize(ctx *cli.Context) {
initLogrus(ctx)
log.Info("Visualizing fullerite...")
if len(ctx.Args()) == 0 {
log.Error("You need a collector file to visualize!, see 'fullerite help visualize'")
return
}
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
// Setup AdHoc Collector config from context and args
collectorFile, _ := filepath.Abs(ctx.Args()[0])
configMap := make(map[string]interface{})
configMap["interval"] = ctx.Int("interval")
configMap["collectorFile"] = collectorFile
// Start collector and handlers
collector := startCollector("AdHoc", c, configMap)
handlers := startHandlers(c)
// Create channel for incoming metrics
metrics := make(chan metric.Metric)
defer close(metrics)
// Read the metrics from the AdHoc collector
go readFromCollector(collector, metrics)
go relayMetricsToHandlers(handlers, metrics)
// Stop collecting after `die-after` duration expires
quitChannel := make(chan bool, 1)
defer close(quitChannel)
dieAfter := time.Duration(ctx.Int("die-after"))
time.AfterFunc(dieAfter*time.Second, func() {
log.Info("Quitting...")
quitChannel <- true
})
// Wait to quit
for {
select {
case <-quitChannel:
return
}
}
}
示例6: start
func start(ctx *cli.Context) {
initLogrus(ctx)
log.Info("Starting beatit...")
runtime.GOMAXPROCS(runtime.NumCPU())
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
var handlers []handler.Handler
for i := 0; i < ctx.Int("num-tasks"); i++ {
if ctx.Bool("graphite") {
h := newHandler("Graphite", c, ctx.Int("num-datapoints"))
go h.Run()
handlers = append(handlers, h)
}
if ctx.Bool("signalfx") {
h := newHandler("SignalFx", c, ctx.Int("num-datapoints"))
go h.Run()
handlers = append(handlers, h)
}
if ctx.Bool("datadog") {
h := newHandler("Datadog", c, ctx.Int("num-datapoints"))
go h.Run()
handlers = append(handlers, h)
}
}
t := time.Tick(1 * time.Second)
count := 0
for _ = range t {
if count++; count > ctx.Int("time") {
os.Exit(0)
}
metrics := generateMetrics(ctx.String("prefix"),
ctx.Int("num-metrics"),
ctx.Int("num-datapoints"),
ctx.Bool("randomize"))
for _, h := range handlers {
go sendMetrics(h, metrics)
}
}
}
示例7: TestParseBadConfig
func TestParseBadConfig(t *testing.T) {
_, err := config.ReadConfig(tmpTestBadFile)
assert.NotNil(t, err, "should fail")
}
示例8: TestParseGoodConfig
func TestParseGoodConfig(t *testing.T) {
_, err := config.ReadConfig(tmpTestGoodFile)
assert.Nil(t, err, "should succeed")
}