0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AKSのコンテナログをLogAnaliticsから検索

Last updated at Posted at 2020-02-18

AKSのモニタリングアドオン有効化(要LogAnaliticsのワークスペース)するとコンテナの標準出力が自動的にCotainerLogというテーブルに入って過去のいないPodのログも見られるけど、構造化されてないログをKustoでパースすると正規表現で頑張るしかなかったのでcsvかjsonでログを吐くようにLogFormatの設定変えたほうがいいんじゃないかと思いました。
ContainerInventoryテーブルとCotainerIDでjoinしたらImage名とれました。

ContainerLog
| where LogEntry !contains "kube-probe/1.1"
| join kind = inner
(
    ContainerInventory
)
on ContainerID
| extend HttpStatusCode = extract(" ([2-5][0-9]{2}) ", 1, LogEntry)
| extend Serverity1 = extract(" \\[([a-z]*)\\]", 1, LogEntry)
| extend Serverity2 = extract(" (DEBUG|TRACE|INFO|ERROR|WORNING) ", 1, LogEntry)
| project Image1, LogEntry, HttpStatusCode, Serverity1, Serverity2
//| where Image1 == "<my-image-name>"
//| limit 50

つかえるっぽい正規表現
https://github.com/google/re2/wiki/Syntax
関数
https://docs.microsoft.com/en-us/azure/kusto/query/extractfunction
パースマニュアル
https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/parse-text
SQL脳チートシート
https://docs.microsoft.com/ja-jp/azure/azure-monitor/log-query/sql-cheatsheet

あとomsagentはnamespace単位で出したり出さなかったりの制御はできるらしいconfigmapの設定方法をみた↓
https://docs.microsoft.com/ja-jp/azure/azure-monitor/insights/container-insights-agent-config
namespaceを制御するとかはできるけどそれ以外何か細かいフィルタしたい場合、出す側でなんかするか別のlogshipperで飛ばすという話になるのかなと思いました。
もしomsagentで収集したPrometheusのNodeデータをAzureLoganalyticsのInsightMetricsテーブルに入れたいという場合はNodeExporterを別途入れて、そのポート番号を設定ファイル側と合わせて設定をするとよい模様。メトリクスの取得間隔 (interval) や、収集するフィールドの設定 (fieldpass/fielddrop) は制御できる模様。

前月を出したい場合は、以下のような感じにすると2,4,6,9,11月もきっちり1か月分でます。

let now = now();
let requireMonth = datetime_add('month', -1, todatetime(now));
let startDate = startofmonth(requireMonth);
let endDate = endofmonth(requireMonth);
ContainerLog 
| where LogEntry !contains "kube-probe/1.15"
| where TimeGenerated between(startDate .. endDate)
...
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?