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


Golang utils.MeasureT函数代码示例

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


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

示例1: GetBuckets

func GetBuckets(token string, min, max time.Time) ([]*Bucket, error) {
	var buckets []*Bucket
	startQuery := time.Now()
	rows, err := db.PGR.Query("select name, bucket, source, token, vals from metrics where token = $1 and bucket > $2 and bucket <= $3 order by bucket desc",
		token, min, max)
	if err != nil {
		return nil, err
	}
	utils.MeasureT(startQuery, "buckets.get-all")

	startParse := time.Now()
	defer rows.Close()
	for rows.Next() {
		var tmp []byte
		b := new(Bucket)
		buckets = append(buckets, b)
		rows.Scan(&b.Name, &b.Time, &b.Source, &b.Token, &tmp)
		if len(tmp) == 0 {
			b.Vals = []float64{}
			continue
		}
		encoding.DecodeArray(tmp, &b.Vals)
	}
	utils.MeasureT(startParse, "buckets.vals.decode")
	return buckets, nil
}
开发者ID:freeformz,项目名称:l2met,代码行数:26,代码来源:bucket.go

示例2: recieveLogs

func recieveLogs(w http.ResponseWriter, r *http.Request, ch chan<- *store.Bucket) {
	defer utils.MeasureT(time.Now(), "http-receiver")
	if r.Method != "POST" {
		http.Error(w, "Invalid Request", 400)
		return
	}
	defer r.Body.Close()
	token, err := utils.ParseToken(r)
	if err != nil {
		utils.MeasureE("http-auth", err)
		http.Error(w, "Invalid Request", 400)
		return
	}
	defer utils.MeasureT(time.Now(), token+"-http-receive")

	buckets, err := store.NewBucket(token, bufio.NewReader(r.Body))
	if err != nil {
		http.Error(w, "Invalid Request", 400)
		return
	}

	for i := range buckets {
		ch <- buckets[i]
	}
}
开发者ID:freeformz,项目名称:l2met,代码行数:25,代码来源:main.go

示例3: GetMetrics

func GetMetrics(token, name string, resolution int64, min, max time.Time) ([]*Metric, error) {
	startQuery := time.Now()
	rows, err := db.PGR.Query("select * from get_metrics($1, $2, $3, $4, $5)",
		token, name, resolution, min, max)
	if err != nil {
		utils.MeasureE("get-metrics-error", err)
		return nil, err
	}
	utils.MeasureT(startQuery, "get-metrics.query")
	startParse := time.Now()
	defer rows.Close()
	var metrics []*Metric
	for rows.Next() {
		startLoop := time.Now()
		var tmp []byte
		b := new(Bucket)
		rows.Scan(&b.Name, &b.Source, &b.Time, &tmp)
		if len(tmp) == 0 {
			b.Vals = []float64{}
			continue
		}
		encoding.DecodeArray(tmp, &b.Vals)
		m := new(Metric)
		m.Time = b.Time
		m.Name = b.Name
		m.Source = b.Source
		m.Mean = b.Mean()
		metrics = append(metrics, m)
		utils.MeasureT(startLoop, "get-metrics.scan-struct-loop")
	}
	utils.MeasureT(startParse, "parse.get-metrics")
	return metrics, nil
}
开发者ID:freeformz,项目名称:l2met,代码行数:33,代码来源:bucket.go

示例4: GetMetrics

func GetMetrics(token, name string, resolution int64, min, max time.Time) ([]*Metric, error) {
	defer utils.MeasureT("get-metrics", time.Now())

	rows, err := pg.Query("select * from get_buckets($1, $2, $3, $4, $5)",
		token, name, resolution, min, max)

	if err != nil {
		return nil, err
	}

	defer rows.Close()
	var metrics []*Metric
	for rows.Next() {
		var tmp []byte
		k := BKey{}
		rows.Scan(&k.Name, &k.Source, &k.Time, &tmp)
		b := Bucket{Key: k}

		if len(tmp) == 0 {
			b.Vals = []float64{}
			continue
		}
		encoding.DecodeArray(tmp, &b.Vals, '{', '}', ',')
		m := new(Metric)
		m.Time = k.Time
		m.Name = k.Name
		m.Source = k.Source
		m.Mean = b.Mean()
		metrics = append(metrics, m)
	}

	return metrics, nil
}
开发者ID:Epictetus,项目名称:l2met,代码行数:33,代码来源:metric.go

示例5: ScanBuckets

func ScanBuckets(mailbox string) <-chan *Bucket {
	buckets := make(chan *Bucket)

	go func(ch chan *Bucket) {
		defer utils.MeasureT("redis.scan-buckets", time.Now())
		defer close(ch)

		rc := redisPool.Get()
		defer rc.Close()

		rc.Send("MULTI")
		rc.Send("SMEMBERS", mailbox)
		rc.Send("DEL", mailbox)
		reply, err := redis.Values(rc.Do("EXEC"))
		if err != nil {
			fmt.Printf("at=%q error=%s\n", "redset-smembers", err)
			return
		}

		var delCount int64
		var members []string
		redis.Scan(reply, &members, &delCount)
		for _, member := range members {
			k, err := ParseKey(member)
			if err != nil {
				fmt.Printf("at=parse-key error=%s\n", err)
				continue
			}
			ch <- &Bucket{Key: *k}
		}
	}(buckets)

	return buckets
}
开发者ID:Epictetus,项目名称:l2met,代码行数:34,代码来源:bucket.go

示例6: Put

func (b *Bucket) Put(partitions uint64) error {
	defer utils.MeasureT("bucket.put", time.Now())

	b.Lock()
	vals := b.Vals
	key := b.String()
	partition := b.Partition([]byte(key), partitions)
	b.Unlock()

	rc := redisPool.Get()
	defer rc.Close()
	libratoMailBox := fmt.Sprintf("librato_outlet.%d", partition)
	//pgMailBox := fmt.Sprintf("postgres_outlet.%d", partition)

	rc.Send("MULTI")
	rc.Send("RPUSH", key, vals)
	rc.Send("EXPIRE", key, 300)
	rc.Send("SADD", libratoMailBox, key)
	rc.Send("EXPIRE", libratoMailBox, 300)
	//rc.Send("SADD", pgMailBox, key)
	//rc.Send("EXPIRE", pgMailBox, 300)
	_, err := rc.Do("EXEC")
	if err != nil {
		return err
	}
	return nil
}
开发者ID:Epictetus,项目名称:l2met,代码行数:27,代码来源:bucket.go

示例7: Putback

func (s *RedisStore) Putback(partition string, id *bucket.Id) error {
	defer utils.MeasureT("bucket.putback", time.Now())
	rc := s.redisPool.Get()
	defer rc.Close()
	_, err := rc.Do("SADD", partition, id.String())
	return err
}
开发者ID:raphweiner,项目名称:l2met,代码行数:7,代码来源:redis_store.go

示例8: post

func (l *LibratoOutlet) post(u, p string, body *bytes.Buffer) error {
	defer utils.MeasureT("librato-post", time.Now())
	req, err := http.NewRequest("POST", libratoUrl, body)
	if err != nil {
		return err
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("User-Agent", "l2met/0")
	req.SetBasicAuth(u, p)
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode/100 != 2 {
		var m string
		s, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			m = fmt.Sprintf("error=failed-request code=%d", resp.StatusCode)
		} else {
			m = fmt.Sprintf("error=failed-request code=%d resp=body=%s req-body=%s",
				resp.StatusCode, s, body)
		}
		return errors.New(m)
	}
	return nil
}
开发者ID:heroku,项目名称:l2met,代码行数:27,代码来源:librato_outlet.go

示例9: getBuckets

func getBuckets(w http.ResponseWriter, r *http.Request) {
	defer utils.MeasureT(time.Now(), "get-buckets")

	if r.Method != "GET" {
		http.Error(w, "Invalid Request", 400)
		return
	}

	token, err := utils.ParseToken(r)
	if err != nil {
		errmsg := map[string]string{"error": "Missing authorization."}
		utils.WriteJson(w, 401, errmsg)
		return
	}

	q := r.URL.Query()
	limit, err := strconv.ParseInt(q.Get("limit"), 10, 32)
	if err != nil {
		errmsg := map[string]string{"error": "Missing limit parameter."}
		utils.WriteJson(w, 400, errmsg)
		return
	}

	max := utils.RoundTime(time.Now(), time.Minute)
	min := max.Add(-1 * time.Minute * time.Duration(limit))
	buckets, err := store.GetBuckets(token, min, max)
	if err != nil {
		errmsg := map[string]string{"error": "Unable to find buckets"}
		utils.WriteJson(w, 500, errmsg)
		return
	}
	utils.WriteJson(w, 200, buckets)
}
开发者ID:freeformz,项目名称:l2met,代码行数:33,代码来源:main.go

示例10: NewBucket

func NewBucket(token string, rdr *bufio.Reader) <-chan *Bucket {
	buckets := make(chan *Bucket, 1000)
	go func(c chan<- *Bucket) {
		defer close(c)
		defer utils.MeasureT("new-bucket", time.Now())
		lp := logplex.NewReader(rdr)
		for {
			packet, err := lp.ReadMsg()
			if err != nil {
				if err == io.EOF {
					break
				}
				fmt.Printf("at=logplex-error err=%s\n", err)
				return
			}
			d, err := encoding.ParseMsgData(packet.Msg)
			if err != nil {
				continue
			}

			name, ok := d["measure"]
			if !ok {
				continue
			}

			source, ok := d["source"]
			if !ok {
				source = ""
			}

			var val float64
			tmpVal, ok := d["val"]
			if ok {
				val, err = strconv.ParseFloat(tmpVal, 64)
				if err != nil {
					fmt.Printf("at=error error=\"unable to parse val.\"\n")
					continue
				}
			} else {
				val = float64(1)
			}

			t, err := packet.Time()
			if err != nil {
				fmt.Printf("at=time-error error=%s\n", err)
				continue
			}
			t = utils.RoundTime(t, time.Minute)

			k := BKey{Token: token, Name: name, Source: source, Time: t}
			b := &Bucket{Key: k}
			b.Vals = append(b.Vals, val)
			c <- b
		}
	}(buckets)
	return buckets
}
开发者ID:Epictetus,项目名称:l2met,代码行数:57,代码来源:bucket.go

示例11: fetch

func fetch(t time.Time, outbox chan<- *store.Bucket) {
	fmt.Printf("at=start_fetch minute=%d\n", t.Minute())
	defer utils.MeasureT("postgres_outlet.fetch", time.Now())

	mailbox := fmt.Sprintf("postgres_outlet.%d", partitionId)
	for bucket := range store.ScanBuckets(mailbox) {
		outbox <- bucket
	}
}
开发者ID:ericfode,项目名称:l2met,代码行数:9,代码来源:main.go

示例12: allBucketIds

func allBucketIds(min, max time.Time) ([]int64, error) {
	var buckets []int64
	startQuery := time.Now()
	r, err := db.PGR.Query("select id from metrics where bucket >= $1 and bucket < $2 order by bucket desc",
		min, max)
	if err != nil {
		return nil, err
	}
	utils.MeasureT(startQuery, "metrics.query")
	startParse := time.Now()
	defer r.Close()
	for r.Next() {
		var id int64
		r.Scan(&id)
		buckets = append(buckets, id)
	}
	utils.MeasureT(startParse, "metrics.vals.parse")
	return buckets, nil
}
开发者ID:freeformz,项目名称:l2met,代码行数:19,代码来源:main.go

示例13: getMetrics

func getMetrics(w http.ResponseWriter, r *http.Request) {
	defer utils.MeasureT("http-metrics", time.Now())

	// Support CORS.
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Authorization")
	w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
	if r.Method == "OPTIONS" {
		return
	}

	names := metricsPat.FindStringSubmatch(r.URL.Path)
	if len(names) < 2 {
		fmt.Printf("at=error error=%q\n", "Name parameter not provided.")
		errmsg := map[string]string{"error": "Name parameter not provided."}
		utils.WriteJson(w, 401, errmsg)
		return
	}
	name := names[1]

	token, err := utils.ParseToken(r)
	if err != nil {
		fmt.Printf("at=error error=%q\n", err)
		errmsg := map[string]string{"error": "Missing authorization."}
		utils.WriteJson(w, 401, errmsg)
		return
	}

	q := r.URL.Query()
	limit, err := strconv.ParseInt(q.Get("limit"), 10, 32)
	if err != nil {
		errmsg := map[string]string{"error": "Missing limit parameter."}
		utils.WriteJson(w, 400, errmsg)
		return
	}

	resolution, err := strconv.ParseInt(q.Get("resolution"), 10, 32)
	if err != nil {
		errmsg := map[string]string{"error": "Missing resolution parameter."}
		utils.WriteJson(w, 400, errmsg)
		return
	}

	max := utils.RoundTime(time.Now(), (time.Minute * time.Duration(resolution)))
	min := max.Add(-1 * time.Minute * time.Duration(limit*resolution))

	metrics, err := store.GetMetrics(token, name, resolution, min, max)
	if err != nil {
		errmsg := map[string]string{"error": "Unable to find metrics."}
		utils.WriteJson(w, 500, errmsg)
		return
	}
	utils.WriteJson(w, 200, metrics)
}
开发者ID:Epictetus,项目名称:l2met,代码行数:54,代码来源:main.go

示例14: CacheGet

func CacheGet(c Cachable) ([]byte, bool) {
	defer utils.MeasureT(time.Now(), "cache-get")
	rc := rp.Get()
	defer rc.Close()
	bs, err := redis.Bytes(rc.Do("GET", c.Key()))
	if err != nil {
		utils.MeasureE("redis-get", err)
		return nil, false
	}
	return bs, true
}
开发者ID:freeformz,项目名称:l2met,代码行数:11,代码来源:cache.go

示例15: fetch

func fetch(t time.Time, outbox chan<- *store.Bucket) {
	fmt.Printf("at=start_fetch minute=%d\n", t.Minute())
	defer utils.MeasureT("postgres_outlet.fetch", time.Now())

	pid, err := utils.LockPartition("postgres_outlet", numPartitions, lockTTL)
	if err != nil {
		log.Fatal("Unable to lock partition.")
	}

	mailbox := fmt.Sprintf("postgres_outlet.%d", pid)
	for bucket := range store.ScanBuckets(mailbox) {
		outbox <- bucket
	}
}
开发者ID:Epictetus,项目名称:l2met,代码行数:14,代码来源:main.go


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