當前位置:網站首頁>elk筆記25--快速體驗APM
elk筆記25--快速體驗APM
2022-07-23 19:15:29【昕光xg】
1 介紹
Elastic APM是建立在Elastic Stack上的應用程序性能監控系統。它允許用戶通過收集關於傳入請求、數據庫查詢、緩存調用、外部HTTP請求等響應時間的詳細性能信息,從而實時監控軟件服務和應用程序。這使用戶定比特和修複性能問題變得非常容易。
Elastic APM還會自動收集未處理的錯誤和异常,這些錯誤主要基於堆棧跟踪進行分組,因此用戶可以在出現新錯誤時識別它們,並關注特定錯誤發生的次數。
在調試生產系統時,度量標准是另一個重要的信息來源。Elastic APM agent會自動獲取基本的主機級指標和特定的代理相關的指標,比如Java代理中的JVM指標和Go代理中的Go運行時指標。
Elastic APM 包含4個主要部分: APM agents, Elastic APM integration, Elasticsearch, and Kibana , 它們的主要工程架構包括如下兩種:
1) 邊緣機器上的APM agents 將數據發送到集中托管的APM集成是
2)APM agents和APM集成運行在邊緣機器上,並通過集中托管的Elastic agent 進行注册
以上為Elastic APM的主要功能和架構,在了解Elastic APM 主要功能後,本文將從基礎開安裝 APM server,並通過 python 案例加以展示。
2 安裝測試
2.1 安裝 APM server
docker pull docker.elastic.co/apm/apm-server:7.15.2
curl -L -O https://raw.githubusercontent.com/elastic/apm-server/7.15/apm-server.docker.yml
docker run -d \
-p 8200:8200 \
--name=apm-server-7.15.2 \
--user=apm-server \
--volume="/home/xg/soft/elk/apm-7.15.2/apm-server.docker.yml:/usr/share/apm-server/apm-server.yml:ro" \
docker.elastic.co/apm/apm-server:7.15.2 \
--strict.perms=false -e \
-E output.elasticsearch.hosts=["es_ip:9200"] -E output.elasticsearch.username="es_user" -E output.elasticsearch.password="es_pwd"
2.2 python測試用例
#!/usr/bin/python3
""" pip3 install elastic-apm[flask] """
import time
from flask import Flask
import requests
import json
from elasticapm.contrib.flask import ElasticAPM
app = Flask(__name__)
app.config['ELASTIC_APM'] = {
'SERVICE_NAME': 'xg-flask-01',
'SECRET_TOKEN': 'not-set',
'SERVER_URL': 'http://localhost:8200'
}
apm = ElasticAPM(app)
@app.route("/")
def hello_world():
ret_dict = {
"main": "/ , Hello. World",
"test_error": "/api/test-error",
"test_wait": "/api/test-wait",
"test_get": "/api/test-get"
}
return json.dumps(ret_dict)
@app.route("/api/test-error")
def test_error():
try:
print(10/0)
except Exception as e:
print(f"error: {
e}")
print(101 + "error")
return json.dumps({
'msg': "test-error"})
def my_wait(ts=1):
time.sleep(ts)
@app.route("/api/test-wait")
def test_wait():
ts = 5
print("wait")
my_wait(ts)
return json.dumps({
'msg': f"wait {
ts}s"})
@app.route("/api/test-get")
def test_get():
r = requests.get(url='http://www.baidu.com')
return json.dumps({
'msg': f"get www.baidu.com, status_code={
r.status_code}"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
2.3 kibana APM 展示信息
Services
Traces
Dependencies
Overview
Transactions
Dependencies
Errors
Metrics
3 注意事項
- 看APM官方文檔,發現Elastic 的 apm-server 支持將數據寫入到 kafka, 因此可以考慮使用其 apm-server 將數據寫入 kafka, 然後再進一步將數據導入到 clickhouse或者其它db, 最上層封裝自己的 APM 查詢前端,那麼就可以實現有個人特色的APM了.
優點: 可以直接使用 elastic 的 apm-server 和 agent 接入規範,我們只需要關注用戶查詢即可
缺點:需要自己實現 APM 的前端,可以參考 elastic 的 apm 功能
Configure the Kafka output
4 說明
測試環境:
elk 7.15.2
apm-server 7.15.2
參考文檔:
APM User Guide
Run APM Server on Docker
agent code example
版權聲明
本文為[昕光xg]所創,轉載請帶上原文鏈接,感謝
https://cht.chowdera.com/2022/204/202207231715484878.html
邊欄推薦
猜你喜歡
隨機推薦
- BGP機房的優點
- 真人踩過的坑,告訴你避免自動化測試常犯的10個錯誤
- 判斷是否為void類型
- C語言——幾道C語言經典習題
- openvino_datawhale
- C語言基礎知識梳理(一)
- Redis源碼與設計剖析 -- 7.快速列錶
- 比特,比特,字節,字的概念與區別
- 項目部署(簡版)
- JDBC的學習以及簡單封裝
- [pytho-flask筆記5]藍圖簡單使用
- Web Component-自定義元素的生命周期
- 數倉4.0筆記——業務數據采集
- 數倉4.0筆記——用戶行為數據采集四
- 對.h5文件的迭代顯示,h5py數據操作
- 常用數學知識匯總
- “東數西算”下數據中心的液冷GPU服務器如何發展?
- 硬件知識1--原理圖和接口類型(基於百問網硬件操作大全視頻教程)
- 鋼結構基本原理複習
- Unity3d:UGUI源碼,Rebuild優化
- 快速解决:Xshell拖不進去文件夾或者軟件包的問題
- RHCSA--文件內容瀏覽、cut、uniq、sort、.tr命令使用
- 信號完整性(SI)電源完整性(PI)學習筆記(三十二)電源分配網路(四)
- EasyGBS平臺出現錄像無法播放並存在RTMP重複推流現象,是什麼原因?
- 第七天筆記
- 【可視化調度軟件】上海道寧為SMB組織帶來NETRONIC下載、試用、教程
- 概率沉思錄:2.The quantitative rules
- 常用的鼠標事件和鍵盤事件
- C#:in、out、ref關鍵字
- GRE,MGRE的詳細了解;OSPF基礎配置知識
- Creo 9.0 如何快速修改CAD坐標系?
- 第五天筆記
- 强化學習——策略梯度理解點
- shell跑的時候需要的需要了解命令
- OKRK3399開發板預留I2C4掛載EEPROM
- 優化華為雲服務器采用Key登陸
- 第2章 基礎查詢與排序
- 【C語言】猜數字小遊戲+關機小程序
- 什麼是Per-Title編碼?
- @FeignClient使用詳細教程(圖解)