<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>accesslogs Archives | Clever Cloud</title>
	<atom:link href="https://www.clever.cloud/blog/tag/accesslogs/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.clever.cloud/blog/tag/accesslogs/</link>
	<description>From Code to Product</description>
	<lastBuildDate>Thu, 09 Apr 2020 11:35:00 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://cdn.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>accesslogs Archives | Clever Cloud</title>
	<link>https://www.clever.cloud/blog/tag/accesslogs/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Access Logs are now available from Clever Tools</title>
		<link>https://www.clever.cloud/blog/features/2020/04/09/access-logs-clever-tools/</link>
		
		<dc:creator><![CDATA[Laurent Doguin]]></dc:creator>
		<pubDate>Thu, 09 Apr 2020 11:35:00 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[accesslogs]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[logs]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2020/04/09/access-logs-clever-tools/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="access logs clever tools 1" decoding="async" fetchpriority="high" srcset="https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p>Yes you read it right, you can now access your access logs. How you ask? With the latest release of Clever Tools. But before we see how it works, let me explain what access logs are.

<span id="more-2973"></span>

Access logs contain all incoming requests to a web server. They are available in different formats. One of the most common being CLF which stands for <a href="https://en.wikipedia.org/wiki/Common_Log_Format">Common Log Format</a>. Here's an example where you can find the IP of the client, date, HTTP verb, URL target, status code and size of the answer: <code>255.255.255.255 - - [06/Feb/2020:07:59:22 +0100] "GET /aget/to/your/beautiful/website -" 200 1453</code>
<h2 id="how-to-get-your-access-logs">How to get your access logs</h2>
To get your access logs you need to use <a href="https://github.com/CleverCloud/clever-tools/">clever-tools</a> and run this in a linked application:

<code>clever accesslogs</code>

You will get all the requests that came to this app in the last hour. This also work for most dedicated add-ons using <code>--addon</code> followed by the add-on id:

<code>clever accesslogs --addon addon_41c5a60f-11c6-442a-9803-f4604fe8638b</code>

You can also choose a date span using <code>--after</code> and <code>--before</code> like so:

<code>clever accesslogs --after 2020-03-27 --before 2020-03-29</code>

Any date you give must follow ISO 8601. You could for instance have a microsecond precision like this:

<code>clever accesslogs --after 2020-03-29T11:01:02.120000Z --before 2020-03-29T11:01:02.123456Z</code>

You can also change the format of the logs with <code>-F</code> (or <code>--format</code>):

<code>clever accesslogs --after 2020-03-28 --before 2020-03-29 -F json</code>

Here's an example of JSON entry, it contains all of the information currently available for each request:
<pre><code class="language-json">{
  "t": "2020-03-10T11:24:34.220324Z",
  "a": "app_87d748d4-3c7b-4baa-8f52-c748e1123ab3",
  "adc": "par-cleverapps-adc-n6",
  "o": "user_51f7098f-604e-4d9e-8fb6-4026fd1767bb",
  "i": "0805330e-cff6-4fd5-87c0-26974d8bcb4e",
  "ipS": "255.255.255.255",
  "pS": 38566,
  "s": {
    "lt": 48.6719,
    "lg": 1.3002,
    "ct": "Aunay-sous-Crecy",
    "co": "FR"
  },
  "ipD": "255.258.258.258",
  "pD": 11810,
  "d": {
    "lt": 48.7967,
    "lg": 2.3338,
    "ct": "Cachan",
    "co": "FR"
  },
  "vb": "GET",
  "path": "/status-codes/500",
  "bIn": 411,
  "bOut": 443,
  "h": "app-87d748d4-3c7b-4baa-8f52-c748e1123ab3.cleverapps.io",
  "rTime": "3ms",
  "sTime": "115μs",
  "scheme": "HTTPS",
  "sC": 500,
  "sT": "Internal Server Error",
  "w": "WRK-01",
  "r": "b6bcab8a-c6d0-4546-9000-57b43d009a49",
  "tlsV": "TLS1.3"
}
</code></pre>
You will find the details for every field in our <a href="https://www.clever.cloud/developers/administrate/metrics/overview/#access-logs-metrics">access logs documentation</a>.
<h2 id="what-you-can-do-with-your-logs">What you can do with your logs</h2>
Now let's say you want to know what are the most returned status codes from a log file, here's how you can do it:
<pre><code class="language-bash">clever accesslogs --after 2020-03-10 --before 2020-03-20 -F json | jq .sC | sort | uniq -c | sort -nr
</code></pre>
Here we use the JSON format and <code>jq</code> to select the field we want, then <code>sort</code> and <code>uniq</code> to get a proper output, which would yield something like:
<pre><code class="language-text">  99999 200
     56 500
     33 404
      2 400
      1 403
      1 301
      1 202
</code></pre>
The first column being the number of hits and the second being the status code.

Now for something a bit more practical, here's a script that allows you to split access logs for each day between two dates:
<pre><code class="language-bash">#!/bin/bash

input_start=2020-01-01
input_end=2020-03-27

startdate=$(date -I -d "$input_start") || exit -1
enddate=$(date -I -d "$input_end")     || exit -1

d="$startdate"
while [ "$d" != "$enddate" ]; do 
  clever accesslogs --alias prod --after $d --before $(date -I -d "$bv d + 1 day") -F clf &gt; access-$d.out
  d=$(date -I -d "$d + 1 day")
done
</code></pre>
It's hard to visualize so much data if you don't have the proper tools. So I really invite you to try <a href="https://goaccess.io/">GoAccess</a>. Combine the script above and this command <code>goaccess access* -o report.html --log-format=COMMON --anonymize-ip</code>. You will get this neat, anonymized HTML report:
<figure><img src="https://cdn.clever-cloud.com/uploads/2021/08/goaccess.png" alt="Demonstrating the filter" />
<figcaption>Viusalize CLF logs with GoAccess</figcaption></figure>
There are of course lots of other tools you can use to visualize logs, like our latest <a href="https://www.clever.cloud/developers/addons/elastic/">Elastic add-on</a> for instance :) Or you can go straight into the metrics tab of your application or add-on and start playing with Warp10. This is actually what we use when you see the live map under the Overview tab of your application.

We hope you'll find this new feature practical and as always welcome your input to make this better. Happy coding!]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="access logs clever tools 1" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/access-logs-clever-tools-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p>Yes you read it right, you can now access your access logs. How you ask? With the latest release of Clever Tools. But before we see how it works, let me explain what access logs are.

<span id="more-2973"></span>

Access logs contain all incoming requests to a web server. They are available in different formats. One of the most common being CLF which stands for <a href="https://en.wikipedia.org/wiki/Common_Log_Format">Common Log Format</a>. Here's an example where you can find the IP of the client, date, HTTP verb, URL target, status code and size of the answer: <code>255.255.255.255 - - [06/Feb/2020:07:59:22 +0100] "GET /aget/to/your/beautiful/website -" 200 1453</code>
<h2 id="how-to-get-your-access-logs">How to get your access logs</h2>
To get your access logs you need to use <a href="https://github.com/CleverCloud/clever-tools/">clever-tools</a> and run this in a linked application:

<code>clever accesslogs</code>

You will get all the requests that came to this app in the last hour. This also work for most dedicated add-ons using <code>--addon</code> followed by the add-on id:

<code>clever accesslogs --addon addon_41c5a60f-11c6-442a-9803-f4604fe8638b</code>

You can also choose a date span using <code>--after</code> and <code>--before</code> like so:

<code>clever accesslogs --after 2020-03-27 --before 2020-03-29</code>

Any date you give must follow ISO 8601. You could for instance have a microsecond precision like this:

<code>clever accesslogs --after 2020-03-29T11:01:02.120000Z --before 2020-03-29T11:01:02.123456Z</code>

You can also change the format of the logs with <code>-F</code> (or <code>--format</code>):

<code>clever accesslogs --after 2020-03-28 --before 2020-03-29 -F json</code>

Here's an example of JSON entry, it contains all of the information currently available for each request:
<pre><code class="language-json">{
  "t": "2020-03-10T11:24:34.220324Z",
  "a": "app_87d748d4-3c7b-4baa-8f52-c748e1123ab3",
  "adc": "par-cleverapps-adc-n6",
  "o": "user_51f7098f-604e-4d9e-8fb6-4026fd1767bb",
  "i": "0805330e-cff6-4fd5-87c0-26974d8bcb4e",
  "ipS": "255.255.255.255",
  "pS": 38566,
  "s": {
    "lt": 48.6719,
    "lg": 1.3002,
    "ct": "Aunay-sous-Crecy",
    "co": "FR"
  },
  "ipD": "255.258.258.258",
  "pD": 11810,
  "d": {
    "lt": 48.7967,
    "lg": 2.3338,
    "ct": "Cachan",
    "co": "FR"
  },
  "vb": "GET",
  "path": "/status-codes/500",
  "bIn": 411,
  "bOut": 443,
  "h": "app-87d748d4-3c7b-4baa-8f52-c748e1123ab3.cleverapps.io",
  "rTime": "3ms",
  "sTime": "115μs",
  "scheme": "HTTPS",
  "sC": 500,
  "sT": "Internal Server Error",
  "w": "WRK-01",
  "r": "b6bcab8a-c6d0-4546-9000-57b43d009a49",
  "tlsV": "TLS1.3"
}
</code></pre>
You will find the details for every field in our <a href="https://www.clever.cloud/developers/administrate/metrics/overview/#access-logs-metrics">access logs documentation</a>.
<h2 id="what-you-can-do-with-your-logs">What you can do with your logs</h2>
Now let's say you want to know what are the most returned status codes from a log file, here's how you can do it:
<pre><code class="language-bash">clever accesslogs --after 2020-03-10 --before 2020-03-20 -F json | jq .sC | sort | uniq -c | sort -nr
</code></pre>
Here we use the JSON format and <code>jq</code> to select the field we want, then <code>sort</code> and <code>uniq</code> to get a proper output, which would yield something like:
<pre><code class="language-text">  99999 200
     56 500
     33 404
      2 400
      1 403
      1 301
      1 202
</code></pre>
The first column being the number of hits and the second being the status code.

Now for something a bit more practical, here's a script that allows you to split access logs for each day between two dates:
<pre><code class="language-bash">#!/bin/bash

input_start=2020-01-01
input_end=2020-03-27

startdate=$(date -I -d "$input_start") || exit -1
enddate=$(date -I -d "$input_end")     || exit -1

d="$startdate"
while [ "$d" != "$enddate" ]; do 
  clever accesslogs --alias prod --after $d --before $(date -I -d "$bv d + 1 day") -F clf &gt; access-$d.out
  d=$(date -I -d "$d + 1 day")
done
</code></pre>
It's hard to visualize so much data if you don't have the proper tools. So I really invite you to try <a href="https://goaccess.io/">GoAccess</a>. Combine the script above and this command <code>goaccess access* -o report.html --log-format=COMMON --anonymize-ip</code>. You will get this neat, anonymized HTML report:
<figure><img src="https://cdn.clever-cloud.com/uploads/2021/08/goaccess.png" alt="Demonstrating the filter" />
<figcaption>Viusalize CLF logs with GoAccess</figcaption></figure>
There are of course lots of other tools you can use to visualize logs, like our latest <a href="https://www.clever.cloud/developers/addons/elastic/">Elastic add-on</a> for instance :) Or you can go straight into the metrics tab of your application or add-on and start playing with Warp10. This is actually what we use when you see the live map under the Overview tab of your application.

We hope you'll find this new feature practical and as always welcome your input to make this better. Happy coding!]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
