感谢您提供反馈

这篇文章已经过机器翻译.放弃

教程-使用协议扩展对 syslog 消息进行负载平衡

NetScaler 设备上可用的 Syslog 协议仅适用于 NetScaler 设备上生成的消息。它不会对来自外部节点的消息进行负载平衡。要对此类消息进行负载平衡,您需要使用协议扩展功能并使用 Lua 5.2 编程语言编写 syslog 消息解析逻辑。

用于解析 syslog 消息的代码

该代码仅定义了 TCP 客户端数据回调函数 - client.on_data()。对于服务器数据,它不添加回调函数,服务器到客户端采用快速的本地路径。该代码根据尾部字符识别消息边界。如果 TCP 数据包包含多个 syslog 消息,那么我们根据尾随字符拆分数据包,并平衡每个消息的负载。

--[[ Syslog event handler for TCP client data ctxt - TCP client side App processing context. data - TCP Data stream received. --]] function client.on_data(ctxt, payload) local message = nil local data_len local data = payload.data local trailing_character = "\n" ::split_message:: -- Get the offset of trailing character local new_line_character_offset = data:find(trailing_character) -- If trailing character is not found, then wait for more data. if (not new_line_character_offset) then goto need_more_data end -- Get the length of the current message data_len = data:len() -- Check whether we have more than one message -- by comparing trailing character offset and -- current data length if (data_len > new_line_character_offset) then -- If we have more than one message, then split -- the data into two parts such that first part -- will contain message upto trailing character -- offset and second part will contain -- remaining message. message, data = data:split(new_line_character_offset) else message = data data = nil end -- Send the data to the backend server. ns.send(ctxt.output, "EOM", {data = message}) goto done ::need_more_data:: -- Wait for more data ctxt:hold(data) data = nil goto done ::done:: -- If we have more data to parse, -- then do parsing again. if (data) then goto split_message end end
本内容的正式版本为英文版。部分 Cloud Software Group 文档内容采用了机器翻译,仅供您参考。Cloud Software Group 无法控制机器翻译的内容,这些内容可能包含错误、不准确或不合适的语言。对于从英文原文翻译成任何其他语言的内容的准确性、可靠性、适用性或正确性,或者您的 Cloud Software Group 产品或服务沿用了任何机器翻译的内容,我们均不作任何明示或暗示的保证,并且适用的最终用户许可协议或服务条款或者与 Cloud Software Group 签订的任何其他协议(产品或服务与已进行机器翻译的任何文档保持一致)下的任何保证均不适用。对于因使用机器翻译的内容而引起的任何损害或问题,Cloud Software Group 不承担任何责任。
教程-使用协议扩展对 syslog 消息进行负载平衡