added GetQueueIds and expire at GetValues

This commit is contained in:
Radu Ioan Fericean
2014-08-01 17:49:18 +03:00
parent 1574de1d38
commit a096d97d94
3 changed files with 38 additions and 14 deletions

View File

@@ -30,6 +30,7 @@ import (
type StatsInterface interface {
AddQueue(*CdrStats, *int) error
GetValues(string, *map[string]float64) error
GetQueueIds(int, *[]string) error
AppendCDR(*utils.StoredCdr, *int) error
}
@@ -38,6 +39,16 @@ type Stats struct {
mux sync.RWMutex
}
func NewStats(accountDb AccountingStorage) *Stats {
cdrStats := &Stats{}
if css, err := accountDb.GetAllCdrStats(); err == nil {
cdrStats.UpdateQueues(css, nil)
} else {
Logger.Err(fmt.Sprintf("Cannot load cdr stats: %v", err))
}
return cdrStats
}
func (s *Stats) AddQueue(cs *CdrStats, out *int) error {
s.mux.Lock()
defer s.mux.Unlock()
@@ -52,14 +63,15 @@ func (s *Stats) AddQueue(cs *CdrStats, out *int) error {
return nil
}
func NewStats(accountDb AccountingStorage) *Stats {
cdrStats := &Stats{}
if css, err := accountDb.GetAllCdrStats(); err == nil {
cdrStats.UpdateQueues(css, nil)
} else {
Logger.Err(fmt.Sprintf("Cannot load cdr stats: %v", err))
func (s *Stats) GetQueueIds(in int, ids *[]string) error {
s.mux.Lock()
defer s.mux.Unlock()
var result []string
for id, _ := range s.queues {
result = append(result, id)
}
return cdrStats
*ids = result
return nil
}
func (s *Stats) GetValues(sqID string, values *map[string]float64) error {
@@ -129,3 +141,7 @@ func (ps *ProxyStats) GetValues(sqID string, values *map[string]float64) error {
func (ps *ProxyStats) AppendCDR(cdr *utils.StoredCdr, out *int) error {
return ps.Client.Call("Stats.AppendCDR", cdr, out)
}
func (ps *ProxyStats) GetQueueIds(in int, ids *[]string) error {
return ps.Client.Call("Stats.GetQueueIds", in, ids)
}

View File

@@ -18,7 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import "time"
import (
"time"
"github.com/cgrates/cgrates/utils"
)
type Metric interface {
AddCdr(*QCdr)
@@ -67,7 +71,8 @@ func (asr *ASRMetric) GetValue() float64 {
if asr.total == 0 {
return 0
}
return asr.answered / asr.total * 100
val := asr.answered / asr.total * 100
return utils.Round(val, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
}
// ACD Average Call Duration
@@ -95,7 +100,8 @@ func (acd *ACDMetric) GetValue() float64 {
if acd.count == 0 {
return 0
}
return acd.sum.Seconds() / acd.count
val := acd.sum.Seconds() / acd.count
return utils.Round(val, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
}
// ACC Average Call Cost
@@ -123,5 +129,6 @@ func (acc *ACCMetric) GetValue() float64 {
if acc.count == 0 {
return 0
}
return acc.sum / acc.count
val := acc.sum / acc.count
return utils.Round(val, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
}

View File

@@ -30,7 +30,7 @@ type StatsQueue struct {
cdrs []*QCdr
conf *CdrStats
metrics map[string]Metric
mux sync.RWMutex
mux sync.Mutex
}
// Simplified cdr structure containing only the necessary info
@@ -141,8 +141,9 @@ func (sq *StatsQueue) purgeObsoleteCdrs() {
}
func (sq *StatsQueue) GetStats() map[string]float64 {
sq.mux.RLock()
defer sq.mux.RUnlock()
sq.mux.Lock()
defer sq.mux.Unlock()
sq.purgeObsoleteCdrs()
return sq.getStats()
}