Adding cdrstats config options

This commit is contained in:
DanB
2014-07-31 17:54:27 +02:00
parent 67d6bdb4d8
commit b57fd3b09a
6 changed files with 150 additions and 19 deletions

41
apier/cdrstatsv1.go Normal file
View File

@@ -0,0 +1,41 @@
/*
Real-time Charging System for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can Storagetribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITH*out ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package apier
import (
"fmt"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
// Interact with Stats server
type CDRStatsV1 struct {
CdrSts *engine.Stats
}
type AttrGetMetrics struct {
StatsInstanceId string // Id of the stats instance queried
}
func (sts *CDRStatsV1) GetMetrics(attr AttrGetMetrics, reply *map[string]float64) error {
if len(attr.StatsInstanceId) == 0 {
return fmt.Errorf("%s:StatsInstanceId", utils.ERR_MANDATORY_IE_MISSING)
}
return sts.CdrSts.GetValues(attr.StatsInstanceId, reply)
}

53
config/cdrstatsconfig.go Normal file
View File

@@ -0,0 +1,53 @@
/*
Real-time Charging System for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package config
import (
"code.google.com/p/goconf/conf"
"time"
)
// Parse the configuration file for CDRStatConfigs
func ParseCfgCDRStatConfigs(c *conf.ConfigFile) ([]*CdrStatsConfig, error) {
return nil, nil
}
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)
ActionTriggerIds []string
}

View File

@@ -423,11 +423,11 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
if hasOpt = c.HasOption("cdrs", "mediator"); hasOpt {
cfg.CDRSMediator, _ = c.GetString("cdrs", "mediator")
}
if hasOpt = c.HasOption("cdrs", "stats"); hasOpt {
cfg.CDRSStats, _ = c.GetString("cdrs", "stats")
if hasOpt = c.HasOption("cdrs", "cdrstats"); hasOpt {
cfg.CDRSStats, _ = c.GetString("cdrs", "cdrstats")
}
if hasOpt = c.HasOption("stats", "enabled"); hasOpt {
cfg.CDRStatsEnabled, _ = c.GetBool("stats", "enabled")
if hasOpt = c.HasOption("cdrstats", "enabled"); hasOpt {
cfg.CDRStatsEnabled, _ = c.GetBool("cdrstats", "enabled")
}
if hasOpt = c.HasOption("cdre", "cdr_format"); hasOpt {
cfg.CdreDefaultInstance.CdrFormat, _ = c.GetString("cdre", "cdr_format")
@@ -526,8 +526,8 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
if hasOpt = c.HasOption("mediator", "reconnects"); hasOpt {
cfg.MediatorReconnects, _ = c.GetInt("mediator", "reconnects")
}
if hasOpt = c.HasOption("mediator", "stats"); hasOpt {
cfg.MediatorStats, _ = c.GetString("mediator", "stats")
if hasOpt = c.HasOption("mediator", "cdrstats"); hasOpt {
cfg.MediatorStats, _ = c.GetString("mediator", "cdrstats")
}
if hasOpt = c.HasOption("session_manager", "enabled"); hasOpt {
cfg.SMEnabled, _ = c.GetBool("session_manager", "enabled")

View File

@@ -290,13 +290,7 @@ func TestConfigFromFile(t *testing.T) {
eCfg.MailerFromAddr = "test"
if !reflect.DeepEqual(cfg, eCfg) {
t.Log(eCfg)
for _, eDC := range eCfg.DerivedChargers {
fmt.Printf("ExpectDerivedChargers: %+v\n", eDC)
}
t.Log(cfg)
for _, eDC := range cfg.DerivedChargers {
fmt.Printf("DerivedChargers: %+v\n", eDC)
}
t.Error("Loading of configuration from file failed!")
}
}

View File

@@ -44,11 +44,8 @@ enabled = true # Starts Scheduler service: <true|false>.
[cdrs]
enabled = true # Start the CDR Server service: <true|false>.
extra_fields = test # Extra fields to scategorye in CDRs
mediator = test # Address where to reach the Mediacategory. Empty for disabling mediation. <""|internal>
stats = test # Address where to reach the stats sevre. Empty for disabling stats. <""|internal>
[stats]
enabled = true # Start the CDR stats service: <true|false>.
mediator = test # Address where to reach the Mediator. Empty for disabling mediation. <""|internal>
cdrstats = test # Address where to reach the CDRStats server. Empty for disabling stats. <""|internal>
[cdre]
cdr_format = test # Exported CDRs format <csv>
@@ -87,8 +84,30 @@ extra_fields = test:test # Field identifiers of the fields to add in extra field
[mediator]
enabled = true # Starts Mediacategory service: <true|false>.
rater = test # Address where to reach the Rater: <internal|x.y.z.y:1234>
reconnects = 99 # Number of reconnects to rater before giving up.
stats = test # Address where to reach the stats service: <internal|x.y.z.y:1234>
reconnects = 99 # Number of reconnects to rater before giving up.
cdrstats = test # Address where to reach the cdrstats service: <internal|x.y.z.y:1234>
[cdrstats]
enabled = true # Start the CDR stats service: <true|false>.
queue_length = 99 # Number of items in the stats buffer
time_window = 99 # Will only keep the CDRs who's call setup time is not older than time.Now()-TimeWindow
metrics = test # Stat metric ids to build
setup_intervals =test # Filter on CDR SetupTime
tors = test # Filter on CDR TOR fields
cdr_hosts= test # Filter on CDR CdrHost fields
cdr_sources = test # Filter on CDR CdrSource fields
req_types = test # Filter on CDR ReqType fields
directions = test # Filter on CDR Direction fields
tenants = test # Filter on CDR Tenant fields
categories = test # Filter on CDR Category fields
accounts = test # Filter on CDR Account fields
subjects = test # Filter on CDR Subject fields
destination_prefixes = test # Filter on CDR Destination prefixes
usage_intervals = test # Filter on CDR Usage
mediation_runs = test # Filter on CDR MediationRunId fields
rated_accounts = test # Filter on CDR RatedAccount fields
rated_subjects = test # Filter on CDR RatedSubject fields
cost_intervals = test # Filter on CDR Cost
[session_manager]
enabled = true # Starts SessionManager service: <true|false>.

View File

@@ -88,6 +88,30 @@
# enabled = false # Starts Mediator service: <true|false>.
# rater = internal # Address where to reach the Rater: <internal|x.y.z.y:1234>
# rater_reconnects = 3 # Number of reconnects to rater before giving up.
# cdrstats = # Address where to reach the cdrstats service: <internal|x.y.z.y:1234>
[cdrstats]
# enabled = false # Starts the cdrstats service: <true|false>
# queue_length = 50 # Number of items in the stats buffer
# time_window = 1h # Will only keep the CDRs who's call setup time is not older than time.Now()-TimeWindow
# metrics = ASR, ACD, ACC # Stat metric ids to build
# setup_intervals = # Filter on CDR SetupTime
# tors = # Filter on CDR TOR fields
# cdr_hosts= # Filter on CDR CdrHost fields
# cdr_sources = # Filter on CDR CdrSource fields
# req_types = # Filter on CDR ReqType fields
# directions = # Filter on CDR Direction fields
# tenants = # Filter on CDR Tenant fields
# categories = # Filter on CDR Category fields
# accounts = # Filter on CDR Account fields
# subjects = # Filter on CDR Subject fields
# destination_prefixes = # Filter on CDR Destination prefixes
# usage_intervals = # Filter on CDR Usage
# mediation_runs = # Filter on CDR MediationRunId fields
# rated_accounts = # Filter on CDR RatedAccount fields
# rated_subjects = # Filter on CDR RatedSubject fields
# cost_intervals = # Filter on CDR Cost
[session_manager]
# enabled = false # Starts SessionManager service: <true|false>