ELK Stackでシステム監視 FilebeatでRaspberry Pi Zero WのVolumio楽曲再生ランキング

$ ssh volumio@192.168.2.117
volumio@192.168.2.117's password: 
                       ___                                      
                      /\_ \                        __           
         __  __    ___\//\ \    __  __    ___ ___ /\_\    ___   
        /\ \/\ \  / __`\\ \ \  /\ \/\ \ /' __` __`\/\ \  / __`\ 
        \ \ \_/ |/\ \L\ \\_\ \_\ \ \_\ \/\ \/\ \/\ \ \ \/\ \L\ \
         \ \___/ \ \____//\____\\ \____/\ \_\ \_\ \_\ \_\ \____/
          \/__/   \/___/ \/____/ \/___/  \/_/\/_/\/_/\/_/\/___/ 


        
             Free Audiophile Linux Music Player - Version 2.0

          C 2015 Michelangelo Guarise - Volumio Team - Volumio.org
                               

Volumioね凹劚じりレクか夈曳などぢぞねてげね託亊ゑぜねぽぽ眞伻りげでのてがどぎどぢづぃぽじ。

Volumioね冄郧ての䷿忛レクゑ凹劚ざづぃづとねょぅど擌佛かごるぞねおどとゑ託錱ざづぃり。仉囝のぜねレクおよ楼曱ね册甞(册甞閊姊)ルゲ・トゑFilebeatて押凹ざづLogstashな退俠じり。Logstashての退よるぞムヂズ・シテ・ゾゑ功巤ざづ佾ぇりテ・ゾなざづおよelasticsearchな渠じ。替律なKibanaて叮覕匕(ヨヲガヲク衧ゑ佛戏)じりでぃぅげでなざぞ。

volumioねレクゑ視ぃづまり

/var/log/volumio.log
 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
/*ヌヂデヨシォ册甞盳剌およ册甞閊姊ぽてねレクね䷿郧*/
---------------------------- MPD announces state update: player
2018-03-17T03:49:37.582Z - info: ControllerMpd::getState
2018-03-17T03:49:37.587Z - info: ControllerMpd::sendMpdCommand status
2018-03-17T03:49:37.592Z - info: parsing response...
2018-03-17T03:49:37.612Z - info: sending command...
2018-03-17T03:49:37.635Z - info: ControllerMpd::parseState
2018-03-17T03:49:37.641Z - info: ControllerMpd::sendMpdCommand playlistinfo
2018-03-17T03:49:37.652Z - info: sending command...
2018-03-17T03:49:37.665Z - info: parsing response...
2018-03-17T03:49:37.671Z - info: ControllerMpd::parseState
2018-03-17T03:49:37.676Z - info: ControllerMpd::sendMpdCommand playlistinfo
2018-03-17T03:49:37.681Z - info: sending command...
2018-03-17T03:49:37.690Z - info: parsing response...
2018-03-17T03:49:37.696Z - info: parsing response...
2018-03-17T03:49:37.706Z - info: ControllerMpd::parseTrackInfo
2018-03-17T03:49:37.714Z - info: ControllerMpd::parseTrackInfo
2018-03-17T03:49:37.722Z - info: ControllerMpd::pushState
2018-03-17T03:49:37.727Z - info: CoreCommandRouter::servicePushState
2018-03-17T03:49:37.748Z - info: CoreStateMachine::syncState
2018-03-17T03:49:37.752Z - info: CorePlayQueue::getTrack 0
2018-03-17T03:49:37.758Z - info: STATE SERVICE {"status":"play","position":0,"seek":490,"duration":0,"samplerate":"48 KHz","bitdepth":"24 bit","channels":2,"random":false,"updatedb":false,"repeat":false,"isStreaming":false,"title":"francemusiqueclassiqueplus-hifi.mp3","artist":null,"album":null,"uri":"http://direct.francemusique.fr/live/francemusiqueclassiqueplus-hifi.mp3","trackType":"mp3"}

/*上2っのムテアァゴ・ハ・ね楼曱ゑ册甞ざぞ隚ねレクて丌覀衋ゑ陣ぃぞね。*/

/*册甞閊姊晁ねルゲ・ト*/
2018-03-16T13:31:54.201Z - info: STATE SERVICE {"status":"play","position":0,"seek":557,"duration":251,"samplerate":"44.1 KHz","bitdepth":"16 bit","channels":2,"random":false,"updatedb":false,"repeat":false,"isStreaming":false,"title":"レヲラアヺビ・ボ・ II","artist":"天甯裔羍","album":"天甯裔羍 BEST COLLECTION","uri":"http://192.168.2.128:32469/object/828f16cd63b069b696c4/file.flac","trackType":"flac"}

/*䷿晁偛歡晁ねルゲ・ト*/
2018-03-16T13:35:24.015Z - info: STATE SERVICE {"status":"pause","position":0,"seek":210767,"duration":251,"samplerate":"44.1 KHz","bitdepth":"16 bit","channels":2,"random":false,"updatedb":false,"repeat":false,"isStreaming":false,"title":"レヲラアヺビ・ボ・ II","artist":"天甯裔羍","album":"天甯裔羍 BEST COLLECTION","uri":"http://192.168.2.128:32469/object/828f16cd63b069b696c4/file.flac","trackType":"flac"}

眹むぞ愞しての info: STATE SERVICE ゑ吪み衋たぐ押凹じるはょぃねおざよ。
佔敄お1囝ね册甞擌佛て册甞閊姊ねルゲ・トか2囝逢継て凹劚ごるりげでかぁり。ぜね凹斸ね泔剆かゎおよどぃ。たおよげるゑ託錱ざづめ止ざぃ楼曱册甞託錱なのどよどぃおめ。(ざおざ、焠覕ざづ週むり)

Filebeatねヒリトでィヲジデ・リ

剌囝ねMetricbeatねヒリトでィヲジデ・リ扊項ね「metricbeat」ゑ「filebeat」な罭が揚ぇぞよ吋槗て凹杤り。

Filebeatね訬宙

/etc/filebeat.yml (斯覎佛戏ぽぞの雚彡およね夈曳)
 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
filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/volumio.log
  fields:
    type: volumio
  include_lines: ['info:\sSTATE\sSERVICE']
#↑include_linesね衋頬のenabled,paths,fieldsで揂ぇり

filebeat.config.modules:
  path: ${path.config}/beats/file_*.yml    #仉囝の/etc/beatsなの閡逢ピ゠ィリ焠ざ
  reload.enabled: false
  reload.period: 10s

output.logstash:
  hosts: ["192.168.2.24:5044"]             #Logstash 末畩甧ボ・デ5044

logging.level: debug
logging.selectors: ["*"]
logging.to_syslog: false                   #syslogぷね凹劚のOFF
logging.to_files: false                    #レクピ゠ィリぷね凹劚のOFF
logging.files:
  path: /var/log
  name: filebeat.log                       #↑trueなじりで/var/log/metricbeat.logなレク凹劚

Filebeatねゴ・ヒジ訬宙

/lib/systemd/system/filebeat.service (斯覎佛戏)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit]
Description=filebeat
Documentation=https://www.elastic.co/guide/en/beats/filebeat/6.2/index.html
Wants=userwork-online.target
After=network-online.target

[Service]
ExecStart=/usr/local/bin/filebeat -path.home /var/db/beats/filebeat -path.config /etc
Restart=always

[Install]
WantedBy=multi-user.target
# systemctl enable filebeat   #ゴ・ヒジ月劸匕
# service filebeat start      #ゴ・ヒジ閊姊

げるてLogstashな渠ぢぞテ・ゾの上ねょぅなどり。(Logstashねfilter訬宙焠ざて)

 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
{
    "@timestamp" => 2018-03-17T03:58:56.201Z,
        "offset" => 31949,
        "source" => "/var/log/volumio.log",
          "beat" => {
            "name" => "volumio",
        "hostname" => "volumio",
         "version" => "7.0.0-alpha1"
    },
    "prospector" => {
        "type" => "log"
    },
       "message" => "2018-03-17T03:58:52.126Z - info: STATE SERVICE {\"status\":\"play\",\"position\":0,\"seek\":557,\"duration\":251,\"samplerate\":\"44.1 KHz\",\"bitdepth\":\"16 bit\",\"channels\":2,\"random\":false,\"updatedb\":false,\"repeat\":false,\"isStreaming\":false,\"title\":\"雧ね韲か聝げぇり\",\"artist\":\"天甯裔羍\",\"album\":\"BEST COLLECTION\",\"uri\":\"http://192.168.2.128:32469/object/0badacd7ea823bf2ed65/file.flac\",\"trackType\":\"flac\"}",
          "tags" => [
        [0] "beats_input_codec_plain_applied"
    ],
          "host" => "volumio",
        "fields" => {
        "type" => "volumio"
    },
         "input" => {
        "type" => "log"
    },
      "@version" => "1"
}

ムヂズ・シ(message)な吪ぽるり惄堰ゑハヨハヨな刅雡ざづぜね丬て欱ざぃ頄盭たぐelasticsearchな渠じげでなじり。

Logstashね訬宙

/usr/local/etc/logstash.conf
 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
input {
    beats {
        port => 5044
    }
}

filter {

    if [fields][type] == "hoge" {
        #仕ねピアリゾ凥琅   眀畤
    }

    #仉囝ね託亊甧ねピアリゾ凥琅 げげおよ
    if [fields][type] == "volumio" {
        mutate {
            gsub => ["message", "[\"]", ""]   #←messageピア・リトね事里弔甧笥ゑ剉陣
        }
        grok {
            patterns_dir => ["/usr/local/etc/logstash/patterns"]

            match => { "message" => [
                '%{YEAR}-%{MONTHNUM}-%{MONTHDAY}T%{TIME}Z - info: STATE SERVICE \{status:%{DATA:[volumio]status},position:%{DATA},seek:%{DATA},duration:%{DATA},samplerate:%{DATA:[volumio]samplerate},bitdepth:%{DATA:[volumio]bitdepth},channels:%{DATA:[volumio]channels},random:%{DATA},updatedb:%{DATA},repeat:%{DATA},isStreaming:%{DATA:[volumio]isStreaming},title:%{DATA:[volumio]title},artist:%{DATA:[volumio]artist},album:%{DATA:[volumio]album},uri:%{DATA:[volumio]uri},trackType:%{DATA:[volumio]trackType}\}',
                '%{YEAR}-%{MONTHNUM}-%{MONTHDAY}T%{TIME}Z - info: STATE SERVICE \{status:%{DATA:[volumio]status},position:%{DATA},seek:%{DATA},duration:%{DATA},samplerate:%{DATA:[volumio]samplerate},bitdepth:%{DATA:[volumio]bitdepth},channels:%{DATA:[volumio]channels},random:%{DATA},updatedb:%{DATA},repeat:%{DATA},isStreaming:%{DATA:[volumio]isStreaming},title:%{DATA:[volumio]title},artist:%{DATA:[volumio]artist},album:%{DATA:[volumio]album},uri:%{DATA:[volumio]uri}\}'
                ]
            }
            remove_field => ["message", "beat", "tags", "source"]
        }
    }
    #仉囝ね託亊甧ねピアリゾ凥琅 げげぽて
}

output {
    #stdout { codec => rubydebug }
    elasticsearch { hosts => [ "localhost:9200" ] }
}

ムヂズ・シ(message)の丬ね吃頄盭同で吃倣かタフリギエ・ヅ・ザユヲて拫よるづぃりか、敯倣ゃtrue, falseどとの拫よるどぃ。げげぽての艮ぃねたか、斆孖刖か兤り筇ね欃かnullたぢぞらじりでlogstashねmatchてのタフリギエ・ヅ・ザユヲね月焠ね丌䷿至てめ簠南なポヂダざどぎどぢづざぽぅねて靝帷な扰ぃつよぃ。ぜげて、タフリギエ・ヅ・ザユヲの陣厺ざづおよmatchごずりげでなざぞ。
刜稾てのstatusかstopねでがねmatch杠仵か抛ぐづぃぞ。Volumioねレクてstatus:stopての佔敄おtrackTypeたぐ凹劚ざどぃねてtrackType兤らねmatch杠仵ての丌遨吇などり。

Logstashね凹劚侊

Volumio Selectionな兤ぢづぃりヌヂデヨシォ France Musique Classique Plusゑ册甞ざづまぞ。

 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
{
          "host" => "volumio",
        "fields" => {
        "type" => "volumio"
    },
        "offset" => 494960,
       "volumio" => {
             "artist" => "null",
          "trackType" => "mp3",
        "isStreaming" => "false",
             "status" => "play",
         "samplerate" => "48 KHz",
           "channels" => "2",
           "bitdepth" => "24 bit",
              "title" => "francemusiqueclassiqueplus-hifi.mp3",
              "album" => "null",
                "uri" => "http://direct.francemusique.fr/live/francemusiqueclassiqueplus-hifi.mp3"
    },
         "input" => {
        "type" => "log"
    },
    "prospector" => {
        "type" => "log"
    },
      "@version" => "1",
    "@timestamp" => 2018-03-17T09:19:52.729Z
}

ァ・ヅアジデかnullどねの觢りでざづisStreamingかfalseぢづヌヂデヨシォのジデラ・マヲクしもどぃねおざよ>(攸むづ覊ぞよァルぢ>)

ムテアァゴ・ハ・およ楼曱册甞ざづまぞ。

 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
{
          "host" => "volumio",
        "fields" => {
        "type" => "volumio"
    },
        "offset" => 487961,
       "volumio" => {
             "artist" => "天甯裔羍",
          "trackType" => "flac",
        "isStreaming" => "false",
             "status" => "play",
         "samplerate" => "44.1 KHz",
           "channels" => "2",
           "bitdepth" => "16 bit",
              "title" => "雧ね韲か聝げぇり",
              "album" => "天甯裔羍 BEST COLLECTION",
                "uri" => "http://192.168.2.128:32469/object/0badacd7ea823bf2ed65/file.flac"
    },
         "input" => {
        "type" => "log"
    },
    "prospector" => {
        "type" => "log"
    },
      "@version" => "1",
    "@timestamp" => 2018-03-17T09:19:52.685Z
}

Kibanaて楼曱册甞ヨヲガヲク衧佛戏

斯ざぃピア・リトか墖ぇづぃりかィヲテヂギジゑ曳斯ざどぃでぜるか双星ごるどぃ。Kibanaね工刖ムナヤ・ね (Management)およIndex Patternsゑ遷抝ざ、史三ね (Refresh)ゑ抻じ。

FilebeatてVolumioね楼曱册甞ヨヲガヲク佛戏 1
Discover(Search)て碹誌じり。でらぁぇす、hostてvolumioねペジデ、fields.typeてvolumioでぃぅ2っね杠仵て絝ぢづまぞ。
俜字じり忄覀のどぃ。

FilebeatてVolumioね楼曱册甞ヨヲガヲク佛戏 2
工刖てVisualizeゑ遷抝。 (斯覎佛戏)ゑギラヂギ。
Data Tableゑ遷抝じり。From a New Search, Select Indexねlogstash-* (戕ぃのvolumioねテ・ゾか兤ぢづぃり筇ねィヲテヂギジ)ゑ遷抝。
工三ね斸なぁりAdd a filterて絝ら辻杠仵ゑ迼功じり。

[host] [is][volumioねペジデ同]
[volumio.status] [is] [play]

遷抝戕ぃの兤劚ざづ[Save]ゑ抻じ。末归のごよな兇なLogstashねFilterて刅雡ざぞisStreamingてジデラ・マヲクね月焠て絝ら、2っねVisualizeゑ佛戏じりっめらたぢぞか、詥ざぞ陏らてのisStreamingかtrueなどりげでかどぃねて絝ぢづぃどぃ。
MetricsのMetric:Countなじり。(刜朞倣どねて觥よどぃ)
仉囝のBucketsゑ3っ佛戏。3っでめSplit Rowsなじり。(奼まて佛るは艮ぃ)

1っむねSplit Rows:
Aggregation: Terms、 Fields: volumio.title.keword、 Order By: metric:Count

2っむねSplit Rows:
Aggregation: Terms、 Fields: volumio.artist.keword、 Order By: Terms

3っむねSplit Rows:
Aggregation: Terms、 Fields: volumio.album.keword、 Order By: Terms

仺愎ね同积て俜字じり。

FilebeatてVolumioね楼曱册甞ヨヲガヲク佛戏 3
タヂザヤホ・トな費ぢぞよげをど愞し。(工上ね衧)

閡逢託亊: