use _ vars
This commit is contained in:
parent
7c266a21d5
commit
338bb50b66
|
@ -1,37 +1,37 @@
|
|||
[Global]
|
||||
[global]
|
||||
# whether print configs
|
||||
PrintConfig = false
|
||||
print_configs = false
|
||||
# add label(agent_hostname) to series
|
||||
Hostname = ""
|
||||
hostname = ""
|
||||
# will not add label(agent_hostname) if true
|
||||
OmitHostname = false
|
||||
omit_hostname = false
|
||||
# s | ms
|
||||
Precision = "ms"
|
||||
precision = "ms"
|
||||
# global collect interval
|
||||
IntervalSeconds = 15
|
||||
interval_seconds = 15
|
||||
|
||||
[Global.Labels]
|
||||
[global.labels]
|
||||
region = "shanghai"
|
||||
env = "localhost"
|
||||
|
||||
[WriterOpt]
|
||||
[writer_opt]
|
||||
# default: 2000
|
||||
Batch = 2000
|
||||
batch = 2000
|
||||
|
||||
[[Writers]]
|
||||
Url = "http://127.0.0.1:19000/prometheus/v1/write"
|
||||
[[writers]]
|
||||
url = "http://127.0.0.1:19000/prometheus/v1/write"
|
||||
# Basic auth username
|
||||
BasicAuthUser = ""
|
||||
basic_auth_user = ""
|
||||
# Basic auth password
|
||||
BasicAuthPass = ""
|
||||
basic_auth_pass = ""
|
||||
# timeout settings, unit: ms
|
||||
Timeout = 3000
|
||||
DialTimeout = 3000
|
||||
TLSHandshakeTimeout = 3000
|
||||
ExpectContinueTimeout = 1000
|
||||
IdleConnTimeout = 90000
|
||||
timeout = 3000
|
||||
dial_timeout = 3000
|
||||
tls_handshake_timeout = 3000
|
||||
expect_continue_timeout = 1000
|
||||
idle_conn_timeout = 90000
|
||||
# time duration, unit: ms
|
||||
KeepAlive = 30000
|
||||
MaxConnsPerHost = 0
|
||||
MaxIdleConns = 100
|
||||
MaxIdleConnsPerHost = 100
|
||||
keep_alive = 30000
|
||||
max_conns_per_host = 0
|
||||
max_idle_conns = 100
|
||||
max_idle_conns_per_host = 100
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# # whether collect per cpu
|
||||
# CollectPerCPU = false
|
||||
# # whether print configs
|
||||
# print_configs = false
|
||||
|
||||
# # collect interval, default 15s
|
||||
# IntervalSeconds = 15
|
||||
# interval_seconds = 15
|
||||
|
||||
# # whether collect per cpu
|
||||
# collect_per_cpu = false
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# # whether collect platform specified metrics
|
||||
# CollectPlatformFields = false
|
||||
# # whether print configs
|
||||
# print_configs = false
|
||||
|
||||
# # collect interval, default 15s
|
||||
# IntervalSeconds = 15
|
||||
# interval_seconds = 15
|
||||
|
||||
# # whether collect platform specified metrics
|
||||
# collect_platform_fields = false
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# # whether collect metric: system_n_users
|
||||
# CollectUserNumber = false
|
||||
# # whether print configs
|
||||
# print_configs = false
|
||||
|
||||
# # collect interval, default 15s
|
||||
# IntervalSeconds = 15
|
||||
# interval_seconds = 15
|
||||
|
||||
# # whether collect metric: system_n_users
|
||||
# collect_user_number = false
|
||||
|
|
|
@ -13,43 +13,45 @@ import (
|
|||
)
|
||||
|
||||
type Global struct {
|
||||
PrintConfig bool
|
||||
Hostname string
|
||||
OmitHostname bool
|
||||
Labels map[string]string
|
||||
Precision string
|
||||
IntervalSeconds int64
|
||||
PrintConfigs bool `toml:"print_configs"`
|
||||
Hostname string `toml:"hostname"`
|
||||
OmitHostname bool `toml:"omit_hostname"`
|
||||
Labels map[string]string `toml:"labels"`
|
||||
Precision string `toml:"precision"`
|
||||
IntervalSeconds int64 `toml:"interval_seconds"`
|
||||
}
|
||||
|
||||
type WriterOpt struct {
|
||||
Batch int
|
||||
Batch int `toml:"batch"`
|
||||
}
|
||||
|
||||
type WriterOption struct {
|
||||
Url string
|
||||
BasicAuthUser string
|
||||
BasicAuthPass string
|
||||
Url string `toml:"url"`
|
||||
BasicAuthUser string `toml:"basic_auth_user"`
|
||||
BasicAuthPass string `toml:"basic_auth_pass"`
|
||||
|
||||
Timeout int64
|
||||
DialTimeout int64
|
||||
TLSHandshakeTimeout int64
|
||||
ExpectContinueTimeout int64
|
||||
IdleConnTimeout int64
|
||||
KeepAlive int64
|
||||
Timeout int64 `toml:"timeout"`
|
||||
DialTimeout int64 `toml:"dial_timeout"`
|
||||
TLSHandshakeTimeout int64 `toml:"tls_handshake_timeout"`
|
||||
ExpectContinueTimeout int64 `toml:"expect_continue_timeout"`
|
||||
IdleConnTimeout int64 `toml:"idle_conn_timeout"`
|
||||
KeepAlive int64 `toml:"keep_alive"`
|
||||
|
||||
MaxConnsPerHost int
|
||||
MaxIdleConns int
|
||||
MaxIdleConnsPerHost int
|
||||
MaxConnsPerHost int `toml:"max_conns_per_host"`
|
||||
MaxIdleConns int `toml:"max_idle_conns"`
|
||||
MaxIdleConnsPerHost int `toml:"max_idle_conns_per_host"`
|
||||
}
|
||||
|
||||
type ConfigType struct {
|
||||
// from console args
|
||||
ConfigDir string
|
||||
DebugMode bool
|
||||
TestMode bool
|
||||
WriterOpt WriterOpt
|
||||
|
||||
Global Global
|
||||
Writers []WriterOption
|
||||
// from config.toml
|
||||
Global Global `toml:"global"`
|
||||
WriterOpt WriterOpt `toml:"writer_opt"`
|
||||
Writers []WriterOption `toml:"writers"`
|
||||
}
|
||||
|
||||
var Config *ConfigType
|
||||
|
@ -87,7 +89,7 @@ func InitConfig(configDir, debugMode string, testMode bool) error {
|
|||
Config.Global.IntervalSeconds = 15
|
||||
}
|
||||
|
||||
if Config.Global.PrintConfig {
|
||||
if Config.Global.PrintConfigs {
|
||||
bs, _ := json.MarshalIndent(Config, "", " ")
|
||||
fmt.Println(string(bs))
|
||||
}
|
||||
|
|
|
@ -17,15 +17,12 @@ import (
|
|||
const InputName = "cpu"
|
||||
|
||||
type CPUStats struct {
|
||||
PrintConfigs bool
|
||||
IntervalSeconds int64
|
||||
|
||||
quit chan struct{}
|
||||
lastStats map[string]cpuUtil.TimesStat
|
||||
|
||||
ps system.PS
|
||||
|
||||
CollectPerCPU bool
|
||||
quit chan struct{} `toml:"-"`
|
||||
ps system.PS `toml:"-"`
|
||||
lastStats map[string]cpuUtil.TimesStat `toml:"-"`
|
||||
PrintConfigs bool `toml:"print_configs"`
|
||||
IntervalSeconds int64 `toml:"interval_seconds"`
|
||||
CollectPerCPU bool `toml:"collect_per_cpu"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
package disk
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "log"
|
||||
// "runtime"
|
||||
// "strings"
|
||||
// "time"
|
||||
|
||||
// "flashcat.cloud/categraf/config"
|
||||
// "flashcat.cloud/categraf/inputs"
|
||||
// "flashcat.cloud/categraf/inputs/system"
|
||||
// "flashcat.cloud/categraf/types"
|
||||
// )
|
||||
|
||||
// const InputName = "disk"
|
||||
|
||||
// type DiskStats struct {
|
||||
// PrintConfigs bool
|
||||
// IntervalSeconds int64
|
||||
|
||||
// quit chan struct{}
|
||||
|
||||
// ps system.PS
|
||||
|
||||
// CollectPlatformFields bool
|
||||
// }
|
||||
|
||||
// func init() {
|
||||
// ps := system.NewSystemPS()
|
||||
// inputs.Add(InputName, func() inputs.Input {
|
||||
// return &DiskStats{
|
||||
// ps: ps,
|
||||
// quit: make(chan struct{}),
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// func (s *DiskStats) getInterval() time.Duration {
|
||||
// if s.IntervalSeconds != 0 {
|
||||
// return time.Duration(s.IntervalSeconds) * time.Second
|
||||
// }
|
||||
// return config.GetInterval()
|
||||
// }
|
||||
|
||||
// // overwrite func
|
||||
// func (s *DiskStats) Init() error {
|
||||
// s.platform = runtime.GOOS
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// // overwrite func
|
||||
// func (s *DiskStats) StopGoroutines() {
|
||||
// s.quit <- struct{}{}
|
||||
// }
|
||||
|
||||
// // overwrite func
|
||||
// func (s *DiskStats) StartGoroutines(queue chan *types.Sample) {
|
||||
// go s.LoopGather(queue)
|
||||
// }
|
||||
|
||||
// func (s *DiskStats) LoopGather(queue chan *types.Sample) {
|
||||
// interval := s.getInterval()
|
||||
// for {
|
||||
// select {
|
||||
// case <-s.quit:
|
||||
// close(s.quit)
|
||||
// return
|
||||
// default:
|
||||
// time.Sleep(interval)
|
||||
// s.Gather(queue)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // overwrite func
|
||||
// func (s *DiskStats) Gather(queue chan *types.Sample) {
|
||||
// var samples []*types.Sample
|
||||
|
||||
// defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// if strings.Contains(fmt.Sprint(r), "closed channel") {
|
||||
// return
|
||||
// } else {
|
||||
// log.Println("E! gather metrics panic:", r)
|
||||
// }
|
||||
// }
|
||||
|
||||
// now := time.Now()
|
||||
// for i := 0; i < len(samples); i++ {
|
||||
// samples[i].Timestamp = now
|
||||
// samples[i].Metric = InputName + "_" + samples[i].Metric
|
||||
// queue <- samples[i]
|
||||
// }
|
||||
// }()
|
||||
|
||||
// // ----------------------------------------------
|
||||
|
||||
// vm, err := s.ps.VMStat()
|
||||
// if err != nil {
|
||||
// log.Println("E! failed to get vmstat:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// fields := map[string]interface{}{
|
||||
// "total": vm.Total, // bytes
|
||||
// "available": vm.Available, // bytes
|
||||
// "used": vm.Used, // bytes
|
||||
// "used_percent": 100 * float64(vm.Used) / float64(vm.Total),
|
||||
// "available_percent": 100 * float64(vm.Available) / float64(vm.Total),
|
||||
// }
|
||||
|
||||
// if s.CollectPlatformFields {
|
||||
// switch s.platform {
|
||||
// case "darwin":
|
||||
// fields["active"] = vm.Active
|
||||
// fields["free"] = vm.Free
|
||||
// fields["inactive"] = vm.Inactive
|
||||
// fields["wired"] = vm.Wired
|
||||
// case "openbsd":
|
||||
// fields["active"] = vm.Active
|
||||
// fields["cached"] = vm.Cached
|
||||
// fields["free"] = vm.Free
|
||||
// fields["inactive"] = vm.Inactive
|
||||
// fields["wired"] = vm.Wired
|
||||
// case "freebsd":
|
||||
// fields["active"] = vm.Active
|
||||
// fields["buffered"] = vm.Buffers
|
||||
// fields["cached"] = vm.Cached
|
||||
// fields["free"] = vm.Free
|
||||
// fields["inactive"] = vm.Inactive
|
||||
// fields["laundry"] = vm.Laundry
|
||||
// fields["wired"] = vm.Wired
|
||||
// case "linux":
|
||||
// fields["active"] = vm.Active
|
||||
// fields["buffered"] = vm.Buffers
|
||||
// fields["cached"] = vm.Cached
|
||||
// fields["commit_limit"] = vm.CommitLimit
|
||||
// fields["committed_as"] = vm.CommittedAS
|
||||
// fields["dirty"] = vm.Dirty
|
||||
// fields["free"] = vm.Free
|
||||
// fields["high_free"] = vm.HighFree
|
||||
// fields["high_total"] = vm.HighTotal
|
||||
// fields["huge_pages_free"] = vm.HugePagesFree
|
||||
// fields["huge_page_size"] = vm.HugePageSize
|
||||
// fields["huge_pages_total"] = vm.HugePagesTotal
|
||||
// fields["inactive"] = vm.Inactive
|
||||
// fields["low_free"] = vm.LowFree
|
||||
// fields["low_total"] = vm.LowTotal
|
||||
// fields["mapped"] = vm.Mapped
|
||||
// fields["page_tables"] = vm.PageTables
|
||||
// fields["shared"] = vm.Shared
|
||||
// fields["slab"] = vm.Slab
|
||||
// fields["sreclaimable"] = vm.Sreclaimable
|
||||
// fields["sunreclaim"] = vm.Sunreclaim
|
||||
// fields["swap_cached"] = vm.SwapCached
|
||||
// fields["swap_free"] = vm.SwapFree
|
||||
// fields["swap_total"] = vm.SwapTotal
|
||||
// fields["vmalloc_chunk"] = vm.VmallocChunk
|
||||
// fields["vmalloc_total"] = vm.VmallocTotal
|
||||
// fields["vmalloc_used"] = vm.VmallocUsed
|
||||
// fields["write_back_tmp"] = vm.WriteBackTmp
|
||||
// fields["write_back"] = vm.WriteBack
|
||||
// }
|
||||
// }
|
||||
|
||||
// samples = inputs.NewSamples(fields)
|
||||
// }
|
|
@ -16,15 +16,12 @@ import (
|
|||
const InputName = "mem"
|
||||
|
||||
type MemStats struct {
|
||||
PrintConfigs bool
|
||||
IntervalSeconds int64
|
||||
|
||||
quit chan struct{}
|
||||
|
||||
ps system.PS
|
||||
platform string
|
||||
|
||||
CollectPlatformFields bool
|
||||
quit chan struct{} `toml:"-"`
|
||||
ps system.PS `toml:"-"`
|
||||
platform string `toml:"-"`
|
||||
PrintConfigs bool `toml:"print_configs"`
|
||||
IntervalSeconds int64 `toml:"interval_seconds"`
|
||||
CollectPlatformFields bool `toml:"collect_platform_fields"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -18,12 +18,10 @@ import (
|
|||
const InputName = "system"
|
||||
|
||||
type SystemStats struct {
|
||||
PrintConfigs bool
|
||||
IntervalSeconds int64
|
||||
|
||||
quit chan struct{}
|
||||
|
||||
CollectUserNumber bool
|
||||
quit chan struct{} `toml:"-"`
|
||||
PrintConfigs bool `toml:"print_configs"`
|
||||
IntervalSeconds int64 `toml:"interval_seconds"`
|
||||
CollectUserNumber bool `toml:"collect_user_number"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
Loading…
Reference in New Issue