You are browsing documentation for an older version. See the latest documentation here.

kong.node

Node-level utilities.

kong.node.get_id()

Returns the ID used by this node to describe itself.

Returns

  • string: The v4 UUID used by this node as its ID.

Usage

  1. local id = kong.node.get_id()

kong.node.get_memory_stats([unit[, scale]])

Returns memory usage statistics about this node.

Parameters

  • unit (string, optional): The unit that memory is reported in. Can be any of b/B, k/K, m/M, or g/G for bytes, kibibytes, mebibytes, or gibibytes, respectively. Defaults to b (bytes).
  • scale (number, optional): The number of digits to the right of the decimal point. Defaults to 2.

Returns

  • table: A table containing memory usage statistics for this node. If unit is b/B (the default), reported values are Lua numbers. Otherwise, reported values are strings with the unit as a suffix.

Usage

  1. local res = kong.node.get_memory_stats()
  2. -- res will have the following structure:
  3. {
  4. lua_shared_dicts = {
  5. kong = {
  6. allocated_slabs = 12288,
  7. capacity = 24576
  8. },
  9. kong_db_cache = {
  10. allocated_slabs = 12288,
  11. capacity = 12288
  12. }
  13. },
  14. workers_lua_vms = {
  15. {
  16. http_allocated_gc = 1102,
  17. pid = 18004
  18. },
  19. {
  20. http_allocated_gc = 1102,
  21. pid = 18005
  22. }
  23. }
  24. }
  25. local res = kong.node.get_memory_stats("k", 1)
  26. -- res will have the following structure:
  27. {
  28. lua_shared_dicts = {
  29. kong = {
  30. allocated_slabs = "12.0 KiB",
  31. capacity = "24.0 KiB",
  32. },
  33. kong_db_cache = {
  34. allocated_slabs = "12.0 KiB",
  35. capacity = "12.0 KiB",
  36. }
  37. },
  38. workers_lua_vms = {
  39. {
  40. http_allocated_gc = "1.1 KiB",
  41. pid = 18004
  42. },
  43. {
  44. http_allocated_gc = "1.1 KiB",
  45. pid = 18005
  46. }
  47. }
  48. }

kong.node.get_hostname()

Returns the name used by the local machine.

Returns

  • string: The local machine hostname.

Usage

  1. local hostname = kong.node.get_hostname()