Esempio n. 1
0
func (c *win_pdh_collector) CollectOnce() newcore.CollectResult {
	logging.Debug("win_pdh_collector.CollectOnce Started")

	var items newcore.MultiDataPoint

	for _, pd := range c.hPdh.CollectData() {
		if pd.Err == nil {
			query, ok := c.map_queries[pd.Query]
			if ok == true {
				logging.Tracef("query: %+v, \n %+v", query.Metric, query)
				items = append(items, newcore.NewDP(c.prefix, query.Metric.Clean(), pd.Value, query.Tags, "", "", ""))
			}
		} else {
			if strings.Index(pd.Err.Error(), `\Process(hickwall)\Working Set - Private`) < 0 {
				logging.Errorf("win_pdh_collector ERROR: ", pd.Err)
			}
		}
	}

	logging.Debugf("win_pdh_collector.CollectOnce Finished. count: %d", len(items))
	return newcore.CollectResult{
		Collected: items,
		Next:      time.Now().Add(c.interval),
		Err:       nil,
	}
}
Esempio n. 2
0
func (c *heartbeat) CollectOnce() newcore.CollectResult {
	var items newcore.MultiDataPoint

	// Add(&items, "hickwall.client", "alive", 1, nil, "", "", "")
	items = append(items, newcore.NewDP("hickwall.client", "alive", 1, nil, "", "", ""))

	return newcore.CollectResult{
		Collected: items,
		Next:      time.Now().Add(c.interval),
		Err:       nil,
	}
}
Esempio n. 3
0
func (c ping_collector) CollectOnce() newcore.CollectResult {
	var (
		md       newcore.MultiDataPoint
		d        stats.Stats
		p        = fastping.NewPinger()
		rtt_chan = make(chan float64)
	)

	ip, err := net.ResolveIPAddr("ip4:icmp", c.config.Target)
	if err != nil {
		logging.Errorf("ping_collector: DNS resolve error: %v", err)
		return newcore.CollectResult{
			Collected: nil,
			Next:      time.Now().Add(c.interval),
			Err:       fmt.Errorf("ping_collector: DNS resolve error: %v", err),
		}
	}

	p.MaxRTT = c.timeout
	p.AddIPAddr(ip)
	p.OnRecv = func(addr *net.IPAddr, rtt time.Duration) {
		rtt_chan <- float64(rtt.Nanoseconds() / 1000 / 1000)
	}

	go func() {
		for i := 0; i < c.config.Packets; i++ {
			err = p.Run()
			if err != nil {
				logging.Errorf("ping_collector run err: ", err)
			}
		}
		close(rtt_chan)
	}()

	for rtt := range rtt_chan {
		d.Update(rtt)
	}

	md = append(md, newcore.NewDP(c.prefix, fmt.Sprintf("%s.%s", c.config.Metric, "time_min"), d.Min(), c.tags, "", "", ""))
	md = append(md, newcore.NewDP(c.prefix, fmt.Sprintf("%s.%s", c.config.Metric, "time_max"), d.Max(), c.tags, "", "", ""))
	md = append(md, newcore.NewDP(c.prefix, fmt.Sprintf("%s.%s", c.config.Metric, "time_avg"), d.Mean(), c.tags, "", "", ""))

	std := d.SampleStandardDeviation()
	if math.IsNaN(std) {
		std = 0
	}
	md = append(md, newcore.NewDP(c.prefix, fmt.Sprintf("%s.%s", c.config.Metric, "time_mdev"), std, c.tags, "", "", ""))
	md = append(md, newcore.NewDP(c.prefix, fmt.Sprintf("%s.%s", c.config.Metric, "ip"), ip.IP.String(), c.tags, "", "", ""))

	lost_pct := float64((c.config.Packets-d.Count())/c.config.Packets) * 100
	md = append(md, newcore.NewDP(c.prefix, fmt.Sprintf("%s.%s", c.config.Metric, "lost_pct"), lost_pct, c.tags, "", "", ""))

	return newcore.CollectResult{
		Collected: md,
		Next:      time.Now().Add(c.interval),
		Err:       nil,
	}
}
Esempio n. 4
0
func (c *hickwall_collector) CollectOnce() newcore.CollectResult {
	var md newcore.MultiDataPoint

	runtime.ReadMemStats(&mem_stats)

	md = append(md, newcore.NewDP("hickwall.client", "NumGoroutine", runtime.NumGoroutine(), nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Alloc", mem_stats.Alloc, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.TotalAlloc", mem_stats.TotalAlloc, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Heap.Sys", mem_stats.HeapSys, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Heap.Alloc", mem_stats.HeapAlloc, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Heap.Idle", mem_stats.HeapIdle, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Heap.Inuse", mem_stats.HeapInuse, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Heap.Released", mem_stats.HeapReleased, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.Heap.Objects", mem_stats.HeapObjects, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.GC.NextGC", mem_stats.NextGC, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.GC.LastGC", mem_stats.LastGC, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.GC.NumGC", mem_stats.NumGC, nil, "", "", ""))
	md = append(md, newcore.NewDP("hickwall.client", "mem.GC.EnableGC", mem_stats.EnableGC, nil, "", "", ""))

	// Add(&md, "hickwall.client", "NumGoroutine", runtime.NumGoroutine(), nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Alloc", mem_stats.Alloc, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.TotalAlloc", mem_stats.TotalAlloc, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Heap.Sys", mem_stats.HeapSys, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Heap.Alloc", mem_stats.HeapAlloc, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Heap.Idle", mem_stats.HeapIdle, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Heap.Inuse", mem_stats.HeapInuse, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Heap.Released", mem_stats.HeapReleased, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.Heap.Objects", mem_stats.HeapObjects, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.GC.NextGC", mem_stats.NextGC, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.GC.LastGC", mem_stats.LastGC, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.GC.NumGC", mem_stats.NumGC, nil, "", "", "")
	// Add(&md, "hickwall.client", "mem.GC.EnableGC", mem_stats.EnableGC, nil, "", "", "")

	return newcore.CollectResult{
		Collected: md,
		Next:      time.Now().Add(c.interval),
		Err:       nil,
	}
}
Esempio n. 5
0
func (c *win_wmi_collector) CollectOnce() (res newcore.CollectResult) {
	var items newcore.MultiDataPoint

	for _, query := range c.config.Queries {

		fields := c.get_fields_of_query(query)

		results, err := c.query(query.Query, fields)

		if err != nil {
			continue
		}

		if len(results) > 0 {
			for _, record := range results {
				for _, item := range query.Metrics {

					metric, err := c.c_win_wmi_parse_metric_key(string(item.Metric), record)
					if err != nil {
						logging.Errorf("CollectOnce: %v", err)
						continue
					}

					tags, err := c.c_win_wmi_parse_tags(item.Tags, record)
					if err != nil {
						logging.Errorf("CollectOnce: %v", err)
						continue
					}

					tags = newcore.AddTags.Copy().Merge(query.Tags).Merge(tags)

					if value, ok := record[item.Value_from]; ok == true {
						items = append(items, newcore.NewDP(c.prefix, metric, value, tags, "", "", ""))
					} else if item.Default != "" {
						items = append(items, newcore.NewDP(c.prefix, metric, item.Default, tags, "", "", ""))
					}
				}
			}
		} else {
			for _, item := range query.Metrics {
				if item.Default != "" {
					// no templating support if no data got
					if strings.Contains(string(item.Metric), "{{") {
						continue
					}
					for _, value := range item.Tags {
						if strings.Contains(value, "{{") {
							continue
						}
					}
					tags := newcore.AddTags.Copy().Merge(query.Tags).Merge(item.Tags)
					items = append(items, newcore.NewDP(c.prefix, item.Metric.Clean(), item.Default, tags, "", "",
						""))
				}
			}
		}
	} // for queries

	for _, dp := range items {
		logging.Tracef("wmi DataPoint -> %+v", dp)
	}
	return newcore.CollectResult{
		Collected: items,
		Next:      time.Now().Add(c.interval),
		Err:       nil,
	}
}