func (d *DelayOutput) GetJson() ([]byte, error) {
	return json.Marshal(d)
}
get json string for DelayOutput
package delay_counter
import (
	"bytes"
	"encoding/json"
	"fmt"
	"sync"
	"time"
)
import (
	"github.com/baidu/go-lib/web-monitor/module_state2"
	"github.com/baidu/go-lib/web-monitor/web_params"
)
type DelayRecent struct {
	lock sync.Mutex
	interval int  
	currTime time.Time
	current  DelaySummary  
	pastTime time.Time
	past     DelaySummary  
	KeyPrefix   string  
	ProgramName string  
}
type DelayOutput struct {
	Interval    int
	KeyPrefix   string
	ProgramName string
	CurrTime string
	Current  DelaySummary
	PastTime string
	Past     DelaySummary
}
func (t *DelayRecent) Init(interval int, bucketSize int, bucketNum int) {
	t.currTime = time.Now()
	t.currTime = t.currTime.Truncate(time.Duration(interval) * time.Second)
	t.interval = interval
	t.current.Init(bucketSize, bucketNum)
	t.past.Init(bucketSize, bucketNum)
}
func (t *DelayRecent) SetKeyPrefix(prefix string) {
	t.KeyPrefix = prefix
}
func (t *DelayRecent) SetProgramName(programName string) {
	t.ProgramName = programName
}
func (t *DelayRecent) AddBySub(start time.Time, end time.Time) {
	duration := end.Sub(start).Nanoseconds() / 1000
	t.Add(duration)
}
func (t *DelayRecent) Clear() {
	t.current.Clear()
	t.past.Clear()
}
func (t *DelayRecent) Add(duration int64) {
	t.lock.Lock()
	defer t.lock.Unlock()
	t.trySwitch()
	t.current.Add(duration)
}
func (t *DelayRecent) AddDuration(duration time.Duration) {
	delay := int64(duration / time.Microsecond)
	t.Add(delay)
}
func (t *DelayRecent) trySwitch() {
	now := time.Now()
	if (t.currTime.Unix() / int64(t.interval)) != (now.Unix() / int64(t.interval)) {
		t.pastTime = t.currTime
		t.currTime = now
		t.past.Copy(t.current)
		t.current.Clear()  
	}
}
func (t *DelayRecent) get() DelayOutput {
	var retVal DelayOutput
	t.lock.Lock()
	defer t.lock.Unlock()
	t.trySwitch()
	retVal.Interval = t.interval
	retVal.CurrTime = fmt.Sprintf(t.currTime.Format("2006-01-02 15:04:05"))
	retVal.Current.Copy(t.current)
	retVal.PastTime = fmt.Sprintf(t.pastTime.Format("2006-01-02 15:04:05"))
	retVal.Past.Copy(t.past)
	retVal.KeyPrefix = t.KeyPrefix
	retVal.ProgramName = t.ProgramName
	return retVal
}
func (t *DelayRecent) Get() DelayOutput {
	retVal := t.get()
	retVal.Current.CalcAvg()
	retVal.Past.CalcAvg()
	return retVal
}
func (t *DelayRecent) GetJson() ([]byte, error) {
	d := t.Get()
	return d.GetJson()
}
func (t *DelayRecent) GetKV() []byte {
	d := t.Get()
	return d.GetKV()
}
func (t *DelayRecent) GetKVWithProgramName() []byte {
	d := t.Get()
	return d.GetKVWithProgramName()
}
func (t *DelayRecent) GetPrometheusFormat() []byte {
	d := t.Get()
	return d.GetPrometheusFormat()
}
func (t *DelayRecent) FormatOutput(params map[string][]string) ([]byte, error) {
	format, err := web_params.ParamsValueGet(params, "format")
	if err != nil {
		format = "json"
	}
	switch format {
	case "json", "hier_json":
		return t.GetJson()
	case "kv", "noah":
		return t.GetKV(), nil
	case "kv_with_program_name":
		return t.GetKVWithProgramName(), nil
	case "prometheus":
		return t.GetPrometheusFormat(), nil
	default:
		return nil, fmt.Errorf("format not support: %s", format)
	}
}
func (d *DelayOutput) Sum(d2 DelayOutput) error {
	if d.Interval != d2.Interval {
		return fmt.Errorf("Interval not match")
	}
	if err := d.Current.calcSum(d2.Current); err != nil {
		return err
	}
	if err := d.Past.calcSum(d2.Past); err != nil {
		return err
	}
	if d.CurrTime < d2.CurrTime {
		d.CurrTime = d2.CurrTime
	}
	if d.PastTime < d2.PastTime {
		d.PastTime = d2.PastTime
	}
	return nil
}