StatS config

This commit is contained in:
DanB
2017-08-02 11:00:34 +02:00
parent 2c01491424
commit f797c32599
7 changed files with 87 additions and 0 deletions

View File

@@ -264,6 +264,7 @@ type CGRConfig struct {
UserServerEnabled bool // Starts User as server: <true|false>
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

View File

@@ -409,6 +409,12 @@ const CGRATES_CFG_JSON = `
},
"stats": {
"enabled": false, // starts ResourceLimiter service: <true|false>.
"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

View File

@@ -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 {

View File

@@ -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"),

View File

@@ -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

44
config/statscfg.go Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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
}

View File

@@ -417,6 +417,7 @@ const (
CacheDerivedChargers = "derived_chargers"
CacheResourceLimits = "resource_limits"
CacheTimings = "timings"
StatS = "stats"
)
func buildCacheInstRevPrefixes() {