support-logging是所有微服务的log集中管理的微服务,support-logging的使用介绍如下,他有5个启动参数可以配置:
- registry是一个bool量,True表示support-logging的配置参数是从consul拉取,False表示从本地配置文件载入。
- profile本地配置文件的路径, 即便registry=True, 该参数也必须要指明一个配置文件,因为连接consul服务所需的host,port等参数必须从本地的配置文件中获取。
Usage: %s [options]
Server Options:
-r, --registry Indicates service should use Registry
-p, --profile <name> Indicate configuration profile other than default
Common Options:
-h, --help Show this message
Table of Contents
support-logging的配置文件
[Writable]
Persistence = 'database'
LogLevel = 'INFO'
[Service]
BootTimeout = 30000
ClientMonitor = 15000
CheckInterval = '10s'
Host = 'localhost'
Port = 48061
Protocol = 'http'
ReadMaxLimit = 100
StartupMsg = 'This is the Support Logging Microservice'
Timeout = 5000
[Registry]
Host = 'localhost'
Port = 8500
Type = 'consul'
[Logging]
File = './logs/edgex-support-logging.log'
[Databases]
[Databases.Primary]
Host = 'localhost'
Name = 'logging'
Password = ''
Port = 27017
Username = ''
Timeout = 5000
Type = 'mongodb'
如上是项目自带的support-logging的配置文件 ,主要分5部分,support-logging启动后会将配置文件的信息导入如下结构中,若registry=True则根据Registry中的信息连接consul并拉取相应的配置信息覆盖之前从本地配置文件中读取到的信息。
type ConfigurationStruct struct {
Writable WritableInfo
Databases map[string]config.DatabaseInfo
Logging config.LoggingInfo
Registry config.RegistryInfo
Service config.ServiceInfo
}
Writable
type WritableInfo struct {
Persistence string
LogLevel string
}
Persistence: Log持久化的方式,目前支持 ‘database’ 和 'file' 两种。
LogLevel: Log等级。
若从consul载入配置信息,support-logging会监听consul中的Writable信息并及时更新。然后根据更新的信息切换Log等级,不过目前代码不支持切换Log持久化方式。
Databases
type DatabaseInfo struct {
Type string
Timeout int
Host string
Port int
Username string
Password string
Name string
}
只有Persistence==‘database’时, Databases参数才会被使用,当前仅支持Primary数据库mongoDB。但是,
从代码
Databases map[string]config.DatabaseInfo
可以看出未来应该会支持多种,多个数据库持久化log。
Type 数据库类型,目前仅支持 mongodb
Timeout 数据库连接超时,单位:s
Host 数据库地址
Port 数据库端口
Username 数据库登录用户名
Password 数据库登录密码
Name 数据库名字
Logging
type LoggingInfo struct {
EnableRemote bool
File string
}
只有Persistence==‘file’时, Logging参数才会被使用。
EnableRemote:目前这个参数无用,一旦Persistence==‘file’, log就会默认存入本地文件中而非远程的文件。
File: 本地Log的路径。
Registry
type RegistryInfo struct {
Host string
Port int
Type string
}
consul连接参数
Service
type ServiceInfo struct {
// BootTimeout indicates, in milliseconds, how long the service will retry connecting to upstream dependencies
// before giving up. Default is 30,000.
BootTimeout int
// Health check interval
CheckInterval string
// Indicates the interval in milliseconds at which service clients should check for any configuration updates
ClientMonitor int
// Host is the hostname or IP address of the service.
Host string
// Port is the HTTP port of the service.
Port int
// The protocol that should be used to call this service
Protocol string
// StartupMsg specifies a string to log once service
// initialization and startup is completed.
StartupMsg string
// ReadMaxLimit specifies the maximum size list supported
// in response to REST calls to other services.
ReadMaxLimit int
// Timeout specifies a timeout (in milliseconds) for
// processing REST calls from other services.
Timeout int
}
Service字段时微服务对外提供接口的设置参数,每个微服务都会有这个参数,而且字段的含义相同。
BootTimeout 微服务连接时的超时参数,以core-command微服务微服务为例,core-command启动的时候如果是能远程log服务的话,会不断的尝试连接support-logging服务直到成功为止或者启动时间超过该参数,单位:毫秒
CheckInterval 与consul连接的健康检查周期
ClientMonitor 连接到该微服务的client的健康检查周期,单位:毫秒
Host 未用,硬编码将服务绑定到所有的网卡,相当于 '0.0.0.0'
Port support-logging提供服务的端口
Protocol 微服务使用的协议,目前仅支持http
StartupMsg 启动成功后会打印该字段到log
ReadMaxLimit 微服务响应请求时所允许的最大数量限制,单位不是字节,取决于具体请求类型,如若请求查看所有设备信息,则最多只能返回ReadMaxLimit 的设备信息
Timeout 微服务响应请求的超时时间,单位:毫秒