Using elk stack for monitoring docker swarm service

Containerで動くのシステムを構築する案件に参加しまして、
経験がなかったので、調査しながら開発を進めていきました。
色々新技術を勉強できまして楽しかった!!!

担当したモジュールは コンテナ・システム全体を監視 / Monitoring機能を展開するのです。
忘れないうちに、自分用のメモを残したいと思います。

ELK Stackってなんのものだ?

ELK StackはみつのOpenSourceを組み合わせて
ログ収集(アプリケーションログ, システムログなど)・分析・可視化のを提供されます。

  • Elasticsearch
  • Logstash
  • Kibana

ELK

構成

ELKの構成は以下のように構成されています。

  1. ログ集めてlogstashに転送する. ELK Stackなら Beatと呼ばれる
  2. logstashで待ち受けて、データ加工・解析
  3. elasticsearchデータベースに書き出す
  4. Kibanaでelasticsearchのデータをベースに可視化できる

ELK

システム構成

On-premisesにDocker swarm の利用でシステムを構築する
Masterノード: 1台
Workノード: 3〜4台
コンテナ合計: 6(ELK除く)

あったIssueと解決

開始する時に以下のような要件が出ました

  • コンテナとして動いてるため、コンテナ停止したらログが残さない
  • アプリケーションログを永久化にしたい
  • 特殊エラーなどの時に警告メールで通知
  • アクセス頻度、バッチ進捗などはvisualizeしたい

ソリューション:

調べながら開発進めました。
その時は ELK Stackがよく出てたので採用になります。

注意:(TBD)

あった問題:

おさらい
。。。(時間があるとき、もっと書きますように)

Show msg Unsupported browser

Issue

Internet Explorer 11 support deprecation and removal

According to announcement from angular, the IE 11 will be removed in the feature.

Is there any way for warning to user who uses IE to open your site?

Solution

the simple way to do that

  • check browser version when your site onload()
  • if it is unsupported browser version, -> close your site

Sourcecode example

Here is an example source.
Add it to your index.html file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script type="text/javascript">

/**
* Check Edge is Chromium version.
*/
function isChromium() {
let userAgentData = navigator['userAgentData'].brands || [];
for (let index = 0; index < userAgentData.length; index++) {
let brand_version_pair = userAgentData[index].brand;
if (brand_version_pair === 'Chromium') {
return true;
}
}
return false;
}

/**
* Check support browser
* Only support: Edge (Chromium) / chrome/ firefox
*/
function isSupportedBrower() {
let userAgent = navigator.userAgent;
if (userAgent.indexOf('Edg') != -1) {
// MS Edge
if (isChromium()) {
return true;
}
} else if (userAgent.indexOf('Chrome') != -1) {
// Google chrome
return true;
} else if (userAgent.indexOf('Firefox') != -1) {
// Firefox
return true;
} else {
return false;
}
}

const confirmBrowserMsg =
'\n(Website cannot be used with your web browser.' +
'\nPlease use one of the below latest browsers)' +
'\n・Firefox' +
'\n・Google Chrome' +
'\n・MS Edge (Chromium)';

window.addEventListener('load', function () {
if (!isSupportedBrower()) {
// Check browser
let r = confirm(confirmBrowserMsg);
if (r) {
// Close current tab
setTimeout(window.close(), 100);
} else {
// to continue loading
}
}
});
</script>