Prometheus metrics and environments


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

extern prometheus installation called prometheus (version 2.5.0)
nginx server with vts module enabled on (version 1.14.0)
nginx-vts-exporter on that connects to (version 0.10.3)
gitlab server on (version 11.4.5)

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

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

By looking on the examples 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.


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:

      - targets: ['myhost:9913']
          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