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


Golang plugins.Accumulator类代码示例

本文整理汇总了Golang中github.com/influxdb/telegraf/plugins.Accumulator的典型用法代码示例。如果您正苦于以下问题:Golang Accumulator类的具体用法?Golang Accumulator怎么用?Golang Accumulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: gatherServer

func (m *Memcached) gatherServer(
	address string,
	unix bool,
	acc plugins.Accumulator,
) error {
	var conn net.Conn
	if unix {
		conn, err := net.DialTimeout("unix", address, defaultTimeout)
		if err != nil {
			return err
		}
		defer conn.Close()
	} else {
		_, _, err := net.SplitHostPort(address)
		if err != nil {
			address = address + ":11211"
		}

		conn, err = net.DialTimeout("tcp", address, defaultTimeout)
		if err != nil {
			return err
		}
		defer conn.Close()
	}

	// Extend connection
	conn.SetDeadline(time.Now().Add(defaultTimeout))

	// Read and write buffer
	rw := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn))

	// Send command
	if _, err := fmt.Fprint(rw, "stats\r\n"); err != nil {
		return err
	}
	if err := rw.Flush(); err != nil {
		return err
	}

	values, err := parseResponse(rw.Reader)
	if err != nil {
		return err
	}

	// Add server address as a tag
	tags := map[string]string{"server": address}

	// Process values
	for _, key := range sendMetrics {
		if value, ok := values[key]; ok {
			// Mostly it is the number
			if iValue, errParse := strconv.ParseInt(value, 10, 64); errParse != nil {
				acc.Add(key, value, tags)
			} else {
				acc.Add(key, iValue, tags)
			}
		}
	}
	return nil
}
开发者ID:timjwright,项目名称:telegraf,代码行数:60,代码来源:memcached.go

示例2: processStat

// Process Twemproxy server stats
func (ti *TwemproxyInstance) processStat(
	acc plugins.Accumulator,
	tags map[string]string,
	data map[string]interface{},
) {
	if source, ok := data["source"]; ok {
		if val, ok := source.(string); ok {
			tags["source"] = val
		}
	}

	metrics := []string{"total_connections", "curr_connections", "timestamp"}
	for _, m := range metrics {
		if value, ok := data[m]; ok {
			if val, ok := value.(float64); ok {
				acc.Add(m, val, tags)
			}
		}
	}

	for _, pool := range ti.Pools {
		if poolStat, ok := data[pool]; ok {
			if data, ok := poolStat.(map[string]interface{}); ok {
				poolTags := copyTags(tags)
				poolTags["pool"] = pool
				ti.processPool(acc, poolTags, pool+"_", data)
			}
		}
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:31,代码来源:twemproxy.go

示例3: gatherPoolStats

func gatherPoolStats(pool poolInfo, acc plugins.Accumulator) error {
	lines, err := internal.ReadLines(pool.ioFilename)
	if err != nil {
		return err
	}

	if len(lines) != 3 {
		return err
	}

	keys := strings.Fields(lines[1])
	values := strings.Fields(lines[2])

	keyCount := len(keys)

	if keyCount != len(values) {
		return fmt.Errorf("Key and value count don't match Keys:%v Values:%v", keys, values)
	}

	tag := map[string]string{"pool": pool.name}

	for i := 0; i < keyCount; i++ {
		value, err := strconv.ParseInt(values[i], 10, 64)
		if err != nil {
			return err
		}

		acc.Add(keys[i], value, tag)
	}

	return nil
}
开发者ID:timjwright,项目名称:telegraf,代码行数:32,代码来源:zfs.go

示例4: gatherUrl

func (n *Mesos) gatherUrl(addr *url.URL, acc plugins.Accumulator) error {
	resp, err := client.Get(fmt.Sprintf("%s/metrics/snapshot", addr.String()))
	if err != nil {
		return fmt.Errorf("Unabale to make HTTP request %s: %v", addr.String(), err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("Unexpected HTTP status %s: %v", addr.String(), resp.Status)
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	metrics := map[string]interface{}{}
	if err := json.Unmarshal(body, &metrics); err != nil {
		return err
	}

	tags := getTags(addr)

	for k, v := range metrics {
		name := strings.Replace(k, "/", "_", -1)
		acc.Add(name, v.(float64), tags)
	}

	return nil
}
开发者ID:rzagabe,项目名称:telegraf,代码行数:29,代码来源:mesos.go

示例5: Gather

func (z *Zfs) Gather(acc plugins.Accumulator) error {
	kstatMetrics := z.KstatMetrics
	if len(kstatMetrics) == 0 {
		kstatMetrics = []string{"arcstats", "zfetchstats", "vdev_cache_stats"}
	}

	kstatPath := z.KstatPath
	if len(kstatPath) == 0 {
		kstatPath = "/proc/spl/kstat/zfs"
	}

	tags := getTags(kstatPath)

	for _, metric := range kstatMetrics {
		lines, err := internal.ReadLines(kstatPath + "/" + metric)
		if err != nil {
			return err
		}
		for i, line := range lines {
			if i == 0 || i == 1 {
				continue
			}
			if len(line) < 1 {
				continue
			}
			rawData := strings.Split(line, " ")
			key := metric + "_" + rawData[0]
			rawValue := rawData[len(rawData)-1]
			value, _ := strconv.ParseInt(rawValue, 10, 64)
			acc.Add(key, value, tags)
		}
	}
	return nil
}
开发者ID:rzagabe,项目名称:telegraf,代码行数:34,代码来源:zfs.go

示例6: processPool

// Process pool data in Twemproxy stats
func (ti *TwemproxyInstance) processPool(
	acc plugins.Accumulator,
	tags map[string]string,
	prefix string,
	data map[string]interface{},
) {
	serverTags := make(map[string]map[string]string)

	for key, value := range data {
		switch key {
		case "client_connections", "forward_error", "client_err", "server_ejects", "fragments", "client_eof":
			if val, ok := value.(float64); ok {
				acc.Add(prefix+key, val, tags)
			}
		default:
			if data, ok := value.(map[string]interface{}); ok {
				if _, ok := serverTags[key]; !ok {
					serverTags[key] = copyTags(tags)
					serverTags[key]["server"] = key
				}
				ti.processServer(acc, serverTags[key], prefix, data)
			}
		}
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:26,代码来源:twemproxy.go

示例7: AddEngineStats

func (e *Engine) AddEngineStats(keys []string, acc plugins.Accumulator, tags map[string]string) {
	engine := reflect.ValueOf(e).Elem()
	for _, key := range keys {
		acc.Add(
			key,
			engine.FieldByName(engineStats[key]).Interface(),
			tags,
		)
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:10,代码来源:rethinkdb_data.go

示例8: Gather

func (k *Kafka) Gather(acc plugins.Accumulator) error {
	k.Lock()
	defer k.Unlock()
	npoints := len(k.pointChan)
	for i := 0; i < npoints; i++ {
		point := <-k.pointChan
		acc.AddFields(point.Name(), point.Fields(), point.Tags(), point.Time())
	}
	return nil
}
开发者ID:demon-xxi,项目名称:telegraf,代码行数:10,代码来源:kafka_consumer.go

示例9: add

func (d *MongodbData) add(acc plugins.Accumulator, key string, val interface{}) {
	acc.AddValuesWithTime(
		key,
		map[string]interface{}{
			"value": val,
		},
		d.Tags,
		d.StatLine.Time,
	)
}
开发者ID:nickscript0,项目名称:telegraf,代码行数:10,代码来源:mongodb_data.go

示例10: processResponse

// Flattens the map generated from the JSON object and stores its float values using a
// plugins.Accumulator. It ignores any non-float values.
// Parameters:
//     acc: the Accumulator to use
//     prefix: What the name of the measurement name should be prefixed by.
//     tags: telegraf tags to
func processResponse(acc plugins.Accumulator, prefix string, tags map[string]string, v interface{}) {
	switch t := v.(type) {
	case map[string]interface{}:
		for k, v := range t {
			processResponse(acc, prefix+"_"+k, tags, v)
		}
	case float64:
		acc.Add(prefix, v, tags)
	}
}
开发者ID:kokarn,项目名称:telegraf,代码行数:16,代码来源:httpjson.go

示例11: Gather

func (s *SystemStats) Gather(acc plugins.Accumulator) error {
	lv, err := s.ps.LoadAvg()
	if err != nil {
		return err
	}

	acc.Add("load1", lv.Load1, nil)
	acc.Add("load5", lv.Load5, nil)
	acc.Add("load15", lv.Load15, nil)

	return nil
}
开发者ID:tylernisonoff,项目名称:telegraf,代码行数:12,代码来源:system.go

示例12: importMetric

// Import HTTP stat data into Telegraf system
func importMetric(r io.Reader, acc plugins.Accumulator, host string) (poolStat, error) {
	stats := make(poolStat)
	var currentPool string

	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		statLine := scanner.Text()
		keyvalue := strings.Split(statLine, ":")

		if len(keyvalue) < 2 {
			continue
		}
		fieldName := strings.Trim(keyvalue[0], " ")
		// We start to gather data for a new pool here
		if fieldName == PF_POOL {
			currentPool = strings.Trim(keyvalue[1], " ")
			stats[currentPool] = make(metric)
			continue
		}

		// Start to parse metric for current pool
		switch fieldName {
		case PF_ACCEPTED_CONN,
			PF_LISTEN_QUEUE,
			PF_MAX_LISTEN_QUEUE,
			PF_LISTEN_QUEUE_LEN,
			PF_IDLE_PROCESSES,
			PF_ACTIVE_PROCESSES,
			PF_TOTAL_PROCESSES,
			PF_MAX_ACTIVE_PROCESSES,
			PF_MAX_CHILDREN_REACHED,
			PF_SLOW_REQUESTS:
			fieldValue, err := strconv.ParseInt(strings.Trim(keyvalue[1], " "), 10, 64)
			if err == nil {
				stats[currentPool][fieldName] = fieldValue
			}
		}
	}

	// Finally, we push the pool metric
	for pool := range stats {
		tags := map[string]string{
			"url":  host,
			"pool": pool,
		}
		for k, v := range stats[pool] {
			acc.Add(strings.Replace(k, " ", "_", -1), v, tags)
		}
	}

	return stats, nil
}
开发者ID:realgo,项目名称:telegraf,代码行数:53,代码来源:phpfpm.go

示例13: Gather

func (s *NetIOStats) Gather(acc plugins.Accumulator) error {
	netio, err := s.ps.NetIO()
	if err != nil {
		return fmt.Errorf("error getting net io info: %s", err)
	}

	for _, io := range netio {
		if len(s.Interfaces) != 0 {
			var found bool

			for _, name := range s.Interfaces {
				if name == io.Name {
					found = true
					break
				}
			}

			if !found {
				continue
			}
		} else if !s.skipChecks {
			iface, err := net.InterfaceByName(io.Name)
			if err != nil {
				continue
			}

			if iface.Flags&net.FlagLoopback == net.FlagLoopback {
				continue
			}

			if iface.Flags&net.FlagUp == 0 {
				continue
			}
		}

		tags := map[string]string{
			"interface": io.Name,
		}

		acc.Add("bytes_sent", io.BytesSent, tags)
		acc.Add("bytes_recv", io.BytesRecv, tags)
		acc.Add("packets_sent", io.PacketsSent, tags)
		acc.Add("packets_recv", io.PacketsRecv, tags)
		acc.Add("err_in", io.Errin, tags)
		acc.Add("err_out", io.Errout, tags)
		acc.Add("drop_in", io.Dropin, tags)
		acc.Add("drop_out", io.Dropout, tags)
	}

	return nil
}
开发者ID:nibosho,项目名称:telegraf,代码行数:51,代码来源:net.go

示例14: GetLustreProcStats

func (l *Lustre2) GetLustreProcStats(fileglob string, wanted_fields []*mapping, acc plugins.Accumulator) error {
	files, err := filepath.Glob(fileglob)
	if err != nil {
		return err
	}

	for _, file := range files {
		/* Turn /proc/fs/lustre/obdfilter/<ost_name>/stats and similar
		 * into just the object store target name
		 * Assumpion: the target name is always second to last,
		 * which is true in Lustre 2.1->2.5
		 */
		path := strings.Split(file, "/")
		name := path[len(path)-2]
		tags := map[string]string{
			"name": name,
		}

		lines, err := internal.ReadLines(file)
		if err != nil {
			return err
		}

		for _, line := range lines {
			fields := strings.Fields(line)

			for _, wanted := range wanted_fields {
				var data uint64
				if fields[0] == wanted.inProc {
					wanted_field := wanted.field
					// if not set, assume field[1]. Shouldn't be field[0], as
					// that's a string
					if wanted_field == 0 {
						wanted_field = 1
					}
					data, err = strconv.ParseUint((fields[wanted_field]), 10, 64)
					if err != nil {
						return err
					}
					report_name := wanted.inProc
					if wanted.reportAs != "" {
						report_name = wanted.reportAs
					}
					acc.Add(report_name, data, tags)

				}
			}
		}
	}
	return nil
}
开发者ID:timjwright,项目名称:telegraf,代码行数:51,代码来源:lustre2.go

示例15: gatherQueues

func gatherQueues(r *RabbitMQ, serv *Server, acc plugins.Accumulator, errChan chan error) {
	// Gather information about queues
	queues := make([]Queue, 0)
	err := r.requestJSON(serv, "/api/queues", &queues)
	if err != nil {
		errChan <- err
		return
	}

	for _, queue := range queues {
		if !shouldGatherQueue(queue, serv) {
			continue
		}
		tags := map[string]string{
			"url":         serv.URL,
			"queue":       queue.Name,
			"vhost":       queue.Vhost,
			"node":        queue.Node,
			"durable":     strconv.FormatBool(queue.Durable),
			"auto_delete": strconv.FormatBool(queue.AutoDelete),
		}

		acc.AddFields(
			"queue",
			map[string]interface{}{
				// common information
				"consumers":            queue.Consumers,
				"consumer_utilisation": queue.ConsumerUtilisation,
				"memory":               queue.Memory,
				// messages information
				"messages":                  queue.Messages,
				"messages_ready":            queue.MessagesReady,
				"messages_unack":            queue.MessagesUnacknowledged,
				"messages_ack":              queue.MessageStats.Ack,
				"messages_ack_rate":         queue.MessageStats.AckDetails.Rate,
				"messages_deliver":          queue.MessageStats.Deliver,
				"messages_deliver_rate":     queue.MessageStats.DeliverDetails.Rate,
				"messages_deliver_get":      queue.MessageStats.DeliverGet,
				"messages_deliver_get_rate": queue.MessageStats.DeliverGetDetails.Rate,
				"messages_publish":          queue.MessageStats.Publish,
				"messages_publish_rate":     queue.MessageStats.PublishDetails.Rate,
				"messages_redeliver":        queue.MessageStats.Redeliver,
				"messages_redeliver_rate":   queue.MessageStats.RedeliverDetails.Rate,
			},
			tags,
		)
	}

	errChan <- nil
}
开发者ID:rzagabe,项目名称:telegraf,代码行数:50,代码来源:rabbitmq.go


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