nginx日志分析工具


安装goaccess 

$ wget -O - https://deb.goaccess.io/gnugpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/goaccess.gpg >/dev/null
$ echo "deb [signed-by=/usr/share/keyrings/goaccess.gpg] https://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/goaccess.list
$ sudo apt-get update
$ sudo apt-get install goaccess

goaccess使用帮助

GoAccess - 1.5.5

Usage: goaccess [filename] [ options ... ] [-c][-M][-H][-S][-q][-d][...]
The following options can also be supplied to the command:

LOG & DATE FORMAT OPTIONS

  --date-format=      - Specify log date format. e.g., %d/%b/%Y
  --log-format=        - Specify log format. Inner quotes need escaping, or use single quotes.
  --time-format=      - Specify log time format. e.g., %H:%M:%S


USER INTERFACE OPTIONS

  -c --config-dialog              - Prompt log/date/time configuration window.
  -i --hl-header                  - Color highlight active panel.
  -m --with-mouse                 - Enable mouse support on main dashboard.
  --color=   - Specify custom colors. See manpage for more details.
  --color-scheme=<1|2|3>          - Schemes: 1 => Grey, 2 => Green, 3 => Monokai.
  --html-custom-css=    - Specify a custom CSS file in the HTML report.
  --html-custom-js=      - Specify a custom JS file in the HTML report.
  --html-prefs=         - Set default HTML report preferences.
  --html-report-title=     - Set HTML report page title and header.
  --html-refresh=<secs>           - Refresh HTML report every X seconds (>=1 or <=60).
  --json-pretty-print             - Format JSON output w/ tabs & newlines.
  --max-items                     - Maximum number of items to show per panel. See man page for limits.
  --no-color                      - Disable colored output.
  --no-column-names               - Don't write column names in term output.
  --no-csv-summary                - Disable summary metrics on the CSV output.
  --no-html-last-updated          - Hide HTML last updated field.
  --no-parsing-spinner            - Disable progress metrics and parsing spinner.
  --no-progress                   - Disable progress metrics.
  --no-tab-scroll                 - Disable scrolling through panels on TAB.

SERVER OPTIONS

  --addr=<addr>                   - Specify IP address to bind server to.
  --unix-socket=<addr>            - Specify UNIX-domain socket address to bind server to.
  --daemonize                     - Run as daemon (if --real-time-html enabled).
  --fifo-in=<path>                - Path to read named pipe (FIFO).
  --fifo-out=<path>               - Path to write named pipe (FIFO).
  --origin=<addr>                 - Ensure clients send this origin header upon the WebSocket handshake.
  --pid-file=<path>               - Write PID to a file when --daemonize is used.
  --port=<port>                   - Specify the port to use.
  --real-time-html                - Enable real-time HTML output.
  --ssl-cert=<cert.crt>           - Path to TLS/SSL certificate.
  --ssl-key=<priv.key>            - Path to TLS/SSL private key.
  --user-name=<username>          - Run as the specified user.
  --ws-url=<url>                  - URL to which the WebSocket server responds.

FILE OPTIONS

  -                               - The log file to parse is read from stdin.
  -f --log-file=<filename>        - Path to input log file.
  -l --debug-file=<filename>      - Send all debug messages to the specified file.
  -p --config-file=<filename>     - Custom configuration file.
  -S --log-size=<number>          - Specify the log size, useful when piping in logs.
  --invalid-requests=<filename>   - Log invalid requests to the specified file.
  --no-global-config              - Don't load global configuration file.
  --unknowns-log=<filename>       - Log unknown browsers and OSs to the specified file.

PARSE OPTIONS

  -a --agent-list                 - Enable a list of user-agents by host.
  -b --browsers-file=<path>       - Use additional custom list of browsers.
  -d --with-output-resolver       - Enable IP resolver on HTML|JSON output.
  -e --exclude-ip=<IP>            - Exclude one or multiple IPv4/6. Allows IP ranges
                                    e.g. 192.168.0.1-192.168.0.10
  -H --http-protocol=<yes|no>     - Set/unset HTTP request protocol if found.
  -M --http-method=<yes|no>       - Set/unset HTTP request method if found.
  -o --output=file.html|json|csv  - Output either an HTML, JSON or a CSV file.
  -q --no-query-string            - Strip request's query string. This can decrease memory consumption.
  -r --no-term-resolver           - Disable IP resolver on terminal output.
  --444-as-404                    - Treat non-standard status code 444 as 404.
  --4xx-to-unique-count           - Add 4xx client errors to the unique visitors count.
  --all-static-files              - Include static files with a query string.
  --anonymize-ip                  - Anonymize IP addresses before outputting to report.
  --crawlers-only                 - Parse and display only crawlers.
  --date-spec=<date|hr>           - Date specificity. Possible values: `date` (default), or `hr`.
  --double-decode                 - Decode double-encoded values.
  --enable-panel=<PANEL>          - Enable parsing/displaying the given panel.
  --hide-referrer=<NEEDLE>        - Hide a referrer but still count it. Wild cards are allowed.
                                    i.e., *.bing.com
  --hour-spec=<hr|min>            - Hour specificity. Possible values: `hr` (default),
                                    or `min` (tenth of a min).
  --ignore-crawlers               - Ignore crawlers.
  --ignore-panel=<PANEL>          - Ignore parsing/displaying the given panel.
  --ignore-referrer=<NEEDLE>      - Ignore a referrer from being counted. Wild cards are allowed.
                                    i.e., *.bing.com
  --ignore-statics=<req|panel>    - Ignore static requests.
                                    req => Ignore from valid requests.
                                    panel => Ignore from valid requests and panels.
  --ignore-status=<CODE>          - Ignore parsing the given status code.
  --keep-last=<NDAYS>             - Keep the last NDAYS in storage.
  --no-ip-validation              - Disable client IPv4/6  validation.
  --no-strict-status              - Disable HTTP status code validation.
  --num-tests=<number>            - Number of lines to test. >= 0 (10 default)
  --persist                       - Persist data to disk on exit to the given --db-path or to /tmp.
  --process-and-exit              - Parse log and exit without outputting data.
  --real-os                       - Display real OS names. e.g, Windows XP, Snow Leopard.
  --restore                       - Restore data from disk from the given --db-path or from /tmp.
  --sort-panel=PANEL,METRIC,ORDER - Sort panel on initial load. e.g., --sort-panel=VISITORS,BY_HITS,ASC.
                                    See manpage for a list of panels/fields.
  --static-file=<extension>       - Add static file extension. e.g.: .mp3. Extensions are case sensitive.

GEOIP OPTIONS

  --geoip-database=<path>         - Specify path to GeoIP database file.
                                    i.e., GeoLiteCity.dat, GeoIPv6.dat ...

OTHER OPTIONS

  -h --help                       - This help.
  -s --storage                    - Display current storage method. e.g., Hash.
  -V --version                    - Display version information and exit.
  --dcf                           - Display the path of the default config file when `-p` is not used.

Examples can be found by running `man goaccess`.

For more details visit: https://goaccess.io/
GoAccess Copyright (C) 2009-2020 by Gerardo Orellana</code></pre>
<h1>添加中文支持</h1>
<pre class="language-bash"><code>apt -y install language-pack-zh-hans
export LANG=zh_CN.UTF-8</code></pre>
<h1>查看nginx记录格式</h1>
<pre class="language-bash"><code>log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" $request_time $upstream_response_time $request_method $host $uri "$request_body" '
                      '"$http_user_agent" "$http_x_forwarded_for" $upstream_cache_status ';</code></pre>
<h1>添加goaccess配置</h1>
<p>和nginx日志记录格式对应</p>
<pre class="language-bash"><code>time-format %T
date-format %d/%b/%Y
log_format %h - %^ [%d:%t %^] "%r" %s %b "%R" %T %^ %m %v %^ "%r_body" "%u" "%^"</code></pre>
<h1>生成报表</h1>
<pre class="language-bash"><code>goaccess -f /usr/local/nginx/logs/access.log -p ./nginlog.conf -o report.html</code></pre>
						  
					  </div>
						<!--conend-->
							<div class="p-2"></div>

						<div class="arcinfo my-3 fs-7 text-center">
							
							
			<a href='/t/etagid626-0.html' class='tagbtn' target='_blank'>Nginx</a>							
						



						</div>
						
						<div class="p-2"></div>

						

						
					</div>
					<div class="p-2"></div>
					<!--xg-->
					<div class="lbox p-4 shadow-sm rounded-3">
						<div class="boxtitle"><h2 class="fs-4">相关</h2></div>
						
<hr>				
						
			<div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-566392.html">linux环境开机自启动nginx</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-565613.html">nginx下配置多个web服务</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-565808.html">一步一步配置docker(tomcat+jenkins+phpmyadmin+nginx)</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-565320.html">阿里云服务器搭建Nginx+rtmp推流服务器</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-564773.html">nginx反向代理websocket wss或ws端口</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="">docker安装与配置nginx详细过程</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-562530.html">ceryx+redis实现nginx动态路由功能、动态管理upstream</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-561908.html">nginx配置文件</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-560881.html">k8s中的nginx-ingress如何配置路径重定向</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-559714.html">Nginx实现负载均衡</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-555043.html">nginx 配置 https</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-553865.html">vue-router history模式在nginx二级目录下的配置</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div>            
            
            <!---->
                                    
           <!---->
  			
						

					</div>
					<!--xgend-->
				</div>

				<div class="col-lg-3 col-12 p-0 ps-lg-2">
					<!--box-->									
					<!--boxend-->
					<!--<div class="p-2"></div>-->

					<!--box-->
									<div class="lbox p-4 shadow-sm rounded-3">
					
									   <div class="boxtitle pb-2"><h2 class="fs-4"><a href="#">标签</a></h2></div>
										<div class="clearfix"></div>
										<ul class="m-0 p-0 fs-7 r-tag">
										</ul>
									

										
										<div class="clearfix"></div>
									</div>
					<!--box end-->

					
				</div>

			</div>
		
		
		
		</div>	

</main>
						<div class="p-2"></div>
<footer>
<div class="container-fluid p-0 bg-black">
	<div class="container p-0  fs-8">
	<p class="text-center m-0 py-2 text-white-50">一品网 <a class="text-white-50" href="https://beian.miit.gov.cn/" target="_blank">冀ICP备14022925号-6</a></p>
	</div>	
</div>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?6e3dd49b5f14d985cc4c6bdb9248f52b";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</footer>
		
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js"></script>

</body>
</html>