예제 #1
0
파일: proc_http.go 프로젝트: ketqi/nodata
func configProcHttpRoutes() {
	// counters
	http.HandleFunc("/proc/counters", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, g.GetAllCounters())
	})
	http.HandleFunc("/statistics/all", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, g.GetAllCounters())
	})

	// judge.status, /proc/status/$endpoint/$metric/$tags-pairs
	http.HandleFunc("/proc/status/", func(w http.ResponseWriter, r *http.Request) {
		urlParam := r.URL.Path[len("/proc/status/"):]
		RenderDataJson(w, judge.GetNodataStatus(urlParam))
	})

	// collector.last.item, /proc/collect/$endpoint/$metric/$tags-pairs
	http.HandleFunc("/proc/collect/", func(w http.ResponseWriter, r *http.Request) {
		urlParam := r.URL.Path[len("/proc/collect/"):]
		item, _ := collector.GetFirstItem(urlParam)
		RenderDataJson(w, item.String())
	})

	// config.mockcfg
	http.HandleFunc("/proc/config", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, service.GetMockCfgFromDB())
	})

	// config.hostgroup, /group/$grpname
	http.HandleFunc("/proc/group/", func(w http.ResponseWriter, r *http.Request) {
		urlParam := r.URL.Path[len("/proc/group/"):]
		RenderDataJson(w, service.GetHostsFromGroup(urlParam))
	})
}
예제 #2
0
파일: judge_cron.go 프로젝트: ketqi/nodata
// Do Judge
func judge() {
	now := time.Now().Unix()
	keys := config.Keys()
	for _, key := range keys {
		ndcfg, found := config.GetNdConfig(key)
		if !found { //策略不存在,不处理
			continue
		}
		step := ndcfg.Step
		mock := ndcfg.Mock

		item, found := collector.GetFirstItem(key)
		if !found { //没有数据,未开始采集,不处理
			continue
		}

		lastTs := now - getTimeout(step)
		if item.FStatus != "OK" || item.FTs < lastTs { //数据采集失败,不处理
			continue
		}

		if fCompare(mock, item.Value) == 0 { //采集到的数据为mock数据,则认为上报超时了
			if LastTs(key)+step <= now {
				TurnNodata(key, now)
				genMock(genTs(now, step), key, ndcfg)
			}
			continue
		}

		if item.Ts < lastTs { //数据过期, 则认为上报超时
			if LastTs(key)+step <= now {
				TurnNodata(key, now)
				genMock(genTs(now, step), key, ndcfg)
			}
			continue
		}

		TurnOk(key, now)
	}
}