kong更改日志格式
基于业务的需求,需要对网关层的日志进行适当定制,以满足使用kibana的制图。
对于kong的日志格式更改,可查看到的资料都过于繁琐,特此记录。
修改kong的日志格式
# ctl edit deployment ingress-kong -n kong
...
spec:
containers:
- env:
- name: KONG_PLUGINS
value: forward-auth-request,prometheus
- name: KONG_LUA_PACKAGE_PATH
value: /opt/?.lua;;
- name: KONG_PROXY_LISTEN
value: 0.0.0.0:8000, 0.0.0.0:8443 ssl http2
- name: KONG_ADMIN_LISTEN
value: 127.0.0.1:8444 ssl
- name: KONG_STATUS_LISTEN
value: 0.0.0.0:8100
- name: KONG_DATABASE
value: "off"
- name: KONG_NGINX_WORKER_PROCESSES
value: "1"
- name: KONG_ADMIN_ACCESS_LOG
value: /dev/stdout custom_fmt
- name: KONG_ADMIN_ERROR_LOG
value: /dev/stderr
- name: KONG_PROXY_ACCESS_LOG
value: /dev/stdout custom_fmt
- name: KONG_PROXY_ERROR_LOG
value: /dev/stderr
- name: KONG_NGINX_HTTP_LOG_FORMAT
value: custom_fmt '$remote_addr - $remote_user [$time_local] "$request"
$status "$upstream_status" $body_bytes_sent "$http_referer" "$http_user_agent"
"$request_time" "$upstream_response_time"'
...
查看日志格式
1xx.xxx.xxx.xx - - [26/Jan/2021:08:14:59 +0000] "PUT /api/xxxx/xxs/xxxx38a458 HTTP/2.0" 200 "200" 133 "https://www.baidu.com/xx/exxxor/e11xxxxxxxxxx47c/?lang=zh" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" "0.072" "0.068"
kong 获取客户端真实ip
# ctl edit svc kong-proxy -n kong
...
spec:
...
externalTrafficPolicy: Local
...
logstash 解析kong日志格式
filter { # kong的单独索引
if [type] == "kong" {
grok {
match => {
"message" => '(?<clientip>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) - - \[(?<requesttime>[^ ]+ \+[0-9]+)\] "(?<requesttype>[A-Z]+) (?<requesturl>[^ ]+) HTTP/\d.\d" (?<status>[0-9]{3}) "(?<upstream_status>[0-9]+)" (?<body_bytes_sent>[0-9]+) "(?<http_referer>[^"]+)" "(?<http_user_agent>[^"]+)" "(?<request_time>[0-9]+\.[0-9]+)" "(?<upstream_response_time>[0-9]+\.[0-9]+)"'
}
}
date {
match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
target => "@timestamp"
}
geoip {
source => "clientip"
target => ["geoip"]
fi
}
}
}
kong更改日志格式的更多相关文章
- Nginx内置变量以及日志格式变量参数详解
$args #请求中的参数值 $query_string #同 $args $arg_NAME #GET请求中NAME的值 $is_args #如果请求中有参数,值为"?",否则为 ...
- binlog之四:mysql中binlog_format模式与配置详解,binlog的日志格式详解
mysql复制主要有三种方式:基于SQL语句的复制(statement-based replication, SBR),基于行的复制(row-based replication, RBR),混合模式复 ...
- Nginx内置变量以及日志格式变量
$args #请求中的参数值$query_string #同 $args$arg_NAME #GET请求中NAME的值$is_args #如果请求中有参数,值为"?",否则为空字符 ...
- log_format为Nginx设置日志格式
nginx服务器日志相关指令主要有两条,一条是log_format,用来设置日志格式, 另外一条是access_log,用来指定日志文件的存放路径.格式和缓存大小,一般在nginx的配置文件中日记配置 ...
- 【nginx运维基础(4)】Nginx的日志管理(日志格式与定时分割日志)
Nginx日志主要分为两种:访问日志和错误日志.日志开关在Nginx配置文件(一般在server段来配置)中设置,两种日志都可以选择性关闭,默认都是打开的. 访问日志access_log #日志格式设 ...
- nignx日志格式
web-master的nginx格式: log_format web_format '$remote_addr $remote_port $remote_user [$time_local] ' '& ...
- 场景2 nginx 错误日志格式:
nginx 错误日志格式: 2016/09/01 11:23:36 [error] 28388#0: *14549 open() "/var/www/zjzc-web-frontEnd/im ...
- nginx日志格式
日志格式 log_format main '$remote_addr - $remote_user [$time_local] $request ' '" ...
- rsyslog 日志格式和输出
日志格式: $EscapeControlCharactersOnReceive off #关闭rsyslog默认转译ASCII<32的所有怪异字符,包括换行符等 $template nginx- ...
随机推荐
- jest all in one
jest all in one ES Modules & TypeScript & React https://github.com/xgqfrms/FEAT/tree/master/ ...
- .pyc & Python
.pyc & Python Python bytecode / 字节码 Python compiles the .py files and saves it as .pyc files , s ...
- LeetCode & Binary Search 解题模版
LeetCode & Binary Search 解题模版 In computer science, binary search, also known as half-interval se ...
- node.js & Unbuntu Linux & nvm & npm
node.js & Unbuntu Linux & nvm & npm https://websiteforstudents.com/install-the-latest-no ...
- 安装 Angular Material UI
文档 调色板 安装 ng add @angular/material ? Choose a prebuilt theme name, or "custom" for a custo ...
- pycharm + git+gitlab的可视化界面操作
前言: 写这篇博客,主要为了记录一套经过本人实践,并运行通过的操作gitlab流程. 通过以下步骤,可实现最基本的远程服务器(gitlab)和本地工具(pycharm)的,针对两端文件增删改查的及 ...
- 官网GitLab CI/CD英文文档翻译
在查阅GitLab官网的CI/CD功能说明时,全是英文看起来不方便,通过翻译软件自动翻译后"内容失真",看起来很变扭.查阅了百度上的资料发现很多翻译很老旧,有些甚至是挂羊头卖狗肉. ...
- Flex实现左右布局
html <div class="business-content-1"> <div class="item"> 111 </di ...
- java基础第11期——Stream流、方法引用、junit单元测试
1.Stream流 Stream流与io流是不同的东西,用于解决集合类库已有的弊端, 1.1 获取Stream流: Collection集合的Stream方法,注意Map集合要经过转化 default ...
- 【springboot读取配置文件】@ConfigurationProperties、@PropertySource和@Value
概念: @ConfigurationProperties : 是springboot的注解,用于把主配置文件中配置属性设置到对于的Bean属性上 @PropertySource :是spring的注解 ...