Skip to content

Commit becf8b3

Browse files
author
Hadrien Huvelle
committed
[IMP] Added promeheus-exporter capabilities & nginx cache cusomisation capabilities
1 parent e5a1c34 commit becf8b3

7 files changed

+122
-9
lines changed

9.0/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ COPY conf.d /etc/confd/conf.d
99
COPY templates /etc/confd/templates
1010
COPY docker-entrypoint.sh /docker-entrypoint.sh
1111

12+
RUN apk add logrotate
13+
14+
WORKDIR /tmp
15+
RUN wget https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases/download/v1.10.0/prometheus-nginxlog-exporter_1.10.0_linux_arm64.tar.gz
16+
RUN tar xvzfp prometheus-nginxlog-exporter_1.10.0_linux_arm64.tar.gz
17+
RUN mv /tmp/prometheus-nginxlog-exporter /usr/local/bin/
18+
RUN rm -rf /tmp/prometheus-nginxlog-exporter /tmp/prometheus-nginxlog-exporter_1.10.0_linux_arm64.tar.gz
19+
WORKDIR /
20+
1221
VOLUME ["/var/cache/nginx"]
1322

1423
ENTRYPOINT ["/docker-entrypoint.sh"]

9.0/conf.d/logrotate.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[template]
2+
3+
# The name of the template that will be used to render the application's configuration file
4+
# Confd will look in `/etc/conf.d/templates` for these files by default
5+
src = "logrotate.conf.tmpl"
6+
7+
# The location to place the rendered configuration file
8+
dest = "/etc/logrotate.conf"
9+
10+
# File ownership and mode information
11+
owner = "root"
12+
mode = "0644"
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[template]
2+
3+
# The name of the template that will be used to render the application's configuration file
4+
# Confd will look in `/etc/conf.d/templates` for these files by default
5+
src = "config.hcl.tmpl"
6+
7+
# The location to place the rendered configuration file
8+
dest = "/etc/prometheus-nginxlog-exporter.hcl"
9+
10+
# File ownership and mode information
11+
owner = "root"
12+
mode = "0644"

9.0/docker-entrypoint.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ set -e
55
echo "${NGX_HTTP_ACCESS}" > /etc/nginx/http-access.conf
66
echo "${NGX_HTPASSWD}" > /etc/nginx/htpasswd
77

8+
export NGX_CACHE_SIZE=${NGX_CACHE_SIZE:-10m}
9+
810
/usr/local/bin/confd -onetime -backend env
911

10-
if [[ -z "${NGX_SPECIFIC_CACHE}" ]]
11-
then
12-
echo "CREATE empty /etc/nginx/specific_cache.conf"
13-
touch /etc/nginx/specific_cache.conf
12+
echo ${NGX_SPECIFIC_SERVER_CONFIG:-"#NO specific configuration defined"} > /etc/nginx/specific_server_config.conf
13+
14+
if [[ -n "${NGX_PROMETHEUS_EXPORTER}" ]]
15+
then
16+
echo "access_log /var/log/nginx/access_prometheus.log prometheus_exporter;" > /etc/nginx/prometheus_eporter.conf
17+
18+
/usr/local/bin/prometheus-nginxlog-exporter -config-file /etc/prometheus-nginxlog-exporter.hcl &
1419
else
15-
echo "OVERRIDE /etc/nginx/specific_cache.conf"
16-
echo "${NGX_SPECIFIC_CACHE}" > /etc/nginx/specific_cache.conf
20+
touch /etc/nginx/prometheus_eporter.conf
1721
fi
1822

1923
exec "$@"

9.0/templates/config.hcl.tmpl

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
listen {
2+
port = 4040
3+
4+
// "metrics_endpoint" can be used to configure an alternative metrics URL
5+
// path. Default value is "/metrics".
6+
//
7+
// metrics_endpoint = "/metrics"
8+
}
9+
10+
namespace "nginx" {
11+
source = {
12+
files = [
13+
"/var/log/nginx/access_prometheus.log",
14+
]
15+
}
16+
17+
format = "$remote_addr - $remote_user [$time_local] \"$request\" \"$request_id\" $status \"$upstream_cache_status\" $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\" rt=$request_time uct=\"$upstream_connect_time\" uht=\"$upstream_header_time\" urt=\"$upstream_response_time\""
18+
19+
labels {
20+
app = "odoo"
21+
website = "ocms"
22+
}
23+
24+
relabel "request_method" {
25+
from = "request"
26+
split = 1
27+
}
28+
relabel "request_url" {
29+
from = "request"
30+
split = 2
31+
}
32+
33+
relabel "request_url_formated" {
34+
from = "request"
35+
split = 2
36+
37+
match "/web/assets/.*" {
38+
replacement = "/web/assets"
39+
}
40+
41+
match "([^?]+).*" {
42+
replacement = "$1"
43+
}
44+
}
45+
46+
47+
relabel "remote_addr" {
48+
from = "remote_addr"
49+
}
50+
51+
relabel "cache" {
52+
from = "upstream_cache_status"
53+
}
54+
55+
relabel "remote_user" {
56+
from = "remote_user"
57+
}
58+
59+
60+
histogram_buckets = [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
61+
62+
}

9.0/templates/logrotate.conf.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/var/log/nginx/access_prometheus.log {
2+
copytruncate
3+
nocompress
4+
rotate 5
5+
size 10M
6+
}

9.0/templates/nginx.conf.tmpl

+11-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ http {
3636
'"referrer": "$http_referer", '
3737
'"agent": "$http_user_agent" }';
3838

39+
log_format prometheus_exporter '$remote_addr - $remote_user [$time_local] '
40+
'"$request" "$request_id" $status "$upstream_cache_status" $body_bytes_sent '
41+
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for" '
42+
'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';
43+
3944
#Default value '4 8k' is raising a '414 Request-URI Too Large' error
4045
#when '/web/webclient/translations/' is requested with a lot of module names
4146
#as GET parameters (performed on user login), rendering a blank page.
@@ -77,7 +82,7 @@ http {
7782
proxy_max_temp_file_size 2048m;
7883
proxy_temp_file_write_size 64k;
7984

80-
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:100m inactive=60m;
85+
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:{{ getenv "NGX_CACHE_SIZE" }} inactive=60m;
8186

8287
include /etc/nginx/proxy_headers.conf;
8388

@@ -93,7 +98,7 @@ http {
9398

9499
client_max_body_size 1G;
95100

96-
add_header Strict-Transport-Security "max-age=600; includeSubDomains" always;
101+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
97102

98103
access_log /var/log/nginx/access.log json_combined;
99104

@@ -148,7 +153,6 @@ http {
148153
try_files =404 @cached;
149154
}
150155

151-
include /etc/nginx/specific_cache.conf;
152156

153157
# warning: /web/content reads ir.attachment, it would not be safe to
154158
# cache other files than .js / .css which can depend on users rights
@@ -182,5 +186,9 @@ http {
182186

183187
proxy_pass http://{{ $odoo_host }}:8069;
184188
}
189+
190+
include /etc/nginx/prometheus_eporter.conf;
191+
192+
include /etc/nginx/specific_server_config.conf;
185193
}
186194
}

0 commit comments

Comments
 (0)