mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Instantiating stats queue out of default config
This commit is contained in:
@@ -26,16 +26,16 @@ import (
|
||||
|
||||
// Interact with Stats server
|
||||
type CDRStatsV1 struct {
|
||||
CdrSts *engine.Stats
|
||||
CdrStats *engine.Stats
|
||||
}
|
||||
|
||||
type AttrGetMetrics struct {
|
||||
StatsInstanceId string // Id of the stats instance queried
|
||||
StatsQueueId string // Id of the stats instance queried
|
||||
}
|
||||
|
||||
func (sts *CDRStatsV1) GetMetrics(attr AttrGetMetrics, reply *map[string]float64) error {
|
||||
if len(attr.StatsInstanceId) == 0 {
|
||||
if len(attr.StatsQueueId) == 0 {
|
||||
return fmt.Errorf("%s:StatsInstanceId", utils.ERR_MANDATORY_IE_MISSING)
|
||||
}
|
||||
return sts.CdrSts.GetValues(attr.StatsInstanceId, reply)
|
||||
return sts.CdrStats.GetValues(attr.StatsQueueId, reply)
|
||||
}
|
||||
|
||||
@@ -464,6 +464,10 @@ func main() {
|
||||
|
||||
if cfg.CDRStatsEnabled {
|
||||
cdrStats = engine.NewStats(accountDb)
|
||||
if cfg.CDRStatConfig != nil && len(cfg.CDRStatConfig.Metrics) != 0 {
|
||||
var out int
|
||||
cdrStats.AddQueue(engine.NewCdrStatsFromCdrStatsCfg(cfg.CDRStatConfig), &out)
|
||||
}
|
||||
server.RpcRegister(cdrStats)
|
||||
server.RpcRegister(apier.CDRStatsV1{cdrStats}) // Public APIs
|
||||
}
|
||||
|
||||
@@ -63,61 +63,61 @@ func ParseCfgDefaultCDRStatsConfig(c *conf.ConfigFile) (*CdrStatsConfig, error)
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "tors"); hasOpt {
|
||||
torsStr, _ := c.GetString("cdrstats", "tors")
|
||||
if csCfg.TOR, err = ConfigSlice(torsStr); err != nil {
|
||||
if csCfg.TORs, err = ConfigSlice(torsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "cdr_hosts"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "cdr_hosts")
|
||||
if csCfg.CdrHost, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.CdrHosts, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "cdr_sources"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "cdr_sources")
|
||||
if csCfg.CdrSource, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.CdrSources, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "req_types"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "req_types")
|
||||
if csCfg.ReqType, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.ReqTypes, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "directions"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "directions")
|
||||
if csCfg.Direction, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.Directions, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "tenants"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "tenants")
|
||||
if csCfg.Tenant, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.Tenants, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "categories"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "categories")
|
||||
if csCfg.Category, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.Categories, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "accounts"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "accounts")
|
||||
if csCfg.Account, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.Accounts, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "subjects"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "subjects")
|
||||
if csCfg.Subject, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.Subjects, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "destination_prefixes"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "destination_prefixes")
|
||||
if csCfg.DestinationPrefix, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.DestinationPrefixes, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -143,13 +143,13 @@ func ParseCfgDefaultCDRStatsConfig(c *conf.ConfigFile) (*CdrStatsConfig, error)
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "rated_accounts"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "rated_accounts")
|
||||
if csCfg.RatedAccount, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.RatedAccounts, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrstats", "rated_subjects"); hasOpt {
|
||||
valsStr, _ := c.GetString("cdrstats", "rated_subjects")
|
||||
if csCfg.RatedSubject, err = ConfigSlice(valsStr); err != nil {
|
||||
if csCfg.RatedSubjects, err = ConfigSlice(valsStr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -172,24 +172,24 @@ func ParseCfgDefaultCDRStatsConfig(c *conf.ConfigFile) (*CdrStatsConfig, error)
|
||||
}
|
||||
|
||||
type CdrStatsConfig struct {
|
||||
Id string // Config id, unique per config instance
|
||||
QueueLength int // Number of items in the stats buffer
|
||||
TimeWindow time.Duration // Will only keep the CDRs who's call setup time is not older than time.Now()-TimeWindow
|
||||
Metrics []string // ASR, ACD, ACC
|
||||
SetupInterval []time.Time // 2 or less items (>= start interval,< stop_interval)
|
||||
TOR []string
|
||||
CdrHost []string
|
||||
CdrSource []string
|
||||
ReqType []string
|
||||
Direction []string
|
||||
Tenant []string
|
||||
Category []string
|
||||
Account []string
|
||||
Subject []string
|
||||
DestinationPrefix []string
|
||||
UsageInterval []time.Duration // 2 or less items (>= Usage, <Usage)
|
||||
MediationRunIds []string
|
||||
RatedAccount []string
|
||||
RatedSubject []string
|
||||
CostInterval []float64 // 2 or less items, (>=Cost, <Cost)
|
||||
Id string // Config id, unique per config instance
|
||||
QueueLength int // Number of items in the stats buffer
|
||||
TimeWindow time.Duration // Will only keep the CDRs who's call setup time is not older than time.Now()-TimeWindow
|
||||
Metrics []string // ASR, ACD, ACC
|
||||
SetupInterval []time.Time // 2 or less items (>= start interval,< stop_interval)
|
||||
TORs []string
|
||||
CdrHosts []string
|
||||
CdrSources []string
|
||||
ReqTypes []string
|
||||
Directions []string
|
||||
Tenants []string
|
||||
Categories []string
|
||||
Accounts []string
|
||||
Subjects []string
|
||||
DestinationPrefixes []string
|
||||
UsageInterval []time.Duration // 2 or less items (>= Usage, <Usage)
|
||||
MediationRunIds []string
|
||||
RatedAccounts []string
|
||||
RatedSubjects []string
|
||||
CostInterval []float64 // 2 or less items, (>=Cost, <Cost)
|
||||
}
|
||||
|
||||
@@ -220,10 +220,10 @@ func TestConfigFromFile(t *testing.T) {
|
||||
eCfg.CDRSMediator = "test"
|
||||
eCfg.CDRStatsEnabled = true
|
||||
eCfg.CDRStatConfig = &CdrStatsConfig{Id: utils.DEFAULT_RUNID, QueueLength: 99, TimeWindow: time.Duration(99) * time.Second,
|
||||
Metrics: []string{"test"}, TOR: []string{"test"}, CdrHost: []string{"test"}, CdrSource: []string{"test"}, ReqType: []string{"test"}, Direction: []string{"test"},
|
||||
Tenant: []string{"test"}, Category: []string{"test"}, Account: []string{"test"}, Subject: []string{"test"}, DestinationPrefix: []string{"test"},
|
||||
Metrics: []string{"test"}, TORs: []string{"test"}, CdrHosts: []string{"test"}, CdrSources: []string{"test"}, ReqTypes: []string{"test"}, Directions: []string{"test"},
|
||||
Tenants: []string{"test"}, Categories: []string{"test"}, Accounts: []string{"test"}, Subjects: []string{"test"}, DestinationPrefixes: []string{"test"},
|
||||
UsageInterval: []time.Duration{time.Duration(99) * time.Second},
|
||||
MediationRunIds: []string{"test"}, RatedAccount: []string{"test"}, RatedSubject: []string{"test"}, CostInterval: []float64{99.0}}
|
||||
MediationRunIds: []string{"test"}, RatedAccounts: []string{"test"}, RatedSubjects: []string{"test"}, CostInterval: []float64{99.0}}
|
||||
eCfg.CDRSStats = "test"
|
||||
eCfg.CdreDefaultInstance = &CdreConfig{
|
||||
CdrFormat: "test",
|
||||
|
||||
@@ -22,9 +22,35 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewCdrStatsFromCdrStatsCfg(csCfg *config.CdrStatsConfig) *CdrStats {
|
||||
return &CdrStats{
|
||||
Id: csCfg.Id,
|
||||
QueueLength: csCfg.QueueLength,
|
||||
TimeWindow: csCfg.TimeWindow,
|
||||
Metrics: csCfg.Metrics,
|
||||
SetupInterval: csCfg.SetupInterval,
|
||||
TOR: csCfg.TORs,
|
||||
CdrHost: csCfg.CdrHosts,
|
||||
CdrSource: csCfg.CdrSources,
|
||||
ReqType: csCfg.ReqTypes,
|
||||
Direction: csCfg.Directions,
|
||||
Tenant: csCfg.Tenants,
|
||||
Category: csCfg.Categories,
|
||||
Account: csCfg.Accounts,
|
||||
Subject: csCfg.Subjects,
|
||||
DestinationPrefix: csCfg.DestinationPrefixes,
|
||||
UsageInterval: csCfg.UsageInterval,
|
||||
MediationRunIds: csCfg.MediationRunIds,
|
||||
RatedAccount: csCfg.RatedAccounts,
|
||||
RatedSubject: csCfg.RatedSubjects,
|
||||
CostInterval: csCfg.CostInterval,
|
||||
}
|
||||
}
|
||||
|
||||
type CdrStats struct {
|
||||
Id string // Config id, unique per config instance
|
||||
QueueLength int // Number of items in the stats buffer
|
||||
|
||||
Reference in New Issue
Block a user