From bbf1da0dcfe546f414a3690a6e2b4e1fa520e50c Mon Sep 17 00:00:00 2001 From: rohow Date: Mon, 22 Jul 2024 12:16:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(loki):=20=E6=97=A5=E5=BF=97=E6=90=9C?= =?UTF-8?q?=E9=9B=86=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{helmchart.yaml => helmchart-loki.yaml} | 3 -- apps/monitor/loki/helmchart-promtail.yaml | 24 +++++++++ apps/net/nginx/helmchart.yaml | 53 ++++++++++++++++++- 3 files changed, 76 insertions(+), 4 deletions(-) rename apps/monitor/loki/{helmchart.yaml => helmchart-loki.yaml} (95%) create mode 100644 apps/monitor/loki/helmchart-promtail.yaml diff --git a/apps/monitor/loki/helmchart.yaml b/apps/monitor/loki/helmchart-loki.yaml similarity index 95% rename from apps/monitor/loki/helmchart.yaml rename to apps/monitor/loki/helmchart-loki.yaml index a4daa89..c86e39a 100644 --- a/apps/monitor/loki/helmchart.yaml +++ b/apps/monitor/loki/helmchart-loki.yaml @@ -15,7 +15,6 @@ spec: lokiCanary: nodeSelector: svccontroller.k3s.cattle.io/enablelb: "true" - labelname: name extraArgs: # 降低测试日志生成条数 - -interval=30s @@ -34,8 +33,6 @@ spec: auth_enabled: false commonConfig: replication_factor: 1 - limits_config: - storage: type: 'filesystem' schemaConfig: diff --git a/apps/monitor/loki/helmchart-promtail.yaml b/apps/monitor/loki/helmchart-promtail.yaml new file mode 100644 index 0000000..c5b5fbb --- /dev/null +++ b/apps/monitor/loki/helmchart-promtail.yaml @@ -0,0 +1,24 @@ +apiVersion: helm.cattle.io/v1 +kind: HelmChart +metadata: + name: loki-promtail + namespace: infra-monitor +spec: + repo: https://grafana.github.io/helm-charts + chart: promtail + targetNamespace: infra-monitor + version: 6.7.1 + valuesContent: |- + nodeSelector: + svccontroller.k3s.cattle.io/enablelb: "true" + configmap: + enabled: true + config: + clients: + - url: http://loki.infra-monitor:3100/loki/api/v1/push + tenant_id: 1 + snippets: + extraRelabelConfigs: + - source_labels: [__meta_kubernetes_pod_label_log_collecting_enabled] + action: keep + regex: true diff --git a/apps/net/nginx/helmchart.yaml b/apps/net/nginx/helmchart.yaml index 1498aa1..3299ed2 100644 --- a/apps/net/nginx/helmchart.yaml +++ b/apps/net/nginx/helmchart.yaml @@ -17,6 +17,8 @@ spec: - key: "node-role.kubernetes.io/master" operator: "Exists" effect: "NoSchedule" + labels: + log-collecting/enabled: "true" kind: DaemonSet hostNetwork: true hostPort: @@ -28,16 +30,65 @@ spec: config: use-forwarded-headers: "true" allow-snippet-annotations: "true" + # 缓存配置 http-snippet: | proxy_cache_path /tmp/nginx-cache levels=1:2 keys_zone=cache:2m max_size=100m inactive=7d use_temp_path=off; proxy_cache_key $scheme$proxy_host$request_uri; proxy_cache_lock on; proxy_cache_use_stale updating; + # dns配置 server-snippet : | resolver 169.254.20.10 10.43.0.10 ipv6=off; + # 启用geoip2模块 + use-geoip: "false" + use-geoip2: "true" + # 日志配置 + log-format-escape-json: "true" + log-format-upstream: '{ + "msec": "$msec", + "connection": "$connection", + "connection_requests": "$connection_requests", + "pid": "$pid", + "request_id": "$request_id", + "request_length": "$request_length", + "remote_addr": "$remote_addr", + "remote_user": "$remote_user", + "remote_port": "$remote_port", + "time_local": "$time_local", + "time_iso8601": "$time_iso8601", + "request": "$request", + "request_uri": "$request_uri", + "args": "$args", + "status": "$status", + "body_bytes_sent": "$body_bytes_sent", + "bytes_sent": "$bytes_sent", + "http_referer": "$http_referer", + "http_user_agent": "$http_user_agent", + "http_x_forwarded_for": "$http_x_forwarded_for", + "http_host": "$http_host", + "server_name": "$server_name", + "request_time": "$request_time", + "upstream": "$upstream_addr", + "upstream_connect_time": "$upstream_connect_time", + "upstream_header_time": "$upstream_header_time", + "upstream_response_time": "$upstream_response_time", + "upstream_response_length": "$upstream_response_length", + "upstream_cache_status": "$upstream_cache_status", + "ssl_protocol": "$ssl_protocol", + "ssl_cipher": "$ssl_cipher", + "scheme": "$scheme", + "request_method": "$request_method", + "server_protocol": "$server_protocol", + "pipe": "$pipe", + "gzip_ratio": "$gzip_ratio", + "http_cf_ray": "$http_cf_ray", + "geoip_country_code": "$geoip2_city_country_code" + }' # crowdsec插件配置 plugins: "crowdsec" lua-shared-dicts: "crowdsec_cache: 50m" + # 启用geoip2模块 + maxmindLicenseKey: "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" extraArgs: default-ssl-certificate: "infra-net/dev-cm-crt" # crowdsec插件配置 @@ -62,4 +113,4 @@ spec: extraVolumeMounts: - name: crowdsec-bouncer-plugin mountPath: /etc/nginx/lua/plugins/crowdsec - subPath: crowdsec \ No newline at end of file + subPath: crowdsec