zoukankan      html  css  js  c++  java
  • goreplay~http输出统计分析

    HTTPOutputConfig 统计信息收集

    是否收集统计信息,统计输出间隔是多少

    if o.config.Stats {
        o.queueStats = NewGorStat("output_http", o.config.StatsMs)
    }

    统计信息收集

    func (o *HTTPOutput) PluginWrite(msg *Message) (n int, err error) {
        if !isRequestPayload(msg.Meta) {
            return len(msg.Data), nil
        }
    
        select {
        case <-o.stop:
            return 0, ErrorStopped
        case o.queue <- msg:
        }
    
        if o.config.Stats {
            o.queueStats.Write(len(o.queue))
        }
        if len(o.queue) > 0 {
            // try to start a new worker to serve
            if atomic.LoadInt32(&o.activeWorkers) < int32(o.config.WorkersMax) {
                go o.startWorker()
                atomic.AddInt32(&o.activeWorkers, 1)
            }
        }
        return len(msg.Data) + len(msg.Meta), nil
    }

    NewGorStat统计类

    func NewGorStat(statName string, rateMs int) (s *GorStat) {
        s = new(GorStat)
        s.statName = statName
        s.rateMs = rateMs
        s.latest = 0
        s.mean = 0
        s.max = 0
        s.count = 0
    
        if Settings.Stats {
            go s.reportStats()
        }
        return
    }

    写入时做统计

    func (s *GorStat) Write(latest int) {
        if Settings.Stats {
            if latest > s.max {
                s.max = latest
            }
            if latest != 0 {
                s.mean = ((s.mean * s.count) + latest) / (s.count + 1)
            }
            s.latest = latest
            s.count = s.count + 1
        }
    }

    打印输出,简单的sleep

    func (s *GorStat) reportStats() {
        Debug(0, "
    ", s.statName+":latest,mean,max,count,count/second,gcount")
        for {
            Debug(0, "
    ", s)
            s.Reset()
            time.Sleep(time.Duration(s.rateMs) * time.Millisecond)
        }
    }
  • 相关阅读:
    Jenkins权限控制-Role Strategy Plugin插件使用
    迁移一个仓库到新的Gitlab
    Gitlab备份以及恢复
    10.使用nexus3配置golang私有仓库
    9.使用nexus3配置Python私有仓库
    8.maven上传jar包以及SNAPSHOT的一个坑
    7.nexus版本升级
    6.使用nexus3配置yum私有仓库
    5.使用nexus3配置npm私有仓库
    4.maven私服nexus2迁移到nexus3
  • 原文地址:https://www.cnblogs.com/it-worker365/p/15113743.html
Copyright © 2011-2022 走看看