Esempio n. 1
0
func ProcMetrics() (L []*model.MetricValue) {

	reportProcs := g.ReportProcs()
	sz := len(reportProcs)
	if sz == 0 {
		return
	}

	ps, err := nux.AllProcs()
	if err != nil {
		log.Println(err)
		return
	}

	pslen := len(ps)

	for tags, m := range reportProcs {
		cnt := 0
		for i := 0; i < pslen; i++ {
			if is_a(ps[i], m) {
				cnt++
			}
		}

		L = append(L, GaugeValue("proc.num", cnt, tags))
	}

	return
}
Esempio n. 2
0
func ProcMetrics() (L []*model.MetricValue) {

	reportProcs := g.ReportProcs()
	sz := len(reportProcs)
	if sz == 0 {
		return
	}

	ps, err := nux.AllProcs()
	if err != nil {
		log.Println(err)
		return
	}

	pslen := len(ps)

	for tags, preProc := range reportProcs {
		cnt := 0
		pids := map[int]struct{}{}
		for i := 0; i < pslen; i++ {
			if is_a(ps[i], preProc) {
				cnt++
				pids[ps[i].Pid] = struct{}{}
			}
		}
		if cnt > 0 && is_restart_proc(pids, preProc) {
			//此进程发生了重启,将进程数置为0
			cnt = 0
		}
		L = append(L, GaugeValue(g.PROC_NUM, cnt, tags))
	}
	return
}