Metricas e Telemetria
Metricas e Telemetria
Seção intitulada “Metricas e Telemetria”Registre metricas de aplicação usando contadores, gauges e histogramas.
Carregamento
Seção intitulada “Carregamento”local metrics = require("metrics")Contadores
Seção intitulada “Contadores”Incrementar Contador
Seção intitulada “Incrementar Contador”metrics.counter_inc("requests_total", {method = "POST"})| Parâmetro | Tipo | Descrição |
|---|---|---|
name | string | Nome da metrica |
labels | table? | Pares chave-valor de labels |
Retorna: boolean, error
Adicionar ao Contador
Seção intitulada “Adicionar ao Contador”metrics.counter_add("bytes_total", 1024, {direction = "out"})| Parâmetro | Tipo | Descrição |
|---|---|---|
name | string | Nome da metrica |
value | number | Valor a adicionar |
labels | table? | Pares chave-valor de labels |
Retorna: boolean, error
Definir Gauge
Seção intitulada “Definir Gauge”metrics.gauge_set("queue_depth", 42, {queue = "emails"})| Parâmetro | Tipo | Descrição |
|---|---|---|
name | string | Nome da metrica |
value | number | Valor atual |
labels | table? | Pares chave-valor de labels |
Retorna: boolean, error
Incrementar Gauge
Seção intitulada “Incrementar Gauge”metrics.gauge_inc("connections", {pool = "db"})| Parâmetro | Tipo | Descrição |
|---|---|---|
name | string | Nome da metrica |
labels | table? | Pares chave-valor de labels |
Retorna: boolean, error
Decrementar Gauge
Seção intitulada “Decrementar Gauge”metrics.gauge_dec("connections", {pool = "db"})| Parâmetro | Tipo | Descrição |
|---|---|---|
name | string | Nome da metrica |
labels | table? | Pares chave-valor de labels |
Retorna: boolean, error
Histogramas
Seção intitulada “Histogramas”Registrar Observação
Seção intitulada “Registrar Observação”metrics.histogram("duration_seconds", 0.123, {method = "GET"})| Parâmetro | Tipo | Descrição |
|---|---|---|
name | string | Nome da metrica |
value | number | Valor observado |
labels | table? | Pares chave-valor de labels |
Retorna: boolean, error
| Condição | Tipo | Retentável |
|---|---|---|
| Coletor não disponível | errors.INTERNAL | não |
Veja Error Handling para trabalhar com erros.