nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http_stub_status_module
is output in the terminal, the stub_status module has been enabled for Nginx.--with-http_stub_status_module
parameter to configure and compile Nginx again from the source code. The example is as follows:./configure \\… \\ ## Command required to compile nginx previously.--with-http_stub_status_modulemakesudo make install
/etc/nginx/conf.d
for the official image), create a ConfigMap, and add the configuration information to the ConfigMap. For the ConfigMap operation guide, see ConfigMap Management.server {listen 8080; # Adjust the configuration based on the business situation.listen [::]:8080; # Adjust the configuration based on the business situation.server_name localhost; # Adjust the configuration based on the business situation.location = /stub_status { # Adjust the specific path based on the business situation.stub_status;}}
nginx -tnginx -s reload
curl http://localhost:8080/stub_status ## Adjust the command based on the configuration content in the configuration file.
Active connections: 45server accepts handled requests1056958 1156958 4491319Reading: 0 Writing: 25 Waiting : 7
Parameters | Description |
name | Exporter name, which should meet the following requirements: The name should be unique. The name should conform to the following regular expression: '^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'. |
address | Nginx service connection address. |
path | Nginx service status path, which is specified in the configuration. |
user name | Username for HTTP authentication of the Nginx service. |
password | Password for HTTP authentication of the Nginx service. |
tag | Custom labels for metrics. |
apiVersion: apps/v1kind: Deploymentmetadata:labels:k8s-app: nginx-exporter # Use the actual name based on business needs. It is recommended to include the information on the corresponding Nginx instance.name: nginx-exporter # Use the actual name based on business needs. It is recommended to include the information on the corresponding Nginx instance.namespace: nginx-demo # Use the actual namespace based on business needs.spec:replicas: 1selector:matchLabels:k8s-app: nginx-exporter # Use the actual name based on business needs. It is recommended to include the information on the corresponding Nginx instance.template:metadata:labels:k8s-app: nginx-exporter # Use the actual name based on business needs. It is recommended to include the information on the corresponding Nginx instance.spec:containers:- args:- --web.listen-address=:8080- --nginx.scrape-uri=http://127.0.0.1:8080/stub_status # Use the actual address corresponding to the Nginx instance based on business needs.image: ccr.ccs.tencentyun.com/rig-agent/common-image:nginx-exporter-v1.1.0name: nginx-exporterports:- containerPort: 9113name: metric-portterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilednsPolicy: ClusterFirstimagePullSecrets:- name: qcloudregistrykeyrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30
wget -qO- http://localhost:8080/metrics
PodMonitor
via service discovery to define the collection task. The YAML example is as follows:apiVersion: monitoring.coreos.com/v1kind: PodMonitormetadata:name: nginx-exporter # Enter a unique name.namespace: cm-prometheus # Pay-as-you-go instance: Use the namespace of the cluster. Monthly subscription instance (no longer available): The namespace is fixed. Do not change it.spec:podMetricsEndpoints:- interval: 30sport: metric-port # Enter the port of the Prometheus Exporter in the Pod YAML file.path: /metrics # Enter the path of the Prometheus Exporter. Default value: /metrics.relabelings:- action: replacesourceLabels:- instanceregex: (.*)targetLabel: instancereplacement: 'crs-xxxxxx' # Enter the information on the corresponding Nginx instance.namespaceSelector: # Select the namespace where the Pod to be monitored is located.matchNames:- nginx-demoselector: # Enter the labels of the Pod to be monitored to locate the target Pod.matchLabels:k8s-app: nginx-exporter
Name | Description |
web.telemetry-path | Path for exposing metrics. Default value /metrics . |
nginx.scrape-uri | URL for Nginx metric collection. Default value: http://127.0.0.1:8080/stub_status . |
[no-]nginx.plus | Whether to enable Nginx Plus. Default value: enabled. |
[no-]nginx.ssl-verify | Whether to verify the SSL certificate. |
nginx.ssl-ca-cert | SSL certificate path. |
nginx.ssl-client-cert | SSL certificate path. |
nginx.ssl-client-key | SSL certificate path. |
nginx.timeout | Nginx metric collection timeout interval. |
prometheus.const-label | Tag to be used for each metric, which is in the format of label=value. One tag can be used multiple times. |
[no-]web.systemd-socket | Use a systemd socket listener instead of a port listener (Linux only). |
web.listen-address | Listening address. Default value: 9113. |
web.config.file | Configuration file path. TLS or authentication can be enabled. (This parameter is used for testing.) |
log.level | Log level. Default value: info. |
log.format | Log message output format. Valid values: logfmt and json. Default value: logfmt. |
version | Printed Apache version information. |
Was this page helpful?