當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Timer.StepCustomTiming方法代碼示例

本文整理匯總了Golang中github.com/MiniProfiler/go/miniprofiler.Timer.StepCustomTiming方法的典型用法代碼示例。如果您正苦於以下問題:Golang Timer.StepCustomTiming方法的具體用法?Golang Timer.StepCustomTiming怎麽用?Golang Timer.StepCustomTiming使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/MiniProfiler/go/miniprofiler.Timer的用法示例。


在下文中一共展示了Timer.StepCustomTiming方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: timeTSDBRequest

func timeTSDBRequest(e *State, T miniprofiler.Timer, req *opentsdb.Request) (s opentsdb.ResponseSet, err error) {
	e.tsdbQueries = append(e.tsdbQueries, *req)
	if e.autods > 0 {
		for _, q := range req.Queries {
			if q.Downsample == "" {
				if err := req.AutoDownsample(e.autods); err != nil {
					return nil, err
				}
			}
		}
	}
	b, _ := json.MarshalIndent(req, "", "  ")
	tries := 1
	for {
		T.StepCustomTiming("tsdb", "query", string(b), func() {
			getFn := func() (interface{}, error) {
				return e.tsdbContext.Query(req)
			}
			var val interface{}
			val, err = e.cache.Get(string(b), getFn)
			s = val.(opentsdb.ResponseSet).Copy()

		})
		if err == nil || tries == tsdbMaxTries {
			break
		}
		slog.Errorf("Error on tsdb query %d: %s", tries, err.Error())
		tries++
	}
	return
}
開發者ID:noblehng,項目名稱:bosun,代碼行數:31,代碼來源:funcs.go

示例2: timeESRequest

// timeESRequest execute the elasticsearch query (which may set or hit cache) and returns
// the search results.
func timeESRequest(e *State, T miniprofiler.Timer, req *ElasticRequest) (resp *elastic.SearchResult, err error) {
	e.elasticQueries = append(e.elasticQueries, *req.Source)
	var source interface{}
	source, err = req.Source.Source()
	if err != nil {
		return resp, fmt.Errorf("failed to get source of request while timing elastic request: %s", err)
	}
	b, err := json.MarshalIndent(source, "", "  ")
	if err != nil {
		return resp, err
	}
	key, err := req.CacheKey()
	if err != nil {
		return nil, err
	}
	T.StepCustomTiming("elastic", "query", fmt.Sprintf("%v\n%s", req.Indices, b), func() {
		getFn := func() (interface{}, error) {
			return e.ElasticHosts.Query(req)
		}
		var val interface{}
		val, err = e.Cache.Get(key, getFn)
		resp = val.(*elastic.SearchResult)
	})
	return
}
開發者ID:nicollet,項目名稱:bosun,代碼行數:27,代碼來源:elastic.go

示例3: timeLSRequest

// timeLSRequest execute the elasticsearch query (which may set or hit cache) and returns
// the search results.
func timeLSRequest(e *State, T miniprofiler.Timer, req *LogstashRequest) (resp *elastic.SearchResult, err error) {
	e.logstashQueries = append(e.logstashQueries, *req.Source)
	b, _ := json.MarshalIndent(req.Source.Source(), "", "  ")
	T.StepCustomTiming("logstash", "query", string(b), func() {
		getFn := func() (interface{}, error) {
			return e.LogstashHosts.Query(req)
		}
		var val interface{}
		val, err = e.Cache.Get(string(b), getFn)
		resp = val.(*elastic.SearchResult)
	})
	return
}
開發者ID:nicollet,項目名稱:bosun,代碼行數:15,代碼來源:logstash.go

示例4: timeGraphiteRequest

func timeGraphiteRequest(e *State, T miniprofiler.Timer, req *graphite.Request) (resp graphite.Response, err error) {
	e.graphiteQueries = append(e.graphiteQueries, *req)
	b, _ := json.MarshalIndent(req, "", "  ")
	T.StepCustomTiming("graphite", "query", string(b), func() {
		key := req.CacheKey()
		getFn := func() (interface{}, error) {
			return e.graphiteContext.Query(req)
		}
		var val interface{}
		val, err = e.cache.Get(key, getFn)
		resp = val.(graphite.Response)
	})
	return
}
開發者ID:noblehng,項目名稱:bosun,代碼行數:14,代碼來源:funcs.go

示例5: timeInfluxRequest

func timeInfluxRequest(e *State, T miniprofiler.Timer, db, query, startDuration, endDuration, groupByInterval string) (s []influxModels.Row, err error) {
	q, err := influxQueryDuration(e.now, query, startDuration, endDuration, groupByInterval)
	if err != nil {
		return nil, err
	}
	conn, err := client.NewHTTPClient(e.InfluxConfig)
	if err != nil {
		return nil, err
	}
	T.StepCustomTiming("influx", "query", q, func() {
		getFn := func() (interface{}, error) {
			res, err := conn.Query(client.Query{
				Command:  q,
				Database: db,
			})
			if err != nil {
				return nil, err
			}
			if res.Error() != nil {
				return nil, res.Error()
			}
			if len(res.Results) != 1 {
				return nil, fmt.Errorf("influx: expected one result")
			}

			r := res.Results[0]
			if r.Err == "" {
				return r.Series, nil
			}
			err = fmt.Errorf(r.Err)
			return r.Series, err
		}
		var val interface{}
		var ok bool
		val, err = e.Cache.Get(q, getFn)
		if s, ok = val.([]influxModels.Row); !ok {
			err = fmt.Errorf("influx: did not get a valid result from InfluxDB")
		}
	})
	return
}
開發者ID:nicollet,項目名稱:bosun,代碼行數:41,代碼來源:influx.go

示例6: Graph


//.........這裏部分代碼省略.........
			}
			if meta == nil {
				return nil, fmt.Errorf("no metadata for %s: cannot use auto rate", q)
			}
			if meta.Unit != "" {
				m_units[q.Metric] = meta.Unit
			}
			if meta.Rate != "" {
				switch meta.Rate {
				case metadata.Gauge:
					// ignore
				case metadata.Rate:
					q.Rate = true
				case metadata.Counter:
					q.Rate = true
					q.RateOptions = opentsdb.RateOptions{
						Counter:    true,
						ResetValue: 1,
					}
				default:
					return nil, fmt.Errorf("unknown metadata rate: %s", meta.Rate)
				}
			}
		}
		queries[i] = fmt.Sprintf(`q("%v", "%v", "%v")`, q, start, end)
		if !schedule.SystemConf.GetTSDBContext().Version().FilterSupport() {
			if err := schedule.Search.Expand(q); err != nil {
				return nil, err
			}
		}
	}
	var tr opentsdb.ResponseSet
	b, _ := json.MarshalIndent(oreq, "", "  ")
	t.StepCustomTiming("tsdb", "query", string(b), func() {
		h := schedule.SystemConf.GetTSDBHost()
		if h == "" {
			err = fmt.Errorf("tsdbHost not set")
			return
		}
		tr, err = oreq.Query(h)
	})
	if err != nil {
		return nil, err
	}
	cs, err := makeChart(tr, m_units)
	if err != nil {
		return nil, err
	}
	if _, present := r.Form["png"]; present {
		c := chart.ScatterChart{
			Title: fmt.Sprintf("%v - %v", oreq.Start, queries),
		}
		c.XRange.Time = true
		if min, err := strconv.ParseFloat(r.FormValue("min"), 64); err == nil {
			c.YRange.MinMode.Fixed = true
			c.YRange.MinMode.Value = min
		}
		if max, err := strconv.ParseFloat(r.FormValue("max"), 64); err == nil {
			c.YRange.MaxMode.Fixed = true
			c.YRange.MaxMode.Value = max
		}
		for ri, r := range cs {
			pts := make([]chart.EPoint, len(r.Data))
			for idx, v := range r.Data {
				pts[idx].X = v[0]
				pts[idx].Y = v[1]
開發者ID:nicollet,項目名稱:bosun,代碼行數:67,代碼來源:chart.go

示例7: QueryRowTimer

func (d DB) QueryRowTimer(t miniprofiler.Timer, query string, args ...interface{}) (row *sql.Row) {
	t.StepCustomTiming("sql", "query", query, func() {
		row = d.DB.QueryRow(query, args...)
	})
	return
}
開發者ID:jango2015,項目名稱:go,代碼行數:6,代碼來源:sql.go

示例8: ExecTimer

func (d DB) ExecTimer(t miniprofiler.Timer, query string, args ...interface{}) (result sql.Result, err error) {
	t.StepCustomTiming("sql", "exec", query, func() {
		result, err = d.DB.Exec(query, args...)
	})
	return
}
開發者ID:jango2015,項目名稱:go,代碼行數:6,代碼來源:sql.go


注:本文中的github.com/MiniProfiler/go/miniprofiler.Timer.StepCustomTiming方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。