fix agent proc.cpu.util
This commit is contained in:
parent
dec9097ce7
commit
b1426945d4
|
@ -132,6 +132,11 @@ type ProcCollect struct {
|
|||
|
||||
Target string `json:"target"`
|
||||
CollectMethod string `json:"collect_method"`
|
||||
|
||||
ProcJiffy map[int]uint64 `xorm:"-" json:"-"`
|
||||
Jiffy uint64 `xorm:"-" json:"-"`
|
||||
RBytes map[int]uint64 `xorm:"-" json:"-"`
|
||||
WBytes map[int]uint64 `xorm:"-" json:"-"`
|
||||
}
|
||||
|
||||
type PluginCollect struct {
|
||||
|
|
|
@ -185,9 +185,7 @@ func (w *Worker) analysis(line string) {
|
|||
analyspoint, err := w.producer(line, strategy)
|
||||
|
||||
if err != nil {
|
||||
log := fmt.Sprintf("%s[producer error][sid:%d] : %v", w.Mark, strategy.ID, err)
|
||||
//sample_log.Error(log)
|
||||
logger.Error(log)
|
||||
logger.Debugf("%s[producer error][sid:%d] : %v", w.Mark, strategy.ID, err)
|
||||
continue
|
||||
} else {
|
||||
if analyspoint != nil {
|
||||
|
|
|
@ -44,13 +44,6 @@ func (p *ProcScheduler) Stop() {
|
|||
close(p.Quit)
|
||||
}
|
||||
|
||||
var (
|
||||
rBytes map[int]uint64
|
||||
wBytes map[int]uint64
|
||||
procJiffy map[int]uint64
|
||||
jiffy uint64
|
||||
)
|
||||
|
||||
func ProcCollect(p *models.ProcCollect) {
|
||||
ps, err := AllProcs()
|
||||
if err != nil {
|
||||
|
@ -84,24 +77,24 @@ func ProcCollect(p *models.ProcCollect) {
|
|||
cnt++
|
||||
memory += proc.Mem
|
||||
fdNum += proc.FdCount
|
||||
rOld := rBytes[proc.Pid]
|
||||
rOld := p.RBytes[proc.Pid]
|
||||
if rOld != 0 && rOld <= proc.RBytes {
|
||||
ioRead += proc.RBytes - rOld
|
||||
}
|
||||
|
||||
wOld := wBytes[proc.Pid]
|
||||
wOld := p.WBytes[proc.Pid]
|
||||
if wOld != 0 && wOld <= proc.WBytes {
|
||||
ioWrite += proc.WBytes - wOld
|
||||
}
|
||||
|
||||
uptime = readUptime(proc.Pid)
|
||||
|
||||
// jiffy 为零,表示第一次采集信息,不做cpu计算
|
||||
if jiffy == 0 {
|
||||
// p.Jiffy 为零,表示第一次采集信息,不做cpu计算
|
||||
if p.Jiffy == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
cpu += float64(newProcJiffy[proc.Pid] - procJiffy[proc.Pid])
|
||||
cpu += float64(newProcJiffy[proc.Pid] - p.ProcJiffy[proc.Pid])
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -114,8 +107,8 @@ func ProcCollect(p *models.ProcCollect) {
|
|||
ioWriteItem := core.GaugeValue("proc.io.write.bytes", ioWrite, p.Tags)
|
||||
items = []*dataobj.MetricValue{procNumItem, memUsedItem, procFdItem, procUptimeItem, ioReadItem, ioWriteItem}
|
||||
|
||||
if jiffy != 0 {
|
||||
cpuUtil := cpu / float64(newJiffy-jiffy) * 100
|
||||
if p.Jiffy != 0 {
|
||||
cpuUtil := cpu / float64(newJiffy-p.Jiffy) * 100
|
||||
if cpuUtil > 100 {
|
||||
cpuUtil = 100
|
||||
}
|
||||
|
@ -144,10 +137,10 @@ func ProcCollect(p *models.ProcCollect) {
|
|||
|
||||
core.Push(items)
|
||||
|
||||
rBytes = newRBytes
|
||||
wBytes = newWBytes
|
||||
procJiffy = newProcJiffy
|
||||
jiffy = readJiffy()
|
||||
p.RBytes = newRBytes
|
||||
p.WBytes = newWBytes
|
||||
p.ProcJiffy = newProcJiffy
|
||||
p.Jiffy = readJiffy()
|
||||
}
|
||||
|
||||
func isProc(p *Proc, method, target string) bool {
|
||||
|
|
|
@ -45,6 +45,7 @@ func Query(reqs []*dataobj.QueryData, stra *models.Stra, expFunc string) []*data
|
|||
if err != nil {
|
||||
stats.Counter.Set("query.data.transfer.err", 1)
|
||||
logger.Warningf("get data err:%v", err)
|
||||
return respData
|
||||
} else {
|
||||
for i := 0; i < len(resp.Data); i++ {
|
||||
var values dataobj.RRDValues
|
||||
|
|
|
@ -287,6 +287,7 @@ func GetReqs(stra *models.Stra, metric string, nids, endpoints []string, now int
|
|||
if err != nil {
|
||||
stats.Counter.Set("query.index.err", 1)
|
||||
logger.Warning("query index err:", err)
|
||||
return reqs
|
||||
}
|
||||
|
||||
lostSeries := []cache.Series{}
|
||||
|
|
|
@ -66,7 +66,7 @@ func userAddPost(c *gin.Context) {
|
|||
root := loginRoot(c)
|
||||
|
||||
var f userProfileForm
|
||||
bind(c, &f)
|
||||
dangerous(c.ShouldBind(&f))
|
||||
dangerous(auth.CheckPassword(f.Password))
|
||||
|
||||
pass, err := models.CryptoPass(f.Password)
|
||||
|
|
Loading…
Reference in New Issue