diff --git a/config/config.go b/config/config.go index 77e3e6930..734211720 100755 --- a/config/config.go +++ b/config/config.go @@ -264,6 +264,7 @@ type CGRConfig struct { UserServerEnabled bool // Starts User as server: UserServerIndexes []string // List of user profile field indexes resourceLimiterCfg *ResourceLimiterConfig // Configuration for resource limiter + statsCfg *StatSCfg // Configuration for StatS MailerServer string // The server to use when sending emails out MailerAuthUser string // Authenticate to email server using this user MailerAuthPass string // Authenticate to email server with this password @@ -1109,6 +1110,10 @@ func (self *CGRConfig) ResourceLimiterCfg() *ResourceLimiterConfig { return self.resourceLimiterCfg } +func (cfg *CGRConfig) StatSCfg() *StatSCfg { + return cfg.statsCfg +} + // ToDo: fix locking here func (self *CGRConfig) SMAsteriskCfg() *SMAsteriskCfg { cfgChan := <-self.ConfigReloads[utils.SMAsterisk] // Lock config for read or reloads diff --git a/config/config_defaults.go b/config/config_defaults.go index c6eeb3ce6..7f07b6c54 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -409,6 +409,12 @@ const CGRATES_CFG_JSON = ` }, +"stats": { + "enabled": false, // starts ResourceLimiter service: . + "cache_dump_interval": "0s", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur> +}, + + "mailer": { "server": "localhost", // the server to use when sending emails out "auth_user": "cgrates", // authenticate to email server using this user diff --git a/config/config_json.go b/config/config_json.go index ec954e707..a76225638 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -23,6 +23,7 @@ import ( "os" "github.com/DisposaBoy/JsonConfigReader" + "github.com/cgrates/cgrates/utils" ) const ( @@ -358,6 +359,18 @@ func (self CgrJsonCfg) ResourceLimiterJsonCfg() (*ResourceLimiterServJsonCfg, er return cfg, nil } +func (self CgrJsonCfg) StatSJsonCfg() (*StatServJsonCfg, error) { + rawCfg, hasKey := self[utils.StatS] + if !hasKey { + return nil, nil + } + cfg := new(StatServJsonCfg) + if err := json.Unmarshal(*rawCfg, cfg); err != nil { + return nil, err + } + return cfg, nil +} + func (self CgrJsonCfg) MailerJsonCfg() (*MailerJsonCfg, error) { rawCfg, hasKey := self[MAILER_JSN] if !hasKey { diff --git a/config/config_json_test.go b/config/config_json_test.go index e66f4fcc8..bb50134a2 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -676,6 +676,18 @@ func TestDfResourceLimiterSJsonCfg(t *testing.T) { } } +func TestDfStatServiceJsonCfg(t *testing.T) { + eCfg := &StatServJsonCfg{ + Enabled: utils.BoolPointer(false), + Cache_dump_interval: utils.StringPointer("0s"), + } + if cfg, err := dfCgrJsonCfg.StatSJsonCfg(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eCfg, cfg) { + t.Error("Received: ", cfg) + } +} + func TestDfMailerJsonCfg(t *testing.T) { eCfg := &MailerJsonCfg{ Server: utils.StringPointer("localhost"), diff --git a/config/libconfig_json.go b/config/libconfig_json.go index f78a0c0ba..6af793245 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -383,6 +383,12 @@ type ResourceLimiterServJsonCfg struct { Cache_dump_interval *string } +// Stat service config section +type StatServJsonCfg struct { + Enabled *bool + Cache_dump_interval *string +} + // Mailer config section type MailerJsonCfg struct { Server *string diff --git a/config/statscfg.go b/config/statscfg.go new file mode 100644 index 000000000..851d4776b --- /dev/null +++ b/config/statscfg.go @@ -0,0 +1,44 @@ +/* +Real-time Online/Offline Charging System (OCS) 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 +*/ +package config + +import ( + "time" + + "github.com/cgrates/cgrates/utils" +) + +type StatSCfg struct { + Enabled bool + CacheDumpInterval time.Duration // Dump regularly from cache into dataDB +} + +func (st *StatSCfg) loadFromJsonCfg(jsnCfg *StatServJsonCfg) (err error) { + if jsnCfg == nil { + return nil + } + if jsnCfg.Enabled != nil { + st.Enabled = *jsnCfg.Enabled + } + if jsnCfg.Cache_dump_interval != nil { + if st.CacheDumpInterval, err = utils.ParseDurationWithSecs(*jsnCfg.Cache_dump_interval); err != nil { + return err + } + } + return nil +} diff --git a/utils/consts.go b/utils/consts.go index d4fbb42c8..6a8d19e26 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -417,6 +417,7 @@ const ( CacheDerivedChargers = "derived_chargers" CacheResourceLimits = "resource_limits" CacheTimings = "timings" + StatS = "stats" ) func buildCacheInstRevPrefixes() {