0

I have next nginx location with Lua code (used with nginx lua-resty-redis):

location = /healthcheck {

  content_by_lua_block {

    local red = redis:new()
    used_mem_limit = 536870912

    -- connect to redis
    ok, err = red:connect(ngx.var.redis_host, 6379)
    if not ok then
        ngx.log(ngx.ERR, "Redis connection error: ", err)
        ngx.status = 500
        return
    end

    -- setting connection timeout
    red:set_timeout(1000)

    -- getting redis used_memory_rss
    memory = red:info('memory')

    red_used_memory = ...

    -- set response code
    if (red_used_memory >= used_mem_limit) then
      http_code = 500
    elseif (red_used_memory < used_mem_limit)
      http_code = 200
    else
      http_code = 500
    end

    ngx.status = http_code

  }

}

memory variable should be like this:

# Memory
used_memory:105157968
used_memory_human:100.29M
used_memory_rss:110387200
used_memory_rss_human:105.27M
used_memory_peak:105219456
used_memory_peak_human:100.35M
used_memory_peak_perc:99.94%
used_memory_overhead:32290608
used_memory_startup:487168
used_memory_dataset:72867360
used_memory_dataset_perc:69.62%
total_system_memory:1044770816

I need to get used_memory_rss value, so then I can compare it with used_mem_limit. So, I don't know, how to complete red_used_memory = ... line.

1 Answer 1

2

There seems to be only digits in possible value so use a simple regexp and then convert resulting string to number:

red_used_memory = tonumber(memory:match('used_memory_rss:(%d+)'))

Line breaks are irrelevant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.