started Destination Id Archive

This commit is contained in:
Radu Ioan Fericean
2015-07-03 20:21:40 +03:00
parent a3e2526c42
commit d405c81166
2 changed files with 35 additions and 0 deletions

View File

@@ -229,3 +229,36 @@ func (tcc *TCCMetric) GetValue() float64 {
}
return utils.Round(tcc.sum, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
}
// DIA - Destination ID Archive
//
type DIAMetric struct {
destinations map[string]int64
}
func (dia *DIAMetric) AddCdr(cdr *QCdr) {
if dia.destinations == nil {
dia.destinations = make(map[string]int64)
}
if count, exists := dia.destinations[cdr.Dest]; exists {
dia.destinations[cdr.Dest] = count + 1
}
}
func (dia *DIAMetric) RemoveCdr(cdr *QCdr) {
if dia.destinations == nil {
dia.destinations = make(map[string]int64)
}
if count, exists := dia.destinations[cdr.Dest]; exists && count > 1 {
dia.destinations[cdr.Dest] = count - 1
} else {
dia.destinations[cdr.Dest] = 0
}
}
func (dia *DIAMetric) GetValue() float64 {
if len(dia.destinations) == 0 {
return STATS_NA
}
return len(dia.destinations)
}

View File

@@ -55,6 +55,7 @@ type QCdr struct {
Pdd time.Duration
Usage time.Duration
Cost float64
Dest string
}
func NewStatsQueue(conf *CdrStats) *StatsQueue {
@@ -164,6 +165,7 @@ func (sq *StatsQueue) simplifyCdr(cdr *StoredCdr) *QCdr {
Pdd: cdr.Pdd,
Usage: cdr.Usage,
Cost: cdr.Cost,
Dest: cdr.Destination,
}
}