VK Cloud logo

Metrics of an image-based application

Collecting metrics

To collect metrics of an image-based application in addition to VM system metrics:

  1. Configure collection of VM system metrics (for details, see the section Monitoring agent).

  2. In the plans/<PLAN_NAME>/deployment/deploy.tf manifest included in the service package of the image-based application, configure the prometheus plugin:

    1. In the /etc/telegraf/telegraf.d directory, create a metrics.conf file and set the prometheus plugin settings.

    2. If the /etc/telegraf/telegraf.d/ directory (including all files) does not have the telegraf owner and the telegraf group assigned, assign them.

      Prometheus plugin configuration
      resource "ivkcs_agent_exec" "monitoring" {...step {    index   = 1    type    = "bash"    content = <<-EOC#!/bin/bash...# Creating the metrics.conf filecat <<EOT > /etc/telegraf/telegraf.d/metrics.conf# Prometheus plugin[[inputs.prometheus]]  name_override = "<NAME>"  urls = ["<METRICS_URL>"]  # Representing metrics via field key with tag preservation  metric_version = 2EOT# Assigning the owner and group to the telegraf.d directory and its fileschown -R telegraf:telegraf /etc/telegraf/telegraf.d/EOC...  }...}

    Here:

    • <NAME> — the prefix of the metrics. The value cannot be empty. If the name_override parameter is not set, the default value prometheus will be applied.
    • <METRICS_URL> — the URL from which the image-based application provides metrics. For example, http://localhost:8428/metrics.

Example of collected metrics

For example, an image-based application provides metrics at http://localhost:8428/metrics in the format:

go_gc_duration_seconds{quantile="0"} 0go_gc_duration_seconds{quantile="0.25"} 0go_gc_duration_seconds{quantile="0.5"} 0go_gc_duration_seconds{quantile="0.75"} 0go_gc_duration_seconds{quantile="1"} 8.4326e-05vm_app_version{version="victoria-metrics-20240301-000115-tags-v1.93.13-0-g26266a463", short_version="v1.93.13"} 1vm_allowed_memory_bytes 4933135564

The prometheus plugin is configured in the metrics.conf file:

[[inputs.prometheus]]  name_override = "victoria"  urls = ["http://localhost:8428/metrics"]# Representing metrics via field key with tag preservation  metric_version = 2

In this case, the monitoring agent will send the metrics to Cloud Monitoring in the format:

victoria_go_gc_duration_seconds{quantile="0"} 0victoria_go_gc_duration_seconds{quantile="0.25"} 0victoria_go_gc_duration_seconds{quantile="0.5"} 0victoria_go_gc_duration_seconds{quantile="0.75"} 0victoria_go_gc_duration_seconds{quantile="1"} 8.4326e-05victoria_vm_app_version{version="victoria-metrics-20240301-000115-tags-v1.93.13-0-g26266a463", short_version="v1.93.13"} 1victoria_vm_allowed_memory_bytes 4933135564
Was this article helpful?