MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Start

Method Start

internal/metrics/task_kv.go:261–312  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

259}
260
261func (this *KVTask) Start() error {
262 // 读取数据
263 this.statsTicker = utils.NewTicker(1 * time.Minute)
264 if Tea.IsTesting() {
265 this.statsTicker = utils.NewTicker(10 * time.Second)
266 }
267 goman.New(func() {
268 for this.statsTicker.Next() {
269 var tr = trackers.Begin("METRIC:DUMP_STATS_TO_LOCAL_DATABASE")
270
271 this.statsLocker.Lock()
272 var statsMap = this.statsMap
273 this.statsMap = map[string]*Stat{}
274 this.statsLocker.Unlock()
275
276 for _, stat := range statsMap {
277 err := this.InsertStat(stat)
278 if err != nil {
279 remotelogs.Error("METRIC", "insert stat failed: "+err.Error())
280 }
281 }
282
283 tr.End()
284 }
285 })
286
287 // 清理
288 this.cleanTicker = time.NewTicker(24 * time.Hour)
289 goman.New(func() {
290 idles.RunTicker(this.cleanTicker, func() {
291 var tr = trackers.Begin("METRIC:CLEAN_EXPIRED")
292 err := this.CleanExpired()
293 tr.End()
294 if err != nil {
295 remotelogs.Error("METRIC", "clean expired stats failed: "+err.Error())
296 }
297 })
298 })
299
300 // 上传
301 this.uploadTicker = utils.NewTicker(this.itemConfig.UploadDuration())
302 goman.New(func() {
303 for this.uploadTicker.Next() {
304 err := this.Upload(1 * time.Second)
305 if err != nil && !rpc.IsConnError(err) {
306 remotelogs.Error("METRIC", "upload stats failed: "+err.Error())
307 }
308 }
309 })
310
311 return nil
312}
313
314func (this *KVTask) Stop() error {
315 this.isStopped = true

Callers

nothing calls this directly

Calls 14

InsertStatMethod · 0.95
CleanExpiredMethod · 0.95
UploadMethod · 0.95
NewTickerFunction · 0.92
NewFunction · 0.92
BeginFunction · 0.92
ErrorFunction · 0.92
RunTickerFunction · 0.92
IsConnErrorFunction · 0.92
NextMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected