local ffi = require("ffi")
ffi.cdef[[
struct timeval {
long int tv_sec;
long int tv_usec;
};
int gettimeofday(struct timeval *tv, void *tz);
]]
--获取时间 年月日时分秒毫秒
local tm = ffi.new("struct timeval")
function RequestId()
ffi.C.gettimeofday(tm,nil)
local sec = tonumber(tm.tv_sec)
local usec = tonumber(tm.tv_usec)
return os.date("%Y%m%d%H%M")..sec..usec
end
不知道这种方式可以不?
在 2016年1月21日星期四 UTC+8上午11:33:41,徐涛写道:
我是“服务器序号+时间戳+进程号+”组装成一个唯一的id
local local_id = "10.77.10.77"
local req_id = local_id .. '-' .. ngx.now() .. '-' .. ngx.var.pid .. '-' .. (ngx.var.connection%4096)
在 2016-01-21 10:54:56,"黄川" <
chua...@gmail.com> 写道:
我就是用上面的library产生random uuid,我也自己循环分派requestid像从1-
10k对于每一个worker
On Wednesday, January 20, 2016 at 3:07:38 AM UTC-8, xiaooloong wrote:http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format最后选用了nginx的变量
$connection
connection serial number
$connection_requests
the current number of requests made through a connection (1.1.18)
作为请求ID
在 2016年1月20日星期三 UTC+8下午5:10:22,wd写道:
调用 uuid 产生一个?
2016-01-20 17:02 GMT+08:00 xiaooloong
<xiaooo...@gmail.com>:
没有找到 nginx 里能提供 request id 的 api 或者变量
当前能想到的方法是
local uniq_req_id = ngx.md5( ngx.req.raw_header() .. ngx.now() )
问题是 ngx.now() 获取到的是 nginx 的缓存时间,虽然可以用 ngx.update_time() 刷新时间,但是文档中提到会发生系统调用,担心影响性能
针对每一次请求而言,ngx.now() 获取的时间是否会出现相同的情况呢?
--
--