Elastic APM 是基于 Elastic Stack 構(gòu)建的應(yīng)用性能監(jiān)控系統(tǒng)炎功。通過 Elastic APM 可以監(jiān)控應(yīng)用程序虎囚,收集有關(guān)請求的響應(yīng)時間邻寿、數(shù)據(jù)庫查詢伯复、高速緩存調(diào)用搞莺、外部 HTTP 請求等的詳細(xì)性能信息,這樣可以更快地查明并修復(fù)性能問題疚鲤。
Elastic APM 還會自動收集未處理的錯誤和異常锥累,錯誤主要基于堆棧跟蹤進行分組,因此可以識別出現(xiàn)的新錯誤集歇,并密切關(guān)注特定錯誤發(fā)生的次數(shù)桶略。
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
APM監(jiān)控
搭建apm-server
APM Server 是用 Go 編寫的開源應(yīng)用程序焕窝,通常運行在專用服務(wù)器上蹬挺,默認(rèn)監(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
應(yīng)用埋點APM agent
APM agent 是使用與服務(wù)相同的語言編寫的開源庫,可以像安裝其他庫一樣將它們安裝到服務(wù)中虐秋,agent 將檢測服務(wù)的代碼并在運行時收集性能數(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)控大盤
SQL語句
錯誤列表
錯誤統(tǒng)計
dashboard
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
歡迎關(guān)注并star~