NGNIX Routes Exporter
Dashboard de métricas do NGINX Exporter. Exporter: martin-helmich/prometheus-nginxlog-exporter
# Overview

Dashboard que exibe algumas métricas úteis a partir do exporter [martin-helmich/prometheus-nginxlog-exporter](https://github.com/martin-helmich/prometheus-nginxlog-exporter).

# Prometheus

Para conseguir exportar as métricas, basta utilizar o exporter e suas instruções que podem ser encontradas na página oficial. O passo a passo também pode ser encontrado [aqui](https://blog.ruanbekker.com/blog/2020/04/25/nginx-metrics-on-prometheus-with-the-nginx-log-exporter/).

## Nginx

Na máquina na qual se deseja fazer o monitoramento dos sistemas que fazem uso do NGINX, é necessário fazer as seguintes configurações:

No arquivo `/etc/nginx/nginx.conf`, alterar as seguintes linhas que determinam como será gerado o log:

```
	##
	# Logging Settings
	##

	log_format custom   '$remote_addr - $remote_user [$time_local] '
                         '"$request" $status $body_bytes_sent '
                         '"$http_referer" "$http_user_agent"'
                         'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';

	access_log /var/log/nginx/access.log custom;
	error_log /var/log/nginx/error.log;
```

Feito isso, execute um comando para verificar que sua configuração de nginx é válida:

```
sudo nginx -t
```

Se tudo estiver certo, podemos então adicionar um novo site. Para isso basta executar ele na máquina que você deseja, e fazer com que os logs sejam salvos preferencialmente dentro de `/var/log/nginx/`.

## Nginx Log Exporter

Hora então de configurar o log exporter para gerar as métricas que posteriormente serão lidas pelo Prometheus. As releases podem ser acompanhadas por [aqui](https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases) e sugiro sempre utilizar versões mais recentes do pacote. Para fins demonstrativos vamos utilizar a v1.9.2.

```
wget https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases/download/v1.9.2/prometheus-nginxlog-exporter
```

Feito isso, dar permissão e move-lo para o local correto

```
chmod +x prometheus-nginxlog-exporter
mv prometheus-nginxlog-exporter /usr/bin/prometheus-nginxlog-exporter
```

Criar o diretório que irá receber a nossa config

```
sudo mkdir /etc/prometheus
```

Criar o arquivo de config `/etc/prometheus/nginxlog_exporter.yml`. O conteúdo dele irá determinar quais e como as métricas serão exportadas/interpretadas. Adapta-lo para cada caso:

```
listen:
  port: 4040
  address: "0.0.0.0"

consul:
  enable: false

namespaces:
  - name: myapp
    relabel_configs:
    - target_label: request_uri
      from: request
      split: 2
      separator: ' '  
    format: "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\"rt=$request_time uct=\"$upstream_connect_time\" uht=\"$upstream_header_time\" urt=\"$upstream_response_time\""
    source:
      files:
        - /var/log/nginx/myapp*
    labels:
      service: "myapp"
      environment: "prod"
      hostname: "http://myapp.domain.com"
    histogram_buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
```

Com essa configuração, ele irá pegar todas as métricas começadas com `myapp` dentro da pasta de logs do nginx default. `service e environment` são importantes para como serão interpretados dentro do dashboard e o `relabel_configs` são as configurações para conseguir identificar qual rota está recebendo o request. A porta onde será exportado os logs também pode ser alterada de acordo com sua necessidade.

A lista completa do que pode ser alterado nas configurações pode ser encontrada no [repositório padrão](https://github.com/martin-helmich/prometheus-nginxlog-exporter).

### Criar o service

Com tudo isso feito, hora de criar o service do processo. para isso crie o arquivo `/etc/systemd/system/nginxlog_exporter.service` e adicione:

```
[Unit]
Description=Prometheus Log Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/bin/prometheus-nginxlog-exporter -config-file /etc/prometheus/nginxlog_exporter.yml

[Install]
WantedBy=multi-user.target
```

Após isso, dê um reload, habilite o exporter para executar sempre que a VM reiniciar, e restarte o serviço:

```
sudo systemctl daemon-reload
sudo systemctl enable nginxlog_exporter
sudo systemctl restart nginxlog_exporter
```

Feito isso o exporter já estará recebendo os requests e as métricas podem ser observadas em `http://ip-machine:4040/metrics`. Caso queira pode também conferir o status do serviço usando:

```
sudo systemctl status nginxlog_exporter
```

## Configurando o prometheus para ler as métricas

Por fim, para que seja possível o prometheus analisar as métricas, é preciso fazer uma pequena configuração na sua configuração. Dentro do arquivo de config dele, basta adicionar as seguintes informações dentro do `scrape_configs`:

```
scrape_configs:
  - job_name: 'myapp'
    scrape_interval: 10s
    static_configs:
      - targets: ['ip.of.nginx.exporter:4040']
```

Basta reiniciar então o prometheus. Exemplo em caso de um container docker:

```
docker-compose restart prometheus
```

Feito isso, as métricas serão então coletadas e disponíveis para alimentar o dashboard :)

# Grafana

Indo agora para o Grafana, basta importar o dashboard. Depois disso, configurar a variável `apis` com a lista das APIs que irão ser monitoradas separadas por um `|`. Para o nosso exemplo:

```
myapp_http_response_count_total|other_http_response_count_total
```

Feito isso, pronto! Os dados já estarão disponíveis para visualização.

# Créditos e Referências

- https://github.com/martin-helmich/prometheus-nginxlog-exporter
- https://blog.ruanbekker.com/blog/2020/04/25/nginx-metrics-on-prometheus-with-the-nginx-log-exporter/
Dashboard de métricas do NGINX Exporter
{
  "__inputs": [
    {
      "name": "DS_GRAFANACLOUD-BRUNOMARRAM-PROM",
      "label": "",
      "description": "Source de onde será extraído os dados",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    },
    {
      "name": "VAR_APIS",
      "type": "constant",
      "label": "Lista de métricas coletadas",
      "value": "api1_http_response_count_total|api2_http_response_count_total",
      "description": "Aqui é importante colocar quais métricas serão usadas para determinar quais namespaces serão monitorados. Exemplo: 1_http_response_count_total|2_http_response_count_total"
    }
  ],
  "__elements": [],
  "__requires": [
    {
      "type": "panel",
      "id": "gauge",
      "name": "Gauge",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "8.5.0"
    },
    {
      "type": "panel",
      "id": "piechart",
      "name": "Pie chart",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "description": "Dashboard de métricas do NGINX Exporter. Exporter: martin-helmich/prometheus-nginxlog-exporter",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1650642563689,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "collapsed": false,
      "datasource": {
        "type": "datasource",
        "uid": "grafana"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 14,
      "panels": [],
      "title": "Visão Geral",
      "type": "row"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            }
          },
          "mappings": [],
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 12,
        "w": 7,
        "x": 0,
        "y": 1
      },
      "id": 2,
      "options": {
        "legend": {
          "displayMode": "hidden",
          "placement": "bottom"
        },
        "pieType": "pie",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "8.3.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "exemplar": true,
          "expr": "{__name__=~\"${api}_http_response_count_total\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}",
          "interval": "",
          "legendFormat": "{{request_uri}} - {{status}}",
          "refId": "A"
        }
      ],
      "title": "Total de Respostas por rota",
      "type": "piechart"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "s"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 17,
        "x": 7,
        "y": 1
      },
      "id": 21,
      "options": {
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "8.5.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "exemplar": true,
          "expr": "sum(rate({__name__=~\"${api}_http_response_time_seconds_sum\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[5m])) by (method) / sum(rate({__name__=~\"${api}_http_response_time_seconds_count\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[5m])) by (method)",
          "interval": "",
          "legendFormat": "{{ method }}",
          "refId": "A"
        }
      ],
      "title": "Tempo médio de resposta por método",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 17,
        "x": 7,
        "y": 7
      },
      "id": 16,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "right"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "exemplar": true,
          "expr": "sum(rate({__name__=~\"${api}_http_response_count_total\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[1m])) by (status)",
          "interval": "",
          "legendFormat": "{{ status }}",
          "refId": "A"
        }
      ],
      "title": "Status por segundo",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "s"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 13,
        "w": 12,
        "x": 0,
        "y": 13
      },
      "id": 20,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "exemplar": true,
          "expr": "sum(rate({__name__=~\"${api}_http_response_time_seconds_sum\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[5m])) by (request_uri) / sum(rate({__name__=~\"${api}_http_response_time_seconds_count\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[5m])) by (request_uri)",
          "interval": "",
          "legendFormat": "{{ request_uri }}",
          "refId": "A"
        }
      ],
      "title": "Tempo médio de resposta por rota",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 13,
        "w": 12,
        "x": 12,
        "y": 13
      },
      "id": 4,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "exemplar": true,
          "expr": "sum(rate({__name__=~\"${api}_http_response_time_seconds_count\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[1m])) by (request_uri)",
          "interval": "",
          "legendFormat": "{{ request_uri }}",
          "refId": "A"
        }
      ],
      "title": "Requests por segundo por rota",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 26
      },
      "id": 17,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "table",
          "placement": "right"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "exemplar": true,
          "expr": "sum(rate({__name__=~\"${api}_http_response_size_bytes\", environment=\"$env\", service=\"$api\", method=~\"$method\", request_uri=~\"$route\"}[5m])) by (request_uri)",
          "interval": "",
          "legendFormat": "{{ request_uri }}",
          "refId": "A"
        }
      ],
      "title": "Tráfego HTTP por rota",
      "type": "timeseries"
    },
    {
      "collapsed": true,
      "datasource": {
        "type": "datasource",
        "uid": "grafana"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 34
      },
      "id": 12,
      "panels": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 0,
                "gradientMode": "none",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "linear",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green"
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 35
          },
          "id": 8,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "right"
            },
            "tooltip": {
              "mode": "single"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "prometheus",
                "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
              },
              "exemplar": true,
              "expr": "{__name__=~\"${api}_http_response_time_seconds\", environment=\"$env\", service=\"$api\", quantile=\"0.9\", method=\"GET\", status=\"200\"}",
              "interval": "",
              "legendFormat": "{{ request_uri }}",
              "refId": "A"
            }
          ],
          "title": "Tempo de resposta GETs com sucesso (Quartil 90)",
          "type": "timeseries"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 0,
                "gradientMode": "none",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "linear",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green"
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 12,
            "y": 35
          },
          "id": 22,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "right"
            },
            "tooltip": {
              "mode": "single"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "prometheus",
                "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
              },
              "exemplar": true,
              "expr": "{__name__=~\"${api}_http_response_time_seconds\", environment=\"$env\", service=\"$api\", quantile=\"0.9\", method=\"POST\", status=\"200\"}",
              "interval": "",
              "legendFormat": "{{ request_uri }}",
              "refId": "A"
            }
          ],
          "title": "Tempo de resposta POSTs com sucesso (Quartil 90)",
          "type": "timeseries"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 0,
                "gradientMode": "none",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "linear",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green"
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              },
              "unit": "bytes"
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 43
          },
          "id": 10,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "right"
            },
            "tooltip": {
              "mode": "single"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "prometheus",
                "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
              },
              "exemplar": true,
              "expr": "sum(rate({__name__=~\"${api}_http_response_size_bytes\", environment=\"$env\", service=\"$api\"}[5m])) by (instance)",
              "interval": "",
              "legendFormat": "{{ instance }}",
              "refId": "A"
            }
          ],
          "title": "Tráfego HTTP por instância",
          "type": "timeseries"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "description": "",
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 0,
                "gradientMode": "none",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "linear",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green"
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 12,
            "y": 43
          },
          "id": 19,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "right"
            },
            "tooltip": {
              "mode": "single"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "prometheus",
                "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
              },
              "exemplar": true,
              "expr": "sum(rate({__name__=~\"${api}_http_response_time_seconds_sum\", environment=\"$env\", service=\"$api\"}[5m])) by (instance) / sum(rate({__name__=~\"${api}_http_response_time_seconds_count\", environment=\"$env\", service=\"$api\"}[5m])) by (instance)",
              "interval": "",
              "legendFormat": "{{ instance }}",
              "refId": "A"
            }
          ],
          "title": "Tempo médio de resposta por instância",
          "type": "timeseries"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 0,
                "gradientMode": "none",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "linear",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green"
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 51
          },
          "id": 6,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "right"
            },
            "tooltip": {
              "mode": "single"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "prometheus",
                "uid": "${DS_GRAFANACLOUD-BRUNOMARRAM-PROM}"
              },
              "exemplar": true,
              "expr": "sum(rate({__name__=~\"${api}_http_response_time_seconds_count\", environment=\"$env\", service=\"$api\"}[1m])) by (instance)",
              "interval": "",
              "legendFormat": "{{ instance }}",
              "refId": "A"
            }
          ],
          "title": "Requests por segundo por instância",
          "type": "timeseries"
        }
      ],
      "title": "Outras Métricas",
      "type": "row"
    }
  ],
  "schemaVersion": 36,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "hide": 2,
        "label": "Lista de métricas coletadas",
        "name": "apis",
        "query": "${VAR_APIS}",
        "skipUrlSync": false,
        "type": "constant",
        "current": {
          "value": "${VAR_APIS}",
          "text": "${VAR_APIS}",
          "selected": false
        },
        "options": [
          {
            "value": "${VAR_APIS}",
            "text": "${VAR_APIS}",
            "selected": false
          }
        ]
      },
      {
        "current": {},
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "definition": "label_values({__name__=~\"$apis\"}, environment)",
        "hide": 0,
        "includeAll": false,
        "label": "Ambiente",
        "multi": false,
        "name": "env",
        "options": [],
        "query": {
          "query": "label_values({__name__=~\"$apis\"}, environment)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "definition": "label_values({__name__=~\"$apis\", environment=\"$env\"}, service)",
        "hide": 0,
        "includeAll": false,
        "label": "API",
        "multi": false,
        "name": "api",
        "options": [],
        "query": {
          "query": "label_values({__name__=~\"$apis\", environment=\"$env\"}, service)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "allValue": ".*",
        "current": {},
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "definition": "label_values({__name__=~\"$apis\", environment=\"$env\", service=\"$api\"}, method)",
        "hide": 0,
        "includeAll": true,
        "label": "Método",
        "multi": false,
        "name": "method",
        "options": [],
        "query": {
          "query": "label_values({__name__=~\"$apis\", environment=\"$env\", service=\"$api\"}, method)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "allValue": ".*",
        "current": {},
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "definition": "label_values({__name__=~\"$apis\", environment=\"$env\", service=\"$api\", method=\"$method\"}, request_uri)",
        "hide": 0,
        "includeAll": true,
        "label": "Rota",
        "multi": true,
        "name": "route",
        "options": [],
        "query": {
          "query": "label_values({__name__=~\"$apis\", environment=\"$env\", service=\"$api\", method=\"$method\"}, request_uri)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-3h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "NGNIX Routes Exporter",
  "uid": "F3NlDvQnz",
  "version": 1,
  "weekStart": "",
  "gnetId": 16155
}