Documentation
¶
Index ¶
Constants ¶
View Source
const ( WebAPPName = "XY.DataRouter" CurrentVersion = "1.0.12.21051313" LastChange = "Milestone Version" ProjectName = "xydatarouter" // 日志级别: -1Trace 0Debug 1Info 2Warn 3Error(默认) 4Fatal 5Panic 6NoLevel 7Off LogLevel = 3 // 抽样日志设置 (每秒最多 3 个日志) LogSamplePeriodDur = time.Second LogSampleBurst = 3 // 每 100M 自动切割, 保留 30 天内最近 10 个日志文件 LogFileMaxSize = 100 LogFileMaxBackups = 10 LogFileMaxAge = 30 // HTTP 接口端口 WebServerAddr = ":6600" // ES 慢查询日志时间设置, 默认: > 10秒则记录 ESSlowQueryDuration = 10 * time.Second // Web 慢响应日志时间设置, 默认: > 1秒则记录 WebSlowRespDuration = time.Second // HTTP 响应码日志记录, 默认: 500, 即大于等于 500 的状态码记录日志 WebErrorCodeLog = 500 // POST 最大 500M, Request Entity Too Large BodyLimit = 500 << 20 // UDP 接口端口, 不应答(Echo包除外) UDPServerRAddr = ":6611" // UDP 接口端口, 每个包都应答字符: 1 UDPServerRWAddr = ":6622" // 1. 在链路层, 由以太网的物理特性决定了数据帧的长度为 (46+18) - (1500+18) // 其中的 18 是数据帧的头和尾, 也就是说数据帧的内容最大为 1500 (不包括帧头和帧尾) // 即 MTU (Maximum Transmission Unit) 为 1500 // 2. 在网络层, 因为 IP 包的首部要占用 20 字节, 所以这的 MTU 为 1500 - 20 = 1480 // 3. 在传输层, 对于 UDP 包的首部要占用 8 字节, 所以这的 MTU 为 1480 - 8 = 1472 // 4. UDP 协议中有 16 位的 UDP 报文长度, 即 UDP 报文长度不能超过 65536, 则数据最大为 65507 UDPMaxRW = 65507 // UDP Goroutine 并发读取的数量 / CPU UDPGoReadNum1CPU = 50 UDPGoReadNumMax = 1000 // ES 数据分隔符 ESBodySep = "=-:-=" ESIndexSep = "=--=" // ES 单次批量写入最大条数或最大字节数 ESPostBatchNum = 3000 ESPOSTBatchBytes = 30 << 20 // Redis Auth 短语环境变量 Key RedisAuthKeyName = "DR_REDIS_AUTH" // Redis 单个 CPU 的连接池数, 默认为 10 connection pool timeout RedisPoolSize1CPU = 50 // Redis 连接池最大值 RedisPoolSizeMax = 1500 // 原始数据 Key 过期时间, 默认 30 秒, OOM command not allowed when used memory > 'maxmemory' SRCKeyExpire = 30 // 数据分发协程数(默认是 10 * runtime.NumCPU(), 以配置文件优先) DataRouterNum1CPU = 10 // 数据汇聚分隔符 redis_key=-|-=redis_data DataAggsQueueSep = "=-|-=" DataAggsQueueSepLen = 5 // 数据汇聚队列处理协程 / CPU DataAggsNum1CPU = 2 // (毫秒)数据汇聚推送到 Redis 的时间间隔或数量间隔 DataAggsPushMs = 200 RedisPipelineLimit = 8000 // 项目基础密钥 (环境变量名) BaseSecretKeyName = "DR_BASE_SECRET_KEY" // 用于解密基础密钥值的密钥 (编译在程序中) BaseSecretSalt = "Fufu@dr.777" // 文件变化监控时间间隔(分) WatcherInterval = 1 // 心跳日志索引 HeartbeatIndex = "monitor_heartbeat_report" ReqAPIName = "REQ_API_NAME" ReqAPIBody = "REQ_API_BODY" )
Variables ¶
View Source
var APIConfig map[string]TAPIConf
以接口名为键的配置
View Source
var ConfigFile = filepath.Join(FilePath, ProjectName+".json")
默认配置文件路径
View Source
var ESWhiteListConfig map[*net.IPNet]struct{}
ES 接口 IP 白名单配置
View Source
var FilePath = filepath.Join(RootPath, "..", "etc")
配置文件绝对路径
View Source
var LogDaemon = filepath.Join(LogDir, "daemon.log")
守护日志
View Source
var LogDir = filepath.Join(RootPath, "..", "log")
日志路径
View Source
var LogFile = filepath.Join(LogDir, ProjectName+".log")
View Source
var ReqUserAgent = req.Header{"User-Agent": WebAPPName + "/" + CurrentVersion}
请求名称
View Source
var RootPath = utils.ExecutableDir(true)
运行绝对路径
View Source
var UDPESIndexField = "_x"
UDP 接口 ES 索引字段
Functions ¶
Types ¶
type TAPIConf ¶
type TAPIConf struct { APIName string `json:"api_name"` ESIndex string `json:"es_index"` ESIndexSplit string `json:"es_index_split"` RequiredField []string `json:"required_field"` PostAPI TPostAPIConf `json:"post_api"` }
type TFilesConf ¶
type TJSONConf ¶
type TJSONConf struct { SYSConf TSYSConf `json:"sys_conf"` APIConf []TAPIConf `json:"api_conf"` ESWhiteList []string `json:"es_white_list"` }
接口配置
var Config TJSONConf
所有配置
type TPostAPIConf ¶
type TSYSConf ¶
type TSYSConf struct { Debug bool `json:"debug"` PProfAddr string `json:"pprof_addr"` Log tLogConf `json:"log"` WebServerAddr string `json:"web_server_addr"` BodyLimit int `json:"body_limit"` ESSlowQuery int `json:"es_slow_query"` WebSlowResponse int `json:"web_slow_response"` WebErrCodeLog int `json:"web_errcode_log"` UDPServerRAddr string `json:"udp_server_raddr"` UDPServerRWAddr string `json:"udp_server_rwaddr"` ESAddress []string `json:"es_address"` RedisAddress string `json:"redis_address"` RedisAuthKeyName string `json:"redis_auth_key_name"` RedisPoolSize1CPU int `json:"redis_poolsize_1cpu"` DataRouterNum1CPU int `json:"datarouter_num_1cpu"` DataAggsNum1CPU int `json:"data_aggs_num_1cpu"` DataAggsPushMs int `json:"data_aggs_push_ms"` RedisPipelineLimit int `json:"redis_pipeline_limit"` UDPGoReadNum1CPU int `json:"udp_go_read_num_1cpu"` UDPProto string `json:"udp_proto"` MainConfig TFilesConf `json:"main_config"` RestartMain bool `json:"restart_main"` WatcherInterval int `json:"watcher_interval"` HeartbeatIndex string `json:"heartbeat_index"` BaseSecretValue string RedisAuthValue string DataRouterNum int SRCKeyExpire int WebSlowRespDuration time.Duration ESSlowQueryDuration time.Duration DataAggsPushDuration time.Duration LogLimitDuration time.Duration }
主配置, 变量意义见配置文件中的描述及 constants.go 中的默认值
Click to show internal directories.
Click to hide internal directories.