Пример #1
0
func point(metric string, keyval ...string) *tsdb.Point {
	point, err := tsdb.NewPoint(time.Unix(0, 0), 0, metric, keyval...)
	if err != nil {
		panic(err)
	}
	return point
}
Пример #2
0
func point(time time.Time, value interface{}, series string) *tsdb.Point {
	id := strings.Fields(strings.Replace(series, "=", " ", -1))
	point, err := tsdb.NewPoint(time, value, id[0], id[1:]...)
	if err != nil {
		log.Panicf("point: %v, time=%v value=%v series=%q id=%q", err, time, value, series, id)
	}
	return point
}
Пример #3
0
// newEmitter returns a function that emits data points for the provided
// time instant.
func newEmitter(w chan *tsdb.Point, timestamp time.Time) emitFn {
	return func(series string, value interface{}) {
		if value == nil {
			panic("zero value")
		}
		series = "netscaler." + series
		id := strings.Fields(strings.Replace(series, "=", " ", -1))
		p, err := tsdb.NewPoint(timestamp, value, id[0], id[1:]...)
		if err != nil {
			panic(err)
		}
		w <- p
	}
}
Пример #4
0
func ExportVars(t time.Time, fn func(*tsdb.Point)) {
	expvar.Do(func(kv expvar.KeyValue) {
		metric := kv.Key
		switch v := kv.Value.(type) {
		default:
			// log.Printf("tsdbutil: ExportVars: ignoring unsupported type %T for %s", v, kv.Key)

		case expvar.Func:
			if kv.Key != "memstats" {
				return
			}
			data := make(map[string]interface{})
			dec := json.NewDecoder(strings.NewReader(v.String()))
			dec.UseNumber()
			if err := dec.Decode(&data); err != nil {
				log.Print(err)
				return
			}
			for key, value := range data {
				num, ok := value.(json.Number)
				if !ok {
					continue
				}
				n, err := num.Int64()
				if err != nil {
					log.Print(err)
					continue
				}
				point, err := tsdb.NewPoint(t, n, "mem."+key)
				if err != nil {
					log.Printf("tsdbutil: ExportVars: cannot export memstats.%s: %v", key, err)
					continue
				}
				fn(point)
			}

		case *expvar.Int:
			value := kv.Value.String()
			point, err := tsdb.NewPoint(t, value, metric)
			if err != nil {
				log.Panic(err)
			}
			fn(point)

		case *expvar.Float:
			value := kv.Value.String()
			point, err := tsdb.NewPoint(t, value, metric)
			if err != nil {
				log.Panic(err)
			}
			fn(point)

		case *expvar.Map:
			v.Do(func(kv expvar.KeyValue) {
				switch kv.Value.(type) {
				default:
					// log.Printf("tsdbutil: ExportVars: ignoring unsupported type %T for key %s of %s", v2, kv2.Key, kv.Key)

				case expvar.Func:
					tags := kv.Key
					value := kv.Value
					tags = strings.Replace(tags, "=", " ", -1)
					point, err := tsdb.NewPoint(t, 0, metric, strings.Fields(tags)...)
					if err != nil {
						log.Panic(err)
					}
					if err := point.SetValue(value.String()); err != nil {
						log.Panic(err)
					}
					fn(point)

				case *expvar.Int:
					tags := kv.Key
					value := kv.Value
					tags = strings.Replace(tags, "=", " ", -1)
					point, err := tsdb.NewPoint(t, 0, metric, strings.Fields(tags)...)
					if err != nil {
						log.Panic(err)
					}
					if err := point.SetValue(value.String()); err != nil {
						log.Panic(err)
					}
					fn(point)

				case *expvar.Float:
					tags := kv.Key
					value := kv.Value
					tags = strings.Replace(tags, "=", " ", -1)
					point, err := tsdb.NewPoint(t, 0, metric, strings.Fields(tags)...)
					if err != nil {
						log.Panic(err)
					}
					if err := point.SetValue(value.String()); err != nil {
						log.Panic(err)
					}
					fn(point)
				}
			})
		}
	})
}