Prometheus metrics and environments

Hi,

I’m trying to get my prometheus integration to work with environments.

Setup:
extern prometheus installation called prometheus (version 2.5.0)
nginx server with vts module enabled on host-a.example.com (version 1.14.0)
nginx-vts-exporter on host-b.example.com that connects to host-a.example.com (version 0.10.3)
gitlab server on gitlab.example.com (version 11.4.5)

gitlab repository configured with external prometheus (http://prometheus:9090)
in my .gitlab-ci.yml i have an environment with name: host-a.example.com

When i made an deployment to host-a.example.com and then press the monitoring icon it doesn’t find any data.

By looking on the examples https://gitlab.elvaco.se/help/user/project/integrations/prometheus_library/nginx.md it says avg(nginx_server_requestMsec{%{environment_filter}})

What does %{environment_filter} expand to? can’t find information about this.

The other example says sum(rate(nginx_server_requests{server_zone!="*", server_zone!="_", %{environment_filter}}[2m])) by (code) but when i look in prometheus it doesn’t have any server_zone at all, but a host tag.

Kind of lost here, i can’t seems to get this to work by reading the documentation, please help.

Hi.

I have the same problem. I’m trying to configure Prometheus to be read by Gitlab, but it can’t find any data. If i put this query sum(rate(nginx_server_requests{server_zone!="*", server_zone!="_", %{environment_filter}}[2m])) by (code) whithout the %{environment_filter}, I’m able to see the data in Prometheus. Please help me.

Finally I was able to do it!

%{environment_filter} translates to environment=environment_slug, where environment_slug is the value of the variable $CI_ENVIRONMENT_SLUG. You can discover that by echoing it in .gitlab-ci.yml. If you environment is called prod, for instance, $CI_ENVIRONMENT_SLUG will be something like “prod-10aixc”. Right now I forced a label in the Prometheus configuration:

static_configs:
      - targets: ['myhost:9913']
        labels:
          environment: 'prod-10aixc'

Perhaps it is possible to convert that name in the query to prod for instance, and set the environment to prod in Prometheus, but I don’t know how to do that right now. I hope it helps you.

1 Like

Can you help in configuring prometheus in Gitlab. I am stuck .From gitlab its not retrieving any data