From ab511070889a988a7511260e0860159e50019169 Mon Sep 17 00:00:00 2001 From: weixiang1862 <652048614@qq.com> Date: Tue, 5 Dec 2023 00:26:57 +0800 Subject: [PATCH] Nginx monitoring showcase. (#153) --- deploy/platform/docker/Makefile.in | 2 +- .../docker/config/nginx/Dockerfile.nginx | 19 ++ .../docker/config/nginx/fluent-bit-script.lua | 36 +++ .../docker/config/nginx/fluent-bit.conf | 48 ++++ .../platform/docker/config/nginx/nginx.conf | 98 ++++++++ .../config/nginx/otel-collector-config.yaml | 44 ++++ .../docker/docker-compose.nginx-monitor.yaml | 74 ++++++ deploy/platform/kubernetes/Makefile | 5 + deploy/platform/kubernetes/Makefile.in | 2 +- .../opentelemetry-config.yaml | 39 +++ .../feature-nginx-monitor/resources.yaml | 228 ++++++++++++++++++ .../templates/otel-collector-config.yaml | 1 + deploy/platform/kubernetes/values.yaml | 5 +- docs/readme.md | 1 + 14 files changed, 599 insertions(+), 3 deletions(-) create mode 100644 deploy/platform/docker/config/nginx/Dockerfile.nginx create mode 100644 deploy/platform/docker/config/nginx/fluent-bit-script.lua create mode 100644 deploy/platform/docker/config/nginx/fluent-bit.conf create mode 100644 deploy/platform/docker/config/nginx/nginx.conf create mode 100644 deploy/platform/docker/config/nginx/otel-collector-config.yaml create mode 100644 deploy/platform/docker/docker-compose.nginx-monitor.yaml create mode 100644 deploy/platform/kubernetes/templates/feature-nginx-monitor/opentelemetry-config.yaml create mode 100644 deploy/platform/kubernetes/templates/feature-nginx-monitor/resources.yaml diff --git a/deploy/platform/docker/Makefile.in b/deploy/platform/docker/Makefile.in index 5af603e..4ade062 100644 --- a/deploy/platform/docker/Makefile.in +++ b/deploy/platform/docker/Makefile.in @@ -17,4 +17,4 @@ # .EXPORT_ALL_VARIABLES: -FEATURE_FLAGS ?= agent,cluster,so11y,vm-monitor,event,mysql-monitor,apisix-monitor,grafana,elasticsearch-monitor +FEATURE_FLAGS ?= agent,cluster,so11y,vm-monitor,event,mysql-monitor,nginx-monitor,apisix-monitor,grafana,elasticsearch-monitor diff --git a/deploy/platform/docker/config/nginx/Dockerfile.nginx b/deploy/platform/docker/config/nginx/Dockerfile.nginx new file mode 100644 index 0000000..75db264 --- /dev/null +++ b/deploy/platform/docker/config/nginx/Dockerfile.nginx @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM openresty/openresty:1.17.8.2-5-alpine-fat + +RUN luarocks install nginx-lua-prometheus +RUN mkdir -p /var/log/nginx/ \ No newline at end of file diff --git a/deploy/platform/docker/config/nginx/fluent-bit-script.lua b/deploy/platform/docker/config/nginx/fluent-bit-script.lua new file mode 100644 index 0000000..4241c14 --- /dev/null +++ b/deploy/platform/docker/config/nginx/fluent-bit-script.lua @@ -0,0 +1,36 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +function rewrite_access_log(tag, timestamp, record) + local newRecord = {} + newRecord["layer"] = "NGINX" + newRecord["service"] = "nginx::nginx" + newRecord["serviceInstance"] = "nginx-instance" + newRecord["body"] = { text = { text = record.log } } + newRecord["tags"] = { data = {{ key = "LOG_KIND", value = "NGINX_ACCESS_LOG"}}} + return 1, timestamp, newRecord +end + +function rewrite_error_log(tag, timestamp, record) + local newRecord = {} + newRecord["layer"] = "NGINX" + newRecord["service"] = "nginx::nginx" + newRecord["serviceInstance"] = "nginx-instance" + newRecord["body"] = { text = { text = record.log } } + newRecord["tags"] = { data = {{ key = "LOG_KIND", value = "NGINX_ERROR_LOG" }}} + return 1, timestamp, newRecord +end \ No newline at end of file diff --git a/deploy/platform/docker/config/nginx/fluent-bit.conf b/deploy/platform/docker/config/nginx/fluent-bit.conf new file mode 100644 index 0000000..73b0538 --- /dev/null +++ b/deploy/platform/docker/config/nginx/fluent-bit.conf @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[SERVICE] + Flush 5 + Daemon Off + Log_Level warn +[INPUT] + Name tail + Tag access + Path /var/log/nginx/access.log +[INPUT] + Name tail + Tag error + Path /var/log/nginx/error.log +[FILTER] + Name lua + Match access + Script fluent-bit-script.lua + Call rewrite_access_log +[FILTER] + Name lua + Match error + Script fluent-bit-script.lua + Call rewrite_error_log +[OUTPUT] + Name stdout + Match * + Format json +[OUTPUT] + Name http + Match * + Host oap + Port 12800 + URI /v3/logs + Format json \ No newline at end of file diff --git a/deploy/platform/docker/config/nginx/nginx.conf b/deploy/platform/docker/config/nginx/nginx.conf new file mode 100644 index 0000000..b5c2ca6 --- /dev/null +++ b/deploy/platform/docker/config/nginx/nginx.conf @@ -0,0 +1,98 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +worker_processes 1; +daemon off; +error_log /var/log/nginx/error.log notice; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + lua_shared_dict prometheus_metrics 10M; + # lua_package_path "/path/to/nginx-lua-prometheus/?.lua;;"; + + init_worker_by_lua_block { + prometheus = require("prometheus").init("prometheus_metrics") + + metric_bytes = prometheus:counter( + "nginx_http_size_bytes", "Total size of HTTP", {"type", "route"}) + metric_requests = prometheus:counter( + "nginx_http_requests_total", "Number of HTTP requests", {"status", "route"}) + metric_latency = prometheus:histogram( + "nginx_http_latency", "HTTP request latency", {"route"}) + metric_connections = prometheus:gauge( + "nginx_http_connections", "Number of HTTP connections", {"state"}) + } + + server { + listen 8080; + + location /test { + default_type application/json; + return 200 '{"code": 200, "message": "success"}'; + + log_by_lua_block { + metric_bytes:inc(tonumber(ngx.var.request_length), {"request", "/test/**"}) + metric_bytes:inc(tonumber(ngx.var.bytes_send), {"response", "/test/**"}) + metric_requests:inc(1, {ngx.var.status, "/test/**"}) + metric_latency:observe(tonumber(ngx.var.request_time), {"/test/**"}) + } + } + + location /test_404 { + default_type application/json; + return 404 '{"code": 404, "message": "404 NOT Found"}'; + + log_by_lua_block { + metric_bytes:inc(tonumber(ngx.var.request_length), {"request", "/test_404/**"}) + metric_bytes:inc(tonumber(ngx.var.bytes_send), {"response", "/test_404/**"}) + metric_requests:inc(1, {ngx.var.status, "/test_404/**"}) + metric_latency:observe(tonumber(ngx.var.request_time), {"/test_404/**"}) + } + } + + location /test_500 { + default_type application/json; + return 500 '{"code": 500, "message": "500 Internal Server Error"}'; + + log_by_lua_block { + metric_bytes:inc(tonumber(ngx.var.request_length), {"request", "/test_500/**"}) + metric_bytes:inc(tonumber(ngx.var.bytes_send), {"response", "/test_500/**"}) + metric_requests:inc(1, {ngx.var.status, "/test_500/**"}) + metric_latency:observe(tonumber(ngx.var.request_time), {"/test_500/**"}) + } + } + } + + server { + listen 9145; + location /metrics { + content_by_lua_block { + metric_connections:set(ngx.var.connections_reading, {"reading"}) + metric_connections:set(ngx.var.connections_waiting, {"waiting"}) + metric_connections:set(ngx.var.connections_writing, {"writing"}) + prometheus:collect() + } + } + } +} diff --git a/deploy/platform/docker/config/nginx/otel-collector-config.yaml b/deploy/platform/docker/config/nginx/otel-collector-config.yaml new file mode 100644 index 0000000..85f0295 --- /dev/null +++ b/deploy/platform/docker/config/nginx/otel-collector-config.yaml @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +receivers: + prometheus: + config: + scrape_configs: + - job_name: 'nginx-monitoring' + scrape_interval: 5s + metrics_path: "/metrics" + static_configs: + - targets: ['nginx:9145'] + labels: + service: nginx + service_instance_id: nginx-instance +processors: + batch: + +exporters: + otlp: + endpoint: oap:11800 + tls: + insecure: true +service: + pipelines: + metrics: + receivers: + - prometheus + processors: + - batch + exporters: + - otlp \ No newline at end of file diff --git a/deploy/platform/docker/docker-compose.nginx-monitor.yaml b/deploy/platform/docker/docker-compose.nginx-monitor.yaml new file mode 100644 index 0000000..4a770c1 --- /dev/null +++ b/deploy/platform/docker/docker-compose.nginx-monitor.yaml @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '2.1' + +services: + nginx: + build: + context: ./config/nginx + dockerfile: Dockerfile.nginx + volumes: + - ./config/nginx/nginx.conf:/var/nginx/conf.d/nginx.conf + - /tmp/skywalking-logs/nginx:/var/log/nginx + entrypoint: ['bash', '-c', 'openresty -c /var/nginx/conf.d/nginx.conf'] + depends_on: + oap: + condition: service_healthy + ports: + - 8080 + expose: + - 9145 + networks: + - sw + + nginx-caller: + image: openresty/openresty:1.17.8.2-5-alpine-fat + depends_on: + - otel-collector + networks: + - sw + entrypoint: sh + command: + - -c + - "while true; do curl -o /dev/null -s http://nginx:8080/test; curl -o /dev/null -s http://nginx:8080/test_404; curl -o /dev/null -s http://nginx:8080/test_500; sleep 1s; done" + + fluent-bit: + image: fluent/fluent-bit:1.9 + volumes: + - /tmp/skywalking-logs/nginx:/var/log/nginx + - ./config/nginx/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf + - ./config/nginx/fluent-bit-script.lua:/fluent-bit/etc/fluent-bit-script.lua + depends_on: + - oap + - nginx + networks: + - sw + + otel-collector: + image: ${OTEL_COLLECTOR_IMAGE}:${OTEL_COLLECTOR_IMAGE_TAG} + command: [ "--config=/etc/otel-collector-config.yaml" ] + volumes: + - ./config/nginx/otel-collector-config.yaml:/etc/otel-collector-config.yaml + depends_on: + - oap + - nginx + expose: + - 55678 + networks: + sw: + +networks: + sw: diff --git a/deploy/platform/kubernetes/Makefile b/deploy/platform/kubernetes/Makefile index bd9465a..13f071f 100644 --- a/deploy/platform/kubernetes/Makefile +++ b/deploy/platform/kubernetes/Makefile @@ -126,6 +126,11 @@ feature-postgresql-monitor: $(eval HELM_OPTIONS := $(HELM_OPTIONS) --set features.postgresqlMonitor.enabled=true) $(eval HELM_OPTIONS := $(HELM_OPTIONS) --set opentelemetry.enabled=true) +.PHONY: feature-nginx-monitor +feature-nginx-monitor: + $(eval HELM_OPTIONS := $(HELM_OPTIONS) --set features.nginxMonitor.enabled=true) + $(eval HELM_OPTIONS := $(HELM_OPTIONS) --set opentelemetry.enabled=true) + .PHONY: feature-apisix-monitor feature-apisix-monitor: $(eval HELM_OPTIONS := $(HELM_OPTIONS) --set features.apisixMonitor.enabled=true) diff --git a/deploy/platform/kubernetes/Makefile.in b/deploy/platform/kubernetes/Makefile.in index 0892ff6..e126b9e 100644 --- a/deploy/platform/kubernetes/Makefile.in +++ b/deploy/platform/kubernetes/Makefile.in @@ -23,4 +23,4 @@ SAMPLE_SERVICES_NAMESPACE ?= sample-services RELEASE ?= demo AGENTLESS ?= false -FEATURE_FLAGS ?= java-agent-injector,cluster,elasticsearch,kubernetes-monitor,so11y,vm-monitor,als,event,istiod-monitor,satellite,rover,trace-profiling,mysql-monitor,postgresql-monitor,apisix-monitor,grafana,elasticsearch-monitor,rabbitmq-monitor,mongodb-monitor +FEATURE_FLAGS ?= java-agent-injector,cluster,elasticsearch,kubernetes-monitor,so11y,vm-monitor,als,event,istiod-monitor,satellite,rover,trace-profiling,mysql-monitor,postgresql-monitor,nginx-monitor,apisix-monitor,grafana,elasticsearch-monitor,rabbitmq-monitor,mongodb-monitor diff --git a/deploy/platform/kubernetes/templates/feature-nginx-monitor/opentelemetry-config.yaml b/deploy/platform/kubernetes/templates/feature-nginx-monitor/opentelemetry-config.yaml new file mode 100644 index 0000000..aaaf8ae --- /dev/null +++ b/deploy/platform/kubernetes/templates/feature-nginx-monitor/opentelemetry-config.yaml @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +{{- define "opentelemetry-config-nginx" }} +{{- if .Values.features.nginxMonitor.enabled }} + +- job_name: 'nginx-monitoring' + scrape_interval: 5s + metrics_path: "/metrics" + kubernetes_sd_configs: + - role: pod + relabel_configs: + - source_labels: [ __meta_kubernetes_pod_container_name, __meta_kubernetes_pod_container_port_name ] + action: keep + regex: nginx;metrics + - source_labels: [ __meta_kubernetes_pod_name ] + target_label: service_instance_id + regex: (.+) + replacement: $$1 + - target_label: service + replacement: nginx + +{{- end }} +{{- end }} diff --git a/deploy/platform/kubernetes/templates/feature-nginx-monitor/resources.yaml b/deploy/platform/kubernetes/templates/feature-nginx-monitor/resources.yaml new file mode 100644 index 0000000..1e62d03 --- /dev/null +++ b/deploy/platform/kubernetes/templates/feature-nginx-monitor/resources.yaml @@ -0,0 +1,228 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +{{- if .Values.features.nginxMonitor.enabled }} + +apiVersion: v1 +kind: ConfigMap +metadata: + name: nginx-config +data: + nginx.conf: | + worker_processes 1; + daemon off; + error_log /var/log/nginx/error.log notice; + + events { + worker_connections 1024; + } + + http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + lua_shared_dict prometheus_metrics 10M; + # lua_package_path "/path/to/nginx-lua-prometheus/?.lua;;"; + + init_worker_by_lua_block { + prometheus = require("prometheus").init("prometheus_metrics") + + metric_bytes = prometheus:counter( + "nginx_http_size_bytes", "Total size of HTTP", {"type", "route"}) + metric_requests = prometheus:counter( + "nginx_http_requests_total", "Number of HTTP requests", {"status", "route"}) + metric_latency = prometheus:histogram( + "nginx_http_latency", "HTTP request latency", {"route"}) + metric_connections = prometheus:gauge( + "nginx_http_connections", "Number of HTTP connections", {"state"}) + } + + server { + listen 8080; + + location /test { + default_type application/json; + return 200 '{"code": 200, "message": "success"}'; + + log_by_lua_block { + metric_bytes:inc(tonumber(ngx.var.request_length), {"request", "/test/**"}) + metric_bytes:inc(tonumber(ngx.var.bytes_send), {"response", "/test/**"}) + metric_requests:inc(1, {ngx.var.status, "/test/**"}) + metric_latency:observe(tonumber(ngx.var.request_time), {"/test/**"}) + } + } + + location /test_404 { + default_type application/json; + return 404 '{"code": 404, "message": "404 NOT Found"}'; + + log_by_lua_block { + metric_bytes:inc(tonumber(ngx.var.request_length), {"request", "/test_404/**"}) + metric_bytes:inc(tonumber(ngx.var.bytes_send), {"response", "/test_404/**"}) + metric_requests:inc(1, {ngx.var.status, "/test_404/**"}) + metric_latency:observe(tonumber(ngx.var.request_time), {"/test_404/**"}) + } + } + + location /test_500 { + default_type application/json; + return 500 '{"code": 500, "message": "500 Internal Server Error"}'; + + log_by_lua_block { + metric_bytes:inc(tonumber(ngx.var.request_length), {"request", "/test_500/**"}) + metric_bytes:inc(tonumber(ngx.var.bytes_send), {"response", "/test_500/**"}) + metric_requests:inc(1, {ngx.var.status, "/test_500/**"}) + metric_latency:observe(tonumber(ngx.var.request_time), {"/test_500/**"}) + } + } + } + + server { + listen 9145; + location /metrics { + content_by_lua_block { + metric_connections:set(ngx.var.connections_reading, {"reading"}) + metric_connections:set(ngx.var.connections_waiting, {"waiting"}) + metric_connections:set(ngx.var.connections_writing, {"writing"}) + prometheus:collect() + } + } + } + } + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: nginx-log-fluent-bit +data: + fluent-bit.conf: | + [SERVICE] + Flush 5 + Daemon Off + Log_Level warn + [INPUT] + Name tail + Tag access + Path /var/log/nginx/access.log + [INPUT] + Name tail + Tag error + Path /var/log/nginx/error.log + [FILTER] + Name lua + Match access + Script fluent-bit-script.lua + Call rewrite_access_log + [FILTER] + Name lua + Match error + Script fluent-bit-script.lua + Call rewrite_error_log + [OUTPUT] + Name stdout + Match * + Format json + [OUTPUT] + Name http + Match * + Host {{ template "skywalking.oap.address.host" . }} + Port 12800 + URI /v3/logs + Format json + + fluent-bit-script.lua: | + function rewrite_access_log(tag, timestamp, record) + local newRecord = {} + newRecord["layer"] = "NGINX" + newRecord["service"] = "nginx::nginx" + newRecord["serviceInstance"] = os.getenv("SW_SERVICE_INSTANCE") + newRecord["body"] = { text = { text = record.log } } + newRecord["tags"] = { data = { { key = "LOG_KIND", value = "NGINX_ACCESS_LOG" } } } + return 1, timestamp, newRecord + end + + function rewrite_error_log(tag, timestamp, record) + local newRecord = {} + newRecord["layer"] = "NGINX" + newRecord["service"] = "nginx::nginx" + newRecord["serviceInstance"] = os.getenv("SW_SERVICE_INSTANCE") + newRecord["body"] = { text = { text = record.log } } + newRecord["tags"] = { data = { { key = "LOG_KIND", value = "NGINX_ERROR_LOG" } } } + return 1, timestamp, newRecord + end + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + annotations: + sidecar.istio.io/inject: "false" + spec: + containers: + - name: nginx + image: openresty/openresty:1.17.8.2-5-alpine-fat + command: ["sh", "-c", "luarocks install nginx-lua-prometheus && openresty -c /var/nginx/conf.d/nginx.conf"] + ports: + - name: metrics + containerPort: 9145 + volumeMounts: + - name: logs + mountPath: /var/log/nginx/ + - name: nginx-config + mountPath: /var/nginx/conf.d/ + - name: nginx-caller + image: openresty/openresty:1.17.8.2-5-alpine-fat + command: ["sh", "-c", "while true; do curl -o /dev/null -s http://localhost:8080/test; curl -o /dev/null -s http://localhost:8080/test_404; curl -o /dev/null -s http://localhost:8080/test_500; sleep 1s; done"] + - name: fluent-bit + image: fluent/fluent-bit:1.9 + env: + - name: SW_SERVICE_INSTANCE + valueFrom: + fieldRef: + fieldPath: metadata.name + volumeMounts: + - name: logs + mountPath: /var/log/nginx/ + - name: fluent-bit-config + mountPath: /fluent-bit/etc/ + volumes: + - name: logs + emptyDir: {} + - name: nginx-config + configMap: + name: nginx-config + - name: fluent-bit-config + configMap: + name: nginx-log-fluent-bit + +{{- end }} diff --git a/deploy/platform/kubernetes/templates/otel-collector-config.yaml b/deploy/platform/kubernetes/templates/otel-collector-config.yaml index 1b3b49b..ba3a09f 100644 --- a/deploy/platform/kubernetes/templates/otel-collector-config.yaml +++ b/deploy/platform/kubernetes/templates/otel-collector-config.yaml @@ -28,6 +28,7 @@ data: prometheus: config: scrape_configs: + {{- include "opentelemetry-config-nginx" . | indent 12 }} {{- include "opentelemetry-config-apisix" . | indent 12 }} {{- include "opentelemetry-config-istiod-monitor" . | indent 12 }} {{- include "opentelemetry-config-kubernetes-monitor" . | indent 12 }} diff --git a/deploy/platform/kubernetes/values.yaml b/deploy/platform/kubernetes/values.yaml index c5e83e6..dffd3f7 100644 --- a/deploy/platform/kubernetes/values.yaml +++ b/deploy/platform/kubernetes/values.yaml @@ -40,7 +40,7 @@ skywalking: # @feature: istiod-monitor; enable rules to analyze Istio control plane metrics # @feature: mysql; enable mysql rules to analyze MySQL metrics # @feature: apisix-monitor; enable APISIX rules to analyze APISIX metrics - SW_OTEL_RECEIVER_ENABLED_OTEL_RULES: vm,oap,k8s/*,istio-controlplane,mysql/*,postgresql/*,apisix,elasticsearch/*,rabbitmq/*,mongodb/* + SW_OTEL_RECEIVER_ENABLED_OTEL_RULES: vm,oap,k8s/*,istio-controlplane,mysql/*,postgresql/*,apisix,elasticsearch/*,rabbitmq/*,mongodb/*,nginx/* SW_TELEMETRY: prometheus # @feature: so11y; expose the metrics of self o11y through prometheus SW_ENVOY_METRIC_ALS_HTTP_ANALYSIS: "mx-mesh,persistence" # @feature: als; enable mesh analyzer (mx-mesh) to analyze ALS logs K8S_SERVICE_NAME_RULE: "mesh-svr::${service.metadata.name}" @@ -300,6 +300,9 @@ features: istiodMonitor: enabled: false + nginxMonitor: + enabled: false + apisixMonitor: enabled: false diff --git a/docs/readme.md b/docs/readme.md index f884f7e..e9fbcdf 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -106,6 +106,7 @@ Currently, the features supported are: | `postgresql-monitor` | Start a PostgreSQL server, and load generator to execute the sample SQLs periodically, set up fluent bit to fetch slow logs and export to OAP, and export their metrics to SkyWalking. | | | `elasticsearch-monitor` | Deploy OpenTelemetry and export Elasticsearch monitoring metrics to SkyWalking for analysis and display on UI. | | | `mongodb-monitor` | Deploy OpenTelemetry and export MongoDB monitoring metrics to SkyWalking for analysis and display on UI. | | +| `nginx-monitor` | Deploy OpenTelemetry and export Nginx metrics and logs to SkyWalking for analysis and display on UI | | | `apisix-monitor` | Deploy OpenTelemetry and export APISIX metrics to SkyWalking for analysis and display on UI | | | `mesh-with-agent` | Deploy services with java agent in the service mesh environment. | Only support deployment in the Kubernetes environment, docker is not supported. | | `grafana` | Deploy a Grafana to show SkyWalking metrics and logs on the Grafana UI. | Feel free to modify the Grafana config when deploy your own environment. |