现在的位置: 首页 > 综合 > 正文

Scribe核心分析

2013年04月30日 ⁄ 综合 ⁄ 共 2122字 ⁄ 字号 评论关闭

Facebook Scribe日志聚合系统有三个核心内容:Configurarion(配置)、Running Scribe Server(运行服务器)、Logging messages(记录日志)

Logging Messages(记录日志)

Scribe 执行下面thrift接口:

enum ResultCode
{
OK,
TRY_LATER
}

struct LogEntry
{
1: string category,
2: string message
}

service scribe extends fb303.FacebookService
{
ResultCode Log(1: list messages);
}

为了给指定主机和端口的Scribe服务器发送一条消息,我们需要简单地创建一个Scribe Client和调用Log()方法,下面是使用Python写的一个实例:

from scribe import scribe
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol

category='test'
message='hello world'
log_entry = scribe.LogEntry(category, message)
# depending on thrift version
#
log_entry = scribe.LogEntry(dict(category=category, message=message))

socket = TSocket.TSocket(host='localhost', port=1463)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
client = scribe.Client(iprot=protocol, oprot=protocol)

transport.open()
result = client.Log(messages=[log_entry])
transport.close()

Running Scribe Server(运行服务器)

$scribed [ -p  ] [ -c  ] #启动scribe服务器
$scribe_ctrl stop [ ] #停止Scribe服务器
$scribe_ctrl {command} [ ] #监控、管理Scribe服务器

scribe_ctrl 的子命令:

status – 如果服务器运行正常则返回'ALIVE'

version – 返回当前Scribe服务器的版本

alive – 返回服务器运行时间

stop – 停止Scribe服务器

reload – 重新加载Scribe配置文件

counters – 返回下列统计信息 (如果非零):

  • received good: 返回Scribe服务器启动后接收到的信息数
  • received bad: 接收到的非法信息数
  • sent:发送到另一台Scribe服务器的信息数
  • denied for queue size: 因信息队列满被禁止的请求数
  • denied for rate: 由于速度限制而被禁止的请求数
  • retries: 缓冲储存重试发送一批消息的次数
  • requeue: Scribe发送消息到一个Store的次数 (如果must_succeed 启用).
  • lost: 没有记录的消息的数量。(推荐配置: 使用Buffer Stores 避免信息丢失)
  • received blank category: 接收到的没有信息类别的信息数量

 

Configurarion(配置)

Scribe Server是通过配置文件启动的。 

  • null:丢弃所有消息
  • multi:给所有multi类型的store传递消息
  • file:将消息写入文件
  • thriftfile:类似于file,但写入的文件类型为thrift TfileTransport文件
  • network:将消息转发给另外一个scribe server
  • buffer:包含两个子store(主、次),在主store工作时,直接使用主store记录日志,只 有当主store不可用时,才使用次store记录。而且一旦主store恢复工作,次 stroe记录的日志将转移到主store。
  • bucket:包含一系列的其他类型的stroe,具体使用哪个是由所定义的Hash函数决定的

更详细的配置信息参见:https://github.com/facebook/scribe/wiki/Scribe-Configuration

 

3.Server的启动过程的流程图:

Log过程的流程图:

客户端调用Log(messages)函数发送消息,通过thrift框架的实现,远程方法scribeHandler:: Log(const vector& messages)函数被调用,过程如下:

 

 

参考文章:http://blog.csdn.net/kohaku/article/details/6049183

https://github.com/facebook/scribe/wiki/

抱歉!评论已关闭.