sumologicのCloudFrontダッシュボードがどのようなクエリで構成されているかを解説してみました(Overview)

sumologicのCloudFrontダッシュボードがどのようなクエリによって構成されているかを解説してみました。
2018.10.16

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

sumologicのCloudFrontダッシュボードがどのようなクエリで構成されているかを解説してみました

はじめに

sumologicには、Setup Wizardが用意されており簡単な手順でログの収集〜ダッシュボード化ができます。

Sumo LogicでCloudFrontをウォッチしてみた

デフォルトのCloudFront用のダッシュボードのOverviewがどのようなクエリによって作成されているかを解説していきます。

解説

Glient Geo Distribution

概要

アクセス元のIPアドレスを元に場所を割り出し地図上に表すパネルです。

クエリ

_sourceCategory=aws/cloudfront
| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,time,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid
| lookup latitude, longitude, country_code, country_name, region, city, postal_code from geo://location on ip = c_ip
| count by latitude, longitude, country_code, country_name, region, city, postal_code
_sourceCategory=aws/cloudfront

クエリ対象として、aws/cloudfrontというsumologicに収集されたData Collectionを指定しています。

| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,time,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid

CloudFrontのアクセスログは下記のフォーマットで出力されます。
アクセスログの設定および使用 - Amazon CloudFront

parseコマンドはログをパースし、sumologic上で使用するための識別名を設定します。
c_ip(アクセス元IPアドレス)を取り出すのが主な目的です。

| lookup latitude, longitude, country_code, country_name, region, city, postal_code from geo://location on ip = c_ip

アクセス元IPアドレスからGeoIPで国名や緯度経度などを割り出します。

| count by latitude, longitude, country_code, country_name, region, city, postal_code

countは指定したフィールドが一致する要素をカウントしてくれます。

latitude, longitude, countがあれば、sumologicではマップ上のcountの値を表示させる事が可能です。

Visitor Access Platforms

概要

アクセス元のプラットフォームを円グラフで表示するパネルです。

クエリ

_sourceCategory=aws/cloudfront 
| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,time,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid 
| urldecode(user_agent) as agent
| if (agent matches "*iPad*" OR agent matches "*iPhone*" OR agent matches "*BlackBerry*" OR agent matches "*Galaxy*" OR agent matches "LGE-*" OR agent matches "SCH-*" OR agent matches "*HUAWEI-*" OR agent matches "*SAMSUNG*" OR agent matches "*samsung*" OR agent matches "Dalvik/*" OR agent matches "Nokia*" OR agent matches "LG-*" OR agent matches "*CFNetwork*"  OR agent matches "*UP.Browser/*" OR agent matches "*QQ*rowser*" OR agent matches "*NetFront/*" OR agent matches "*Windows Phone*" OR agent matches "*iemobile*","mobile","") as type
| if (agent matches "*Windows NT*" OR agent matches "*i686*" OR agent matches "*x86*","PC",type) as type
| if (agent matches "*Macintosh*","Mac",type) as type
| if (type = "","unknown",type) as type
| count type
| urldecode(user_agent) as agent

URLデコードを行う

| if (agent matches "*iPad*" OR agent matches "*iPhone*" OR agent matches "*BlackBerry*" OR agent matches "*Galaxy*" OR agent matches "LGE-*" OR agent matches "SCH-*" OR agent matches "*HUAWEI-*" OR agent matches "*SAMSUNG*" OR agent matches "*samsung*" OR agent matches "Dalvik/*" OR agent matches "Nokia*" OR agent matches "LG-*" OR agent matches "*CFNetwork*"  OR agent matches "*UP.Browser/*" OR agent matches "*QQ*rowser*" OR agent matches "*NetFront/*" OR agent matches "*Windows Phone*" OR agent matches "*iemobile*","mobile","") as type
| if (agent matches "*Windows NT*" OR agent matches "*i686*" OR agent matches "*x86*","PC",type) as type
| if (agent matches "*Macintosh*","Mac",type) as type
| if (type = "","unknown",type) as type

agentフィールドを確認して、一致するなら mobile, PC, Macをtypeフィールドに記載する。
最後にtypeフィールドが空なら unknown を記載する。

| count type

タイプ毎に集計し、typeと個数のテーブルを返します。

Requests Served by Edge Location

どのEdge経由でアクセスされたかを円グラフで表示するパネルです。

クエリ

_sourceCategory=aws/cloudfront 
| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,time,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid
| count by edgeloc
| sort by _count

CloudFrontのログに元々どのEdge経由か情報が含まれているのでそれを count しています。

Cache Hit and Miss

リクエストがキャッシュにヒットしたかどうかを円グラフで表示するパネルです。

_sourceCategory=aws/cloudfront ("hit" or "miss" or "RefreshHit")
| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,time,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid
| count by edgeresult
_sourceCategory=aws/cloudfront ("hit" or "miss" or "RefreshHit")

クエリ対象として、aws/cloudfrontというsumologicに収集されたData Collectionを指定しています。
hit, miss, RefreshHit という文字列を含むログのみを対象にフィルタします。

Requests Served by Edge Location と同様にキャッシュにヒットしたかの情報がログに含まれているのでそれを count しています。

HTTP Status Codes Over Time

応答したHTTPステータスコードの件数が棒グラフで確認できるパネルです。
エラーが多発しているなどといった状況の確認に役立ちます。

_sourceCategory=aws/cloudfront
| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,_ftime,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid 
| count as count by status
| sort by count
| count as count by status

ステータスコード毎にカウントします。

これも他は説明済みのコマンドしか使っていませんね。

Number of Unique Visitors

アクセス元IPアドレスを使用して、何ユーザーがアクセスしたか表示してくれるパネルです。
この期間は何人ぐらいアクセスしているか、おおよそですが確認できます。

クエリ

_sourceCategory=aws/cloudfront
| parse "*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*" as _filedate,time,edgeloc, scbytes, c_ip,method,cs_host,uri_stem,status,referer,user_agent,uri_query,cookie,edgeresult,requestid 
| count_distinct(c_ip) as UniqueVisitors
| count_distinct(c_ip) as UniqueVisitors

アクセス元IPアドレスが何種類あるかを集計します。
100より大きい値を返す時は誤差が発生する使用です。

あとがき

機能的なダッシュボードですが、1つ1つのクエリを見てみると簡単なもので構成されていますね。
後半はほとんど説明する必要がないなーという感じでした、とても良いことです!
また、望む形があるけど、どうクエリを書けば良いかまるで想像がつかない!という方はまず、下記のチートシートを見てみることをオススメします。
Search Cheat Sheets - Sumo Logic