mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Fixup concurrency on mediation runs and stats, improving tutorial CdrStats files
This commit is contained in:
@@ -189,6 +189,7 @@ func startSessionManager(responder *engine.Responder, loggerDb engine.LogStorage
|
||||
sm, _ = sessionmanager.NewOSipsSessionManager(cfg, raterConn, cdrsConn)
|
||||
default:
|
||||
engine.Logger.Err(fmt.Sprintf("<SessionManager> Unsupported session manger type: %s!", cfg.SMSwitchType))
|
||||
exitChan <- true
|
||||
}
|
||||
if err = sm.Connect(); err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("<SessionManager> error: %s!", err))
|
||||
|
||||
@@ -232,6 +232,9 @@ func main() {
|
||||
}
|
||||
if cdrstats != nil {
|
||||
statsQueueIds, _ := loader.GetLoadedIds(engine.CDR_STATS_PREFIX)
|
||||
if *flush {
|
||||
statsQueueIds = []string{} // Force reload all
|
||||
}
|
||||
if len(statsQueueIds) != 0 {
|
||||
if *verbose {
|
||||
log.Print("Reloading CDRStats data")
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
STANDARD_TRIGGERS,*monetary,*out,*min_balance,2,false,0,,,,,,,LOG_WARNING,10
|
||||
STANDARD_TRIGGERS,*monetary,*out,*max_balance,20,false,0,,,,,,,LOG_WARNING,10
|
||||
STANDARD_TRIGGERS,*monetary,*out,*max_counter,5,false,0,FS_USERS,,,,,,LOG_WARNING,10
|
||||
CDRST5_WARN,,,*min_asr,45,true,1m,,,,,,3,LOG_WARNING,10
|
||||
CDRST5_WARN,,,*min_acd,10,true,1m,,,,,,5,LOG_WARNING,10
|
||||
CDRST5_WARN,,,*max_acc,10,true,1m,,,,,,5,LOG_WARNING,10
|
||||
CDRST6_WARN,,,*min_asr,30,true,0,,,,,,5,LOG_WARNING,10
|
||||
CDRST6_WARN,,,*min_acd,3,true,0,,,,,,2,LOG_WARNING,10
|
||||
CDRST1_WARN,,,*min_asr,45,true,1m,,,,,,3,LOG_WARNING,10
|
||||
CDRST1_WARN,,,*min_acd,10,true,1m,,,,,,5,LOG_WARNING,10
|
||||
CDRST1_WARN,,,*max_acc,10,true,1m,,,,,,5,LOG_WARNING,10
|
||||
CDRST1001_WARN,,,*min_asr,65,true,1m,,,,,,3,LOG_WARNING,10
|
||||
CDRST1001_WARN,,,*min_acd,10,true,1m,,,,,,5,LOG_WARNING,10
|
||||
CDRST1001_WARN,,,*max_acc,5,true,1m,,,,,,5,LOG_WARNING,10
|
||||
CDRST3_WARN,,,*min_acd,60,true,1m,,,,,,5,LOG_WARNING,10
|
||||
|
@@ -1,6 +1,13 @@
|
||||
#Id,QueueLength,TimeWindow,Metrics,SetupInterval,TOR,CdrHost,CdrSource,ReqType,Direction,Tenant,Category,Account,Subject,DestinationPrefix,UsageInterval,MediationRunIds,RatedAccount,RatedSubject,CostInterval,Triggers
|
||||
CDRST5,5,1m,ASR,,*voice,,,,*out,cgrates.org,call,1001,1001,,,default,,,,CDRST5_WARN
|
||||
CDRST5,,,ACD,,,,,,,,,,,,,,,,,
|
||||
CDRST5,,,ACC,,,,,,,,,,,,,,,,,
|
||||
CDRST6,10,0,ASR,,,,,,,cgrates.org,,,,,,default,,,,CDRST6_WARN
|
||||
CDRST6,,,ACD,,,,,,,,,,,,,,,,,
|
||||
#Id,QueueLength,TimeWindow,Metric,SetupInterval,TOR,CdrHost,CdrSource,ReqType,Direction,Tenant,Category,Account,Subject,DestinationPrefix,UsageInterval,MediationRunIds,RatedAccount,RatedSubject,CostInterval,Triggers
|
||||
CDRST1,10,0,ASR,,,,,,,cgrates.org,,,,,,default,,,,CDRST1_WARN
|
||||
CDRST1,,,ACD,,,,,,,,,,,,,,,,,
|
||||
CDRST1,,,ACC,,,,,,,,,,,,,,,,,
|
||||
CDRST_1001,10,10m,ASR,,,,,,,cgrates.org,,,1001,,,default,,,,CDRST1001_WARN
|
||||
CDRST_1001,,,ACD,,,,,,,,,,,,,,,,,
|
||||
CDRST_1001,,,ACC,,,,,,,,,,,,,,,,,
|
||||
CDRST_1002,10,10m,ASR,,,,,,,cgrates.org,,,1002,,,default,,,,CDRST1001_WARN
|
||||
CDRST_1002,,,ACD,,,,,,,,,,,,,,,,,
|
||||
CDRST_1002,,,ACC,,,,,,,,,,,,,,,,,
|
||||
CDRST_1003,,,ASR,,,,,,,cgrates.org,,,,1003,,default,,,,CDRST3_WARN
|
||||
CDRST_1003,,,ACD,,,,,,,,,,,,,,,,,
|
||||
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Tutorial FS_JSON
|
||||
CGRateS Tutorial
|
||||
================
|
||||
|
||||
Scenario:
|
||||
@@ -15,25 +15,30 @@ Scenario:
|
||||
- Account 1001 will receive a special *deal* for 1002 and 1003 destinations during peak times with *RT_20CNT*, otherwise same as default rating.
|
||||
|
||||
- Create 5 accounts (equivalent of FreeSWITCH default test users - 1001, 1002, 1003, 1004, 1007).
|
||||
- 1002, 1003, 1004 will receive 10units of *monetary balance.
|
||||
- 1001 will receive 5 units of general *monetary and 5 units of shared balance in the shared group *SHARED_A*.
|
||||
- 1007 will receive 0 units of shared balance in the shared group *SHARED_A*.
|
||||
- Define the shared balance *SHARED_A* with debit policy *highest.
|
||||
|
||||
- 1002, 1003, 1004 will receive 10units of *monetary balance.
|
||||
- 1001 will receive 5 units of general *monetary and 5 units of shared balance in the shared group *SHARED_A*.
|
||||
- 1007 will receive 0 units of shared balance in the shared group *SHARED_A*.
|
||||
- Define the shared balance *SHARED_A* with debit policy *highest.
|
||||
|
||||
- Create 1 RatingProfile Alias: 1006 - alias of rating profile 1001.
|
||||
- Create 1 Account Alias: 1006 - alias of account 1002.
|
||||
|
||||
- For each balance created, attach 3 triggers to control the balance: log on balance=2, log on balance=20, log on 5 mins talked towards 10xx destination.
|
||||
|
||||
- Add 2 CDRStats Queue configurations:
|
||||
- Add 4 CDRStats Queue configurations (extra to default one configured in .cfg file):
|
||||
|
||||
- CDRStatsQueueId: *CDRST1* with purpose of monitoring calls on the Tenant=cgrates.org, and MediationRunId=default, with a QueueLength of 10 CDRs and no TimeWindow, monitoring ASR, ACD and ACC. Thrrough ActionTriggers *CDRST1_WARN* we monitor *min_asr(45), *min_acd(10) and *max_acc(10) parameters and log the warning on thresholds reached.
|
||||
- CDRStatsQueueId: *CDRST_1001* with a QueueLength of 10 CDRs and a TimeWindow of 10 minutes, gathering ASR,ACD and ACC metrics with CDR filters on Tenant=cgrates.org, Subject=1001 and MediationRunId=default with the purpose of monitoring calls of user 1001. To this queue we attach an ActionTrigger profile named *CDRST1001_WARN* which will monitor min_asr(65), min_acd(10), max_acc(5) and log to syslog a warning once thresholds are reached.
|
||||
|
||||
- CDRStatsQueueId: *CDRST5* with a QueueLength of 5 CDRs and a TimeWindow of 1 minute monitoring ASR, ACD and ACC for CDRs with filters on TOR=*voice, Direction=*out, Tenant=cgrates.org, Category=call, Account=1001, Subject=1001 and MediationRunId=default. To this queue we attach ActionTriggers profile named CDRST5_WARN
|
||||
- CDRStatsQueueId: *CDRST6* with a QueueLength of 10 CDRs and no TimeWindow gathering ASR and ACD metrics with CDR filters on Tenant=cgrates.org and MediationRunId=default. To this queue we attach an ActionTrigger profile named CDRST6_WARN.
|
||||
- ActionTrigger: *CDRST5_WARN* with thresholds explained bellow and having as action the *log on syslog
|
||||
|
||||
- Threshold on *min_asr of 45, configured as recurrent with a sleep time of 1 minute and a minimum of 3 items in the stats queue.
|
||||
- Threshold on *min_acd of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue.
|
||||
- Threshold on *max_acc of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue.
|
||||
- Threshold on *min_asr of 45, configured as recurrent with a sleep time of 1 minute and a minimum of 3 items in the stats queue.
|
||||
- Threshold on *min_acd of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue.
|
||||
- Threshold on *max_acc of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue.
|
||||
|
||||
- ActionTrigger: *CDRST6_WARN* with thresholds explained bellow and having as action the *log on syslog
|
||||
|
||||
- Threshold on *min_asr of 30, configured as recurrent without sleep time and a minimum of 5 items in the stats queue.
|
||||
- Threshold on *min_acd of 3, configured as recurrent without sleep time and a minimum of 2 items in the stats queue.
|
||||
- Threshold on *min_asr of 30, configured as recurrent without sleep time and a minimum of 5 items in the stats queue.
|
||||
- Threshold on *min_acd of 3, configured as recurrent without sleep time and a minimum of 2 items in the stats queue.
|
||||
|
||||
|
||||
@@ -175,11 +175,11 @@ func (self *Mediator) RateCdr(storedCdr *utils.StoredCdr, sendToStats bool) erro
|
||||
}
|
||||
}
|
||||
if sendToStats && self.stats != nil { // We send to stats only after saving to db since there are chances we cannot store and then no way to reproduce stats offline
|
||||
go func() {
|
||||
go func(cdr *utils.StoredCdr) { // Pass it by value since the variable will be overwritten by for
|
||||
if err := self.stats.AppendCDR(cdr, nil); err != nil {
|
||||
Logger.Err(fmt.Sprintf("Could not append cdr to stats (mediator): %s", err.Error()))
|
||||
}
|
||||
}()
|
||||
}(cdr)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -122,6 +122,7 @@ func (osm *OsipsSessionManager) SubscribeEvents(evStop chan struct{}) error {
|
||||
continue // Try again
|
||||
}
|
||||
if !success {
|
||||
engine.Logger.Err(fmt.Sprintf("<SM-OpenSIPS> Shutting down, failed subscribing to OpenSIPS at address: <%s>", osm.cgrCfg.OsipsMiAddr))
|
||||
close(osm.stopServing) // Do not serve anymore since we got errors on subscribing
|
||||
return errors.New("Failed subscribing to OpenSIPS events")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user