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


Golang Container.ChildrenMap方法代码示例

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


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

示例1: scrapeMetrics

func (e *Exporter) scrapeMetrics(json *gabs.Container, ch chan<- prometheus.Metric) {
	elements, _ := json.ChildrenMap()
	for key, element := range elements {
		switch key {
		case "message":
			log.Errorf("Problem collecting metrics: %s\n", element.Data().(string))
			return
		case "version":
			data := element.Data()
			version, ok := data.(string)
			if !ok {
				log.Errorf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for version\n", data))
			} else {
				gauge, _ := e.Gauges.Fetch("metrics_version", "Marathon metrics version", "version")
				gauge.WithLabelValues(version).Set(1)
				gauge.Collect(ch)
			}

		case "counters":
			e.scrapeCounters(element)
		case "gauges":
			e.scrapeGauges(element)
		case "histograms":
			e.scrapeHistograms(element)
		case "meters":
			e.scrapeMeters(element)
		case "timers":
			e.scrapeTimers(element)
		}
	}
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:31,代码来源:exporter.go

示例2: scrapeMeter

func (e *Exporter) scrapeMeter(key string, json *gabs.Container) (bool, error) {
	count, ok := json.Path("count").Data().(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad meter! %s has no count\n", key))
	}
	units, ok := json.Path("units").Data().(string)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad meter! %s has no units\n", key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(meterHelp, key, units)
	counter, new := e.Counters.Fetch(name+"_count", help)
	counter.WithLabelValues().Set(count)

	gauge, _ := e.Gauges.Fetch(name, help, "rate")
	properties, _ := json.ChildrenMap()
	for key, property := range properties {
		if strings.Contains(key, "rate") {
			if value, ok := property.Data().(float64); ok {
				gauge.WithLabelValues(renameRate(key)).Set(value)
			}
		}
	}

	return new, nil
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:27,代码来源:exporter.go

示例3: mergeVolumeConfig

// Merge guest volume/block device configuration with any volumes found in
// host container.
func mergeVolumeConfig(volumeconfig []volumeConfig, guest *gabs.Container) (err error) {
	var mounts *gabs.Container
	if guest.ExistsP("mount") {
		mounts = guest.S("mount")
	} else {
		mounts, _ = guest.ObjectP("mount")
	}
	mmap, _ := mounts.ChildrenMap()
	for _, mount := range mmap {
		var source string
		var path string
		var ok bool
		if source, ok = mount.Path("source").Data().(string); !ok {
			continue
		}
		if path, ok = mount.Path("path").Data().(string); !ok {
			continue
		}
		if source == "blk" && strings.HasPrefix(path, "/dev/ld") {
			return fmt.Errorf("Guest configuration defines " +
				"/dev/ld* block devices, cannot merge with " +
				"host volumes")
		}
	}
	blkIndex := 0
	for _, v := range volumeconfig {
		mp := "/" + v.name
		obj, _ := guest.Object("mount", mp)
		obj.Set("blk", "source")
		obj.Set(fmt.Sprintf("/dev/ld%va", blkIndex), "path")
		blkIndex += 1
	}
	return
}
开发者ID:sjfloat,项目名称:docker-unikernel-runner,代码行数:36,代码来源:guest.go

示例4: scrapeTimer

func (e *Exporter) scrapeTimer(key string, json *gabs.Container) (bool, error) {
	count, ok := json.Path("count").Data().(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad timer! %s has no count\n", key))
	}
	units, ok := json.Path("rate_units").Data().(string)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad timer! %s has no units\n", key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(timerHelp, key, units)
	counter, new := e.Counters.Fetch(name+"_count", help)
	counter.WithLabelValues().Set(count)

	rates, _ := e.Gauges.Fetch(name+"_rate", help, "rate")
	percentiles, _ := e.Gauges.Fetch(name, help, "percentile")
	min, _ := e.Gauges.Fetch(name+"_min", help)
	max, _ := e.Gauges.Fetch(name+"_max", help)
	mean, _ := e.Gauges.Fetch(name+"_mean", help)
	stddev, _ := e.Gauges.Fetch(name+"_stddev", help)

	properties, _ := json.ChildrenMap()
	for key, property := range properties {
		switch key {
		case "mean_rate", "m1_rate", "m5_rate", "m15_rate":
			if value, ok := property.Data().(float64); ok {
				rates.WithLabelValues(renameRate(key)).Set(value)
			}

		case "p50", "p75", "p95", "p98", "p99", "p999":
			if value, ok := property.Data().(float64); ok {
				percentiles.WithLabelValues("0." + key[1:]).Set(value)
			}
		case "min":
			if value, ok := property.Data().(float64); ok {
				min.WithLabelValues().Set(value)
			}
		case "max":
			if value, ok := property.Data().(float64); ok {
				max.WithLabelValues().Set(value)
			}
		case "mean":
			if value, ok := property.Data().(float64); ok {
				mean.WithLabelValues().Set(value)
			}
		case "stddev":
			if value, ok := property.Data().(float64); ok {
				stddev.WithLabelValues().Set(value)
			}
		}
	}

	return new, nil
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:55,代码来源:exporter.go

示例5: scrapeTimers

func (e *Exporter) scrapeTimers(json *gabs.Container) {
	elements, _ := json.ChildrenMap()
	for key, element := range elements {
		new, err := e.scrapeTimer(key, element)
		if err != nil {
			log.Debug(err)
		} else if new {
			log.Infof("Added timer %q\n", key)
		}
	}
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:11,代码来源:exporter.go


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