Page MenuHomeSoftware Heritage

nginx: add the configuration to retrieve the metrics in prometheus
ClosedPublic

Authored by vsellier on Feb 3 2022, 3:55 PM.

Details

Summary

It will allow to have an idea of the load of the nginx.
Unfortunately, the community version of nginx provides only global
metrics, not detailed metrics per vhosts.

Example of exported statistics :

root@pergamon:~# curl 10.168.130.30:9103/metrics
# HELP nginx_connections_accepted Accepted client connections
# TYPE nginx_connections_accepted counter
nginx_connections_accepted 170
# HELP nginx_connections_active Active client connections
# TYPE nginx_connections_active gauge
nginx_connections_active 5
# HELP nginx_connections_handled Handled client connections
# TYPE nginx_connections_handled counter
nginx_connections_handled 170
# HELP nginx_connections_reading Connections where NGINX is reading the request header
# TYPE nginx_connections_reading gauge
nginx_connections_reading 0
# HELP nginx_connections_waiting Idle client connections
# TYPE nginx_connections_waiting gauge
nginx_connections_waiting 4
# HELP nginx_connections_writing Connections where NGINX is writing the response back to the client
# TYPE nginx_connections_writing gauge
nginx_connections_writing 1
# HELP nginx_http_requests_total Total http requests
# TYPE nginx_http_requests_total counter
nginx_http_requests_total 268

more info at : https://nginx.org/en/docs/http/ngx_http_stub_status_module.html#stub_status

Test Plan
  • moma
diff origin/production/moma.softwareheritage.org current/moma.softwareheritage.org
*******************************************
+ Concat::Fragment[nginx-metrics-500-6666cd76f96956469e7be39d750cc7d9] =>
   parameters =>
     "content": "\n  location / {\n    index     index.html index.htm index.php;\...
     "order": 500,
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat::Fragment[nginx-metrics-500-ae3b848d2daecffc635ae20b0b882d8f] =>
   parameters =>
     "content": "\n  location /metrics {\n    stub_status on;\n    index     inde...
     "order": 500,
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat::Fragment[nginx-metrics-footer] =>
   parameters =>
     "content": "}\n",
     "order": "699",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat::Fragment[nginx-metrics-header] =>
   parameters =>
     "content": "# MANAGED BY PUPPET\nserver {\n  listen 127.0.0.1:9081 deferred;...
     "order": "001",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat[/etc/nginx/sites-available/nginx-metrics.conf] =>
   parameters =>
     "backup": "puppet",
     "ensure": "present",
     "ensure_newline": false,
     "force": false,
     "format": "plain",
     "group": "root",
     "mode": "0644",
     "notify": "Class[Nginx::Service]",
     "order": "alpha",
     "owner": "root",
     "path": "/etc/nginx/sites-available/nginx-metrics.conf",
     "replace": true,
     "show_diff": true,
     "tag": "nginx_config_file",
     "warn": false
*******************************************
+ Concat_file[/etc/nginx/sites-available/nginx-metrics.conf] =>
   parameters =>
     "backup": "puppet",
     "ensure_newline": false,
     "force": false,
     "format": "plain",
     "group": "root",
     "mode": "0644",
     "order": "alpha",
     "owner": "root",
     "replace": true,
     "show_diff": true,
     "tag": "_etc_nginx_sites-available_nginx-metrics.conf"
*******************************************
+ Concat_fragment[nginx-metrics-500-6666cd76f96956469e7be39d750cc7d9] =>
   parameters =>
     "content": "\n  location / {\n    index     index.html index.htm index.php;\...
     "order": 500,
     "tag": "_etc_nginx_sites-available_nginx-metrics.conf",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat_fragment[nginx-metrics-500-ae3b848d2daecffc635ae20b0b882d8f] =>
   parameters =>
     "content": "\n  location /metrics {\n    stub_status on;\n    index     inde...
     "order": 500,
     "tag": "_etc_nginx_sites-available_nginx-metrics.conf",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat_fragment[nginx-metrics-footer] =>
   parameters =>
     "content": "}\n",
     "order": "699",
     "tag": "_etc_nginx_sites-available_nginx-metrics.conf",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Concat_fragment[nginx-metrics-header] =>
   parameters =>
     "content": "# MANAGED BY PUPPET\nserver {\n  listen 127.0.0.1:9081 deferred;...
     "order": "001",
     "tag": "_etc_nginx_sites-available_nginx-metrics.conf",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ File[/etc/default/prometheus-nginx-exporter] =>
   parameters =>
     "content": "# Managed by Puppet (class profile::prometheus::nginx), changes ...
     "ensure": "present",
     "group": "root",
     "mode": "0644",
     "notify": "Service[prometheus-nginx-exporter]",
     "owner": "root"
*******************************************
+ File[/etc/nginx/sites-enabled/nginx-metrics.conf] =>
   parameters =>
     "ensure": "link",
     "group": "root",
     "mode": "0644",
     "notify": "Class[Nginx::Service]",
     "owner": "root",
     "target": "/etc/nginx/sites-available/nginx-metrics.conf"
*******************************************
+ Nginx::Resource::Location[/metrics] =>
   parameters =>
     "add_header": {
     },
     "ensure": "present",
     "fastcgi_params": "/etc/nginx/fastcgi.conf",
     "flv": false,
     "index_files": [
       "index.html",
       "index.htm",
       "index.php"
     ],
     "internal": false,
     "location": "/metrics",
     "mp4": false,
     "priority": 500,
     "proxy_connect_timeout": "90s",
     "proxy_hide_header": [
    
     ],
     "proxy_ignore_header": [
    
     ],
     "proxy_pass_header": [
    
     ],
     "proxy_read_timeout": "90s",
     "proxy_send_timeout": "90s",
     "proxy_set_header": [
       "Host $host",
       "X-Real-IP $remote_addr",
       "X-Forwarded-For $proxy_add_x_forwarded_for",
       "X-Forwarded-Proto $scheme",
       "Proxy \"\""
     ],
     "rewrite_rules": [
    
     ],
     "server": "nginx-metrics",
     "ssl": false,
     "ssl_only": false,
     "stub_status": true,
     "uwsgi_params": "/etc/nginx/uwsgi_params"
*******************************************
+ Nginx::Resource::Location[nginx-metrics-default] =>
   parameters =>
     "add_header": {
     },
     "ensure": "present",
     "fastcgi_params": "/etc/nginx/fastcgi.conf",
     "flv": false,
     "index_files": [
       "index.html",
       "index.htm",
       "index.php"
     ],
     "internal": false,
     "location": "/",
     "location_allow": [
    
     ],
     "location_deny": [
    
     ],
     "mp4": false,
     "notify": "Class[Nginx::Service]",
     "priority": 500,
     "proxy_connect_timeout": "90s",
     "proxy_hide_header": [
    
     ],
     "proxy_ignore_header": [
    
     ],
     "proxy_pass_header": [
    
     ],
     "proxy_read_timeout": "90s",
     "proxy_send_timeout": "90s",
     "proxy_set_header": [
       "Host $host",
       "X-Real-IP $remote_addr",
       "X-Forwarded-For $proxy_add_x_forwarded_for",
       "X-Forwarded-Proto $scheme",
       "Proxy \"\""
     ],
     "rewrite_rules": [
    
     ],
     "server": "nginx-metrics",
     "ssl": false,
     "ssl_only": false,
     "uwsgi_params": "/etc/nginx/uwsgi_params"
*******************************************
+ Nginx::Resource::Server[nginx-metrics] =>
   parameters =>
     "add_header": {
     },
     "ensure": "present",
     "fastcgi_params": "/etc/nginx/fastcgi.conf",
     "format_log": "combined",
     "geo_mappings": {
     },
     "group": "root",
     "http2": "off",
     "index_files": [
       "index.html",
       "index.htm",
       "index.php"
     ],
     "ipv6_enable": false,
     "ipv6_listen_ip": "::",
     "ipv6_listen_options": "default ipv6only=on",
     "ipv6_listen_port": 9081,
     "listen_ip": "127.0.0.1",
     "listen_options": "deferred",
     "listen_port": 9081,
     "listen_unix_socket": "/var/run/nginx.sock",
     "listen_unix_socket_enable": false,
     "location_allow": [
    
     ],
     "location_deny": [
    
     ],
     "locations": {
       "/metrics": {
         "stub_status": true
       }
     },
     "locations_defaults": {
     },
     "maintenance": false,
     "maintenance_value": "return 503",
     "mode": "0644",
     "owner": "root",
     "proxy_connect_timeout": "90s",
     "proxy_hide_header": [
    
     ],
     "proxy_pass_header": [
    
     ],
     "proxy_read_timeout": "90s",
     "proxy_send_timeout": "90s",
     "proxy_set_header": [
       "Host $host",
       "X-Real-IP $remote_addr",
       "X-Forwarded-For $proxy_add_x_forwarded_for",
       "X-Forwarded-Proto $scheme",
       "Proxy \"\""
     ],
     "resolver": [
    
     ],
     "rewrite_non_www_to_www": false,
     "rewrite_rules": [
    
     ],
     "rewrite_www_to_non_www": false,
     "server_name": [
       "127.0.0.1",
       "localhost"
     ],
     "spdy": "off",
     "ssl": false,
     "ssl_listen_option": true,
     "ssl_port": 443,
     "ssl_redirect": false,
     "ssl_stapling": false,
     "ssl_stapling_verify": false,
     "ssl_verify_client": "on",
     "string_mappings": {
     },
     "use_default_location": true,
     "uwsgi_params": "/etc/nginx/uwsgi_params"
*******************************************
+ Package[prometheus-nginx-exporter] =>
   parameters =>
     "ensure": "present",
     "notify": "Service[prometheus-nginx-exporter]"
*******************************************
+ Profile::Prometheus::Export_scrape_config[nginx] =>
   parameters =>
     "job": "nginx",
     "labels": {
     },
     "target": "192.168.100.31:9103"
*******************************************
+ Service[prometheus-nginx-exporter] =>
   parameters =>
     "enable": true,
     "ensure": "running"
*******************************************
`

Diff Detail

Repository
rSPSITE puppet-swh-site
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

vsellier edited the summary of this revision. (Show Details)

minor update on documentation

This revision is now accepted and ready to land.Feb 3 2022, 4:08 PM

use -- for all the options of the exporter configuration