Skip to content

Commit

Permalink
change config file format to yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
barryz committed May 15, 2018
1 parent 7c97e19 commit e267db8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 84 deletions.
48 changes: 0 additions & 48 deletions cfg.json.example

This file was deleted.

56 changes: 56 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# debug mode
debug: false
# getting metric details
details: true
# hostname specified
hostname: ""
# agent collect interval
interval: 10
# push batch-size metrics per-operation
batchsize: 100
# enable functions
enabled:
collect: true
witch: true
log_rotate: true

# http client settings (timeout in seconds)
http:
conn_timeout: 10
response_timeout: 10

# RabbitMQ settings
rabbitmq:
host: 127.0.0.1
port: 15672
user: admin
password: admin

# falcon settings
falcon:
api: "http://127.0.0.1:1988/v1/push"

# scheduler config
scheduler:
log_rotate: "0 11 18 ? * 0-6"

# witch config
witch:
listen: ":5671"
control: "buildin"
service: ""
command: "sleep 120"
process: "beam"
pid_file: "var/run/witch.pid"
auth:
admin: "ADMIN"

# filter for queues
ignore_queue:
- "test"
- "celery"

# status which indicate queue's running state
qrunning:
- "idle"
- "running"
2 changes: 1 addition & 1 deletion falcon/falcon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestGetStatsDB(t *testing.T) {
g.ParseConfig("../cfg.json.example")
g.ParseConfig("../config.example.yml")

//ov, err := funcs.GetOverview()
//if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion funcs/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestGetExchanges(t *testing.T) {
g.ParseConfig("../cfg.json.example")
g.ParseConfig("../config.example.yml")
//exchs, err := GetExchanges()
//if err != nil {
// t.Error(err.Error())
Expand Down
66 changes: 33 additions & 33 deletions g/cfg.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
package g

import (
"encoding/json"
"log"
"os"
"sync"

"github.com/toolkits/file"
"gopkg.in/yaml.v2"
)

// EnableConfig configs which can be used
type EnableConfig struct {
Collect bool `json:"collect"`
LogRotate bool `json:"log_rotate"`
Witch bool `json:"witch"`
Collect bool `yaml:"collect"`
LogRotate bool `yaml:"log_rotate"`
Witch bool `yaml:"witch"`
}

// RabbitConfig ...
type RabbitConfig struct {
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
}

// FalconConfig ...
type FalconConfig struct {
API string `json:"api"`
API string `yaml:"api"`
}

// HTTPConfig ...
type HTTPConfig struct {
ConnTimeout int `json:"conn_timeout"`
RespTimeout int `json:"response_timeout"`
ConnTimeout int `yaml:"conn_timeout"`
RespTimeout int `yaml:"response_timeout"`
}

// SchedulerConfig ...
type SchedulerConfig struct {
LogRotate string `json:"log_rotate"`
LogRotate string `yaml:"log_rotate"`
}

// WitchConfig Program Config ...
type WitchConfig struct {
ListenAddr string `json:"listen"`
Control string `json:"control"`
Service string `json:"service"`
Process string `json:"process"`
Command string `json:"command"`
PidFile string `json:"pid_file"`
Auth map[string]string `json:"auth"`
ListenAddr string `yaml:"listen"`
Control string `yaml:"control"`
Service string `yaml:"service"`
Process string `yaml:"process"`
Command string `yaml:"command"`
PidFile string `yaml:"pid_file"`
Auth map[string]string `yaml:"auth"`
}

// GlobalConfig ...
type GlobalConfig struct {
Debug bool `json:"debug"`
Details bool `json:"details"`
Hostname string `json:"hostname"`
Batchsize int `json:"batchsize"`
Interval int64 `json:"interval"`
Rabbit *RabbitConfig `json:"rabbitmq"`
Falcon *FalconConfig `json:"falcon"`
HTTP *HTTPConfig `json:"http"`
Cron *SchedulerConfig `json:"scheduler"`
Enabled *EnableConfig `json:"enabled"`
Ignores []string `json:"ignore_queue"`
Qrunning []string `json:"qrunning"`
Witch *WitchConfig `json:"witch"`
Debug bool `yaml:"debug"`
Details bool `yaml:"details"`
Hostname string `yaml:"hostname"`
Batchsize int `yaml:"batchsize"`
Interval int64 `yaml:"interval"`
Rabbit *RabbitConfig `yaml:"rabbitmq"`
Falcon *FalconConfig `yaml:"falcon"`
HTTP *HTTPConfig `yaml:"http"`
Cron *SchedulerConfig `yaml:"scheduler"`
Enabled *EnableConfig `yaml:"enabled"`
Ignores []string `yaml:"ignore_queue"`
Qrunning []string `yaml:"qrunning"`
Witch *WitchConfig `yaml:"witch"`
}

var (
Expand Down Expand Up @@ -93,7 +93,7 @@ func ParseConfig(cfg string) {
log.Fatalln("[ERROR]: read config file:", cfg, "fail:", err)
}

err = json.Unmarshal([]byte(configContent), &c)
err = yaml.Unmarshal([]byte(configContent), &c)
if err != nil {
log.Fatalln("[ERROR]: read config file:", cfg, "fail:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion witch/witch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func Test_SystemLauncher(t *testing.T) {
g.ParseConfig("../cfg.json.example")
g.ParseConfig("../config.example.yml")

//Launch()
//
Expand Down

0 comments on commit e267db8

Please sign in to comment.