<h2 id="revision---21st-june-2022">Revision - 21st June 2022</h2>
<ul>
<li>Updated visitor map to support week on week comparison and top country listing</li>
</ul>
<h2 id="revision---20th-february-2021">Revision - 20th February 2021</h2>
<ul>
<li>Changed overall dashboard look and initial display of panels.</li>
</ul>
<h2 id="revision---16th-february-2021">Revision - 16th February 2021</h2>
<ul>
<li>Last 30 day graph of unique visitors to site added</li>
<li>Removed more browser and crawler bot statistics from unique visitors and other relevant panels</li>
</ul>
<h2 id="revision---12th-february-2021">Revision - 12th February 2021</h2>
<ul>
<li>Changed Last 7 day graph from ’new time series beta graph’ to standard graph display.</li>
<li>Removed further browser and crawler bot statistics from relevant panel - to add these back in edit the panel and remove below from query on each panel.</li>
</ul>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">| http_user_agent !~ ".*bot.*" | remote_addr !~ "2001:4ca0:108:42::*" | remote_addr !~ "91.134.156.*" | http_user_agent != "worldping-api" | request_uri !~ "/wp-.*" | request_uri !~ "//wp-.*" | request_uri !~ "/*.wordfence.*" | request_uri !~ "/robots.txt" | request_uri !~ "/xmlrpc.php"</code></pre>
</div>
</div>
<h2 id="extension-of-original-dashboard">Extension of original dashboard</h2>
<p><a href="/grafana/dashboards/12559?pg=dashboards&plcmt=featured-main">https://grafana.com/grafana/dashboards/12559?pg=dashboards&plcmt=featured-main</a></p>
<h2 id="setup-of-nginx-promtail--loki-required">Setup of nginx, promtail & loki required</h2>
<p><a href="https://www.youtube.com/watch?v=kR5ay4lX0OM" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=kR5ay4lX0OM</a></p>
<h2 id="required-nginx-json-log-format-configuration-described-below">Required nginx json log format configuration described below</h2>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">log_format json_analytics escape=json '{'
'"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution
'"connection": "$connection", ' # connection serial number
'"connection_requests": "$connection_requests", ' # number of requests made in connection
'"pid": "$pid", ' # process pid
'"request_id": "$request_id", ' # the unique request id
'"request_length": "$request_length", ' # request length (including headers and body)
'"remote_addr": "$remote_addr", ' # client IP
'"remote_user": "$remote_user", ' # client HTTP username
'"remote_port": "$remote_port", ' # client port
'"time_local": "$time_local", '
'"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format
'"request": "$request", ' # full path no arguments if the request
'"request_uri": "$request_uri", ' # full path and arguments if the request
'"args": "$args", ' # args
'"status": "$status", ' # response status code
'"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client
'"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client
'"http_referer": "$http_referer", ' # HTTP referer
'"http_user_agent": "$http_user_agent", ' # user agent
'"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for
'"http_host": "$http_host", ' # the request Host: header
'"server_name": "$server_name", ' # the name of the vhost serving the request
'"request_time": "$request_time", ' # request processing time in seconds with msec resolution
'"upstream": "$upstream_addr", ' # upstream backend server for proxied requests
'"upstream_connect_time": "$upstream_connect_time", ' # upstream handshake time incl. TLS
'"upstream_header_time": "$upstream_header_time", ' # time spent receiving upstream headers
'"upstream_response_time": "$upstream_response_time", ' # time spend receiving upstream body
'"upstream_response_length": "$upstream_response_length", ' # upstream response length
'"upstream_cache_status": "$upstream_cache_status", ' # cache HIT/MISS where applicable
'"ssl_protocol": "$ssl_protocol", ' # TLS protocol
'"ssl_cipher": "$ssl_cipher", ' # TLS cipher
'"scheme": "$scheme", ' # http or https
'"request_method": "$request_method", ' # request method
'"server_protocol": "$server_protocol", ' # request protocol, like HTTP/1.1 or HTTP/2.0
'"pipe": "$pipe", ' # "p" if request was pipelined, "." otherwise
'"gzip_ratio": "$gzip_ratio", '
'"http_cf_ray": "$http_cf_ray",'
'"geoip_country_code": "$geoip_country_code"'
'}';
access_log /var/log/nginx/access.log json_analytics;</code></pre>
</div>
</div>
<p>Adding log_format to sites-available on Nginx :</p>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">server {
....
access_log /var/log/nginx/website_access.log json_analytics;</code></pre>
</div>
</div>
<p>For IP to country mapping, also enable the Geo_IP module:</p>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">geoip_country /etc/nginx/GeoIP.dat;
geoip_city /etc/nginx/GeoIPCity.dat;</code></pre>
</div>
</div>
<p>Option if you are using Cloudflare IP Geo location you can change the log_format :</p>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">'"geoip_country_code": "$http_cf_ipcountry"'</code></pre>
</div>
</div>
<p>Cloudflare IP Geo location : <a href="https://support.cloudflare.com/hc/en-us/articles/200168236-Configuring-Cloudflare-IP-Geolocation" target="_blank" rel="noopener noreferrer">https://support.cloudflare.com/hc/en-us/articles/200168236-Configuring-Cloudflare-IP-Geolocation</a></p>
<p>Promtail scrapes the log files best when you mount the log volume in the docker container.</p>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">$ sudo mv promtail-config.yaml /mnt/config/
$ docker create --name promtail --restart unless-stopped -v /mnt/config:/mnt/config -v /var/log:/var/log grafana/promtail:2.1.0 -config.file=/mnt/config/promtail-config.yaml
$ docker start promtail</code></pre>
</div>
</div>
<p>Promtail-config.yml file details.</p>
<div class="code-snippet "><div class="lang-toolbar">
<span class="lang-toolbar__item lang-toolbar__item-active">console</span>
<span class="code-clipboard">
<button x-data="app_code_snippet()" x-init="init()" @click="copy()">
<img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
<span>Copy</span>
</button>
</span>
<div class="lang-toolbar__border"></div>
</div><div class="code-snippet ">
<pre data-expanded="false"><code class="language-console">server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://<ip address>:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
host: nginx01
agent: promtail
__path__: /var/log/*log
- job_name: nginx
static_configs:
- targets:
- localhost
labels:
job: nginx
host: nginx01
agent: promtail
__path__: /var/log/nginx/*log</code></pre>
</div>
</div>
Data source config
Collector type:
Collector config: