微服務異常太亂,我們?nèi)绾畏诸悾?/h2>

Elastic APM 是基于 Elastic Stack 構建的應用性能監(jiān)控系統(tǒng)。通過 Elastic APM 可以監(jiān)控應用程序,收集有關請求的響應時間、數(shù)據(jù)庫查詢、高速緩存調(diào)用、外部 HTTP 請求等的詳細性能信息,這樣可以更快地查明并修復性能問題。

Elastic APM 還會自動收集未處理的錯誤和異常,錯誤主要基于堆棧跟蹤進行分組,因此可以識別出現(xiàn)的新錯誤,并密切關注特定錯誤發(fā)生的次數(shù)。

Elastic APM

kibana

Kibana 是開源的分析和可視化平臺,旨在與 Elasticsearch 協(xié)同工作,可以通過 Kibana 搜索、查看 Elasticsearch 中存儲的數(shù)據(jù),此處用于可視化 Elasticsearch 中存儲的 APM 數(shù)據(jù)

目錄

mkdir /app
cd /app

下載

wget https://artifacts.elastic.co/downloads/kibana/kibana-6.5.4-linux-x86_64.tar.gz

解壓

tar -zxvf kibana-6.5.4-linux-x86_64.tar.gz 
cd kibana-6.5.4-linux-x86_64/

配置

vi config/kibana.yml

[root@JD kibana-6.5.4-linux-x86_64]# vi config/kibana.yml 
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://47.99.88.28:9200"

啟動

nohup ./bin/kibana &

訪問Kibana

image

APM監(jiān)控

image

搭建apm-server

APM Server 是用 Go 編寫的開源應用程序,通常運行在專用服務器上,默認監(jiān)聽端口 8200 ,并通過 JSON HTTP API 從 agent 接收數(shù)據(jù),然后根據(jù)該數(shù)據(jù)創(chuàng)建文檔并將其存儲在 Elasticsearch 中。

wget https://artifacts.elastic.co/downloads/apm-server/apm-server-6.5.4-linux-x86_64.tar.gz

配置文件

[root@demo03 apm-server-6.5.4-linux-x86_64]# vi apm-server.yml 
apm-server:
  # Defines the host and port the server is listening on.  use "unix:/path/to.sock" to listen on a unix domain socket.
  host: "0.0.0.0:8200"
  run:
    enabled: true
output.elasticsearch:
  # Array of hosts to connect to.
  # Scheme and port can be left out and will be set to the default (http and 9200)
  # In case you specify and additional path, the scheme is required: http://localhost:9200/path
  # IPv6 addresses should always be defined as: https://[2001:db8::1]:9200
  hosts: ["47.99.88.28:9200"]

  indices:
    - index: "apm-%{[beat.version]}-sourcemap"
      when.contains:
        processor.event: "sourcemap"

    - index: "apm-%{[beat.version]}-error-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "error"

    - index: "apm-%{[beat.version]}-transaction-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "transaction"

    - index: "apm-%{[beat.version]}-span-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "span"

    - index: "apm-%{[beat.version]}-metric-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "metric"

    - index: "apm-%{[beat.version]}-onboarding-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "onboarding"

啟動

nohup ./apm-server -e  >&/dev/null &

下載

cd app/agent
wget https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/1.4.0/elastic-apm-agent-1.4.0.jar

應用埋點APM agent

APM agent 是使用與服務相同的語言編寫的開源庫,可以像安裝其他庫一樣將它們安裝到服務中,agent 將檢測服務的代碼并在運行時收集性能數(shù)據(jù)和錯誤,這些數(shù)據(jù)緩沖一小段時間并發(fā)送到 APM server。

#!/bin/bash
cs=`echo ../lib/*jar | sed 's/ /:/g'`
export JAVA_OPTS='-javaagent:/app/agent/elastic-apm-agent-1.4.0.jar  -Delastic.apm.service_name=USER-CENTER -Delastic.apm.server_url=http://192.168.235.129:8200 -Delastic.apm.secret_token= -Delastic.apm.application_packages=com.open.capacity  -XX:+UseG1GC   -Xmx400M -Xms400M   -XX:MaxMetaspaceSize=128M   -XX:MetaspaceSize=128M      -XX:MaxGCPauseMillis=100 -XX:InitiatingHeapOccupancyPercent=45    -XX:+ParallelRefProcEnabled  -XX:MaxTenuringThreshold=3   -XX:+AlwaysPreTouch  -XX:+UseStringDeduplication -XX:StringDeduplicationAgeThreshold=3 -XX:-OmitStackTraceInFastThrow -Djava.security.egd=file:/dev/./urandom -verbose:gc  -XX:+PrintGCDetails   -XX:+PrintGCDateStamps  -XX:+PrintGCApplicationStoppedTime  -XX:+PrintGCApplicationConcurrentTime  -XX:+PrintTenuringDistribution -XX:+PrintClassHistogramBeforeFullGC  -XX:+PrintClassHistogramAfterFullGC -Xloggc:/tmp/logs/gc_%p.log  -XX:+HeapDumpOnOutOfMemoryError  -XX:HeapDumpPath=/tmp/logs   -XX:ErrorFile=/tmp/logs/hs_error_pid%p.log -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=2199 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false '

nohup java -server  $JAVA_OPTS  -cp  .:$cs  com.open.capacity.UserCenterApp   &>/dev/null  &   echo $! >pid&

#java -server  $JAVA_OPTS  -cp  .:$cs  com.open.capacity.UserCenterApp     &   echo $! >pid&

監(jiān)控大盤

image

SQL語句

SQL語句界面

錯誤列表

錯誤列表界面

錯誤統(tǒng)計

錯誤統(tǒng)計界面

dashboard

dashboard界面

service

service界面

來源OCP開源項目教程文檔:https://www.kancloud.cn/owenwangwen/open-capacity-platform/1801099

文末

文章收錄至
Github: https://github.com/CoderMerlin/coder-programming
Gitee: https://gitee.com/573059382/coder-programming
歡迎關注并star~

微信公眾號
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容