Skip to content

Latest commit

 

History

History
175 lines (119 loc) · 4.63 KB

getting_started.rst

File metadata and controls

175 lines (119 loc) · 4.63 KB

Monitoring: getting started

Tarantool

First, you need to install the metrics package:

$ cd ${PROJECT_ROOT}
$ tarantoolctl rocks install metrics

Next, require it in your code:

local metrics = require('metrics')

Set a global label for your metrics:

metrics.set_global_labels({alias = 'alias'})

Enable default Tarantool metrics such as network, memory, operations, etc:

metrics.enable_default_metrics()

If you use Cartridge, enable Cartridge metrics:

metrics.enable_cartridge_metrics()

Initialize the Prometheus Exporter, or export metrics in any other format:

local httpd = require('http.server')
local http_handler = require('metrics.plugins.prometheus').collect_http


httpd.new('0.0.0.0', 8088)
    :route({path = '/metrics'}, function(...)
        return http_handler(...)
end)
    :start()

box.cfg{
    listen = 3302
}

Now you can use the HTTP API endpoint /metrics to collect your metrics in the Prometheus format. If you need your custom metrics, see the API reference <metrics-api-reference>.

Cartridge role

cartridge.roles.metrics is a role for Tarantool Cartridge. It allows using default metrics in a Cartridge application and manage them via configuration.

Usage

  1. Add metrics package to dependencies in the .rockspec file. Make sure that you are using version 0.3.0 or higher.

    dependencies = {
        ...
        'metrics >= 0.3.0-1',
        ...
    }
  2. Make sure that you have cartridge.roles.metrics in the roles list in cartridge.cfg in your entry-point file (e.g. init.lua).

    local ok, err = cartridge.cfg({
        ...
        roles = {
            ...
            'cartridge.roles.metrics',
            ...
        },
    })
  3. Enable role in the interface:

    image

    Since version 0.6.0 metrics role is permanent and enabled on instances by default.

  4. After role initialization, default metrics will be enabled and the global label 'alias' will be set. Note that 'alias' label value is set by instance configuration option <cartridge-cfg> alias or instance_name (since 0.6.1).

    If you need to use the functionality of any metrics package, you may get it as a Cartridge service and use it like a regular package after require:

    local cartridge = require('cartridge')
    local metrics = cartridge.service_get('metrics')
  5. To view metrics via API endpoints, use the following configuration (to learn more about Cartridge configuration, see this):

    metrics:
      export:
      - path: '/path_for_json_metrics'
        format: 'json'
      - path: '/path_for_prometheus_metrics'
        format: 'prometheus'

    image

    OR

    Use set_export:

    NOTE that set_export has lower priority than clusterwide config and won't work if metrics config is present.

    metrics.set_export({
        {
            path = '/path_for_json_metrics',
            format = 'json'
        },
        {
            path = '/path_for_prometheus_metrics',
            format = 'prometheus'
        }
    })

    The metrics will be available on the path specified in path in the format specified in format.

    You can add several entry points of the same format by different paths, like this:

    metrics:
      export:
        - path: '/path_for_json_metrics'
          format: 'json'
        - path: '/another_path_for_json_metrics'
          format: 'json'