openresty 集成 sentry 异常系统
sentry 是一个方便的错误异常追踪系统,同时社区也提供了openresty 的lua 包,使用docker-compose 进行测试
备注: sentry 部分的配置来自官方文档
环境准备
- docker-compose 文件
# NOTE: This docker-compose.yml is meant to be just an example of how
# you could accomplish this on your own. It is not intended to work in
# all use-cases and must be adapted to fit your needs. This is merely
# a guideline.
# See docs.getsentry.com/on-premise/server/ for full
# instructions
version: '3.4'
x-defaults: &defaults
restart: unless-stopped
build: .
depends_on:
- redis
- postgres
- memcached
- smtp
env_file: .env
environment:
SENTRY_MEMCACHED_HOST: memcached
SENTRY_REDIS_HOST: redis
SENTRY_POSTGRES_HOST: postgres
SENTRY_EMAIL_HOST: smtp
volumes:
- sentry-data:/var/lib/sentry/files
services:
smtp:
restart: unless-stopped
image: tianon/exim4
memcached:
restart: unless-stopped
image: memcached:1.5-alpine
redis:
restart: unless-stopped
image: redis:3.2-alpine
postgres:
restart: unless-stopped
image: postgres:9.5
ports:
- "5432:5432"
volumes:
- sentry-postgres:/var/lib/postgresql/data
web:
<<: *defaults
ports:
- '9000:9000'
openresty:
build:
context: ./
dockerfile: ./Dockerfile-nginx
ports:
- "8080:80"
volumes:
- "./nginx_lua/:/opt/app/"
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
cron:
<<: *defaults
command: run cron
worker:
<<: *defaults
command: run worker
volumes:
sentry-data:
external: true
sentry-postgres:
external: true
- openresty 配置
nginx.conf
worker_processes 1;
user root;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
lua_code_cache off;
lua_need_request_body on;
gzip on;
resolver 127.0.0.11 ipv6=off;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
lua_package_path '/opt/app/?.lua;;';
server {
listen 80;
server_name localhost;
charset utf-8;
default_type text/html;
location / {
default_type text/plain;
content_by_lua_block {
require("sentry/init")()
}
}
location = /favicon.ico {
root /opt/app/static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
dockerfile 配置
主要是添加了raven 包
FROM openresty/openresty:alpine-fat
LABEL author="1141591465@qq.com"
RUN /usr/local/openresty/luajit/bin/luarocks install resty-raven
EXPOSE 80
调用代码
主要来自github 文档,同时这个是一个简单的测试,注意lua 包的问题,当前测试支持的只是旧版本的dsn 方式
新版本的运行有问题
nginx_lua/sentry/init.lua
local raven = require "raven"
function init()
-- http://pub:secret@127.0.0.1:8080/sentry/proj-id
local rvn = raven:new("http://092b2e429b4c480e83c2e7f18890b8f2:e41f2a264e5e47329d0026e99ae825b1@web:9000/2", {
tags = { foo = "bar" },
})
-- Send a message to sentry
local id, err = rvn:captureMessage(
"Sentry is a realtime event logging and aggregation platform.",
{ tags = { abc = "def" } } -- optional
)
if not id then
print(err)
end
-- Send an exception to sentry
local exception = {{
["type"]= "SyntaxError",
["value"]= "Wattttt!",
["module"]= "__builtins__"
}}
local id, err = rvn:captureException(
exception,
{ tags = { abc = "def" } } -- optional
)
if not id then
print(err)
end
-- Catch an exception and send it to sentry
function bad_func(n)
return not_defined_func(n)
end
-- variable 'ok' should be false, and an exception will be sent to sentry
local ok = rvn:call(bad_func, 1)
end
return init
环境启动
主要是sentry的启动,因为sentry 启动稍有点费事,依赖数据库以及key 的生成,基本流程如下:
- sentry 启动
来自官方文档,就懒得翻译了
docker volume create --name=sentry-data && docker volume create --name=sentry-postgres
- Make our local database and sentry volumes
Docker volumes have to be created manually, as they are declared as external to be more durable.cp -n .env.example .env
- create env config filedocker-compose build
- Build and tag the Docker servicesdocker-compose run --rm web config generate-secret-key
- Generate a secret key.
Add it to.env
asSENTRY_SECRET_KEY
.docker-compose run --rm web upgrade
- Build the database.
Use the interactive prompts to create a user account.docker-compose up -d
- Lift all services (detached/background mode).- Access your instance at
localhost:9000
!
- openresty 启动
在启动sentry 的时候openresty 对应的镜像以及以及依赖的raven 已经同时处理了,基本可以不用管了
测试效果
- sentry 日志效果
说明
当前lua raven 支持的dsn 版本有点老,新版本的有问题,但是总的来说还是很不错的,在实际openresty 项目的开发中,可以作为一个
可选的问题分析方案,同时sentry 的功能还是很强大的,我们可以继承git 以及问题管理系统
参考资料
https://github.com/rongfengliang/openresty-sentry-docker-compose
https://github.com/UseFedora/raven-lua
https://github.com/getsentry/onpremise
openresty 集成 sentry 异常系统的更多相关文章
- .net core 集成 sentry 进行异常报警
.net core 集成 sentry 进行异常报警 Intro Sentry 是一个实时事件日志记录和汇集的平台.其专注于错误监控以及提取一切事后处理所需信息而不依赖于麻烦的用户反馈.它分为客户端和 ...
- hive集成sentry
1.安装配置sentry 详细步骤见上一篇安装配置sentry 2.配置hive 2.1 Hive-server2集成Sentry 在 /etc/hive/conf/hive-site.xml中添加: ...
- 【flask】项目集成Sentry收集线上错误日志
flask集成sentry分为4个步骤: 首先在sentry官网注册1个账号 然后创建1个新的项目,这里我选择的是flask,这会得到一些关于sdk的使用说明 接下来创建一个简单的flask项目使用s ...
- 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦
听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何? 上周奥威公开 ...
- 支付宝sdk集成,报系统繁忙 请稍后再试(ALI64)
移动快捷支付,往往需要集成支付宝的sdk,集成的过程相对简单,只要按照支付宝的文档,进行操作一般不会出问题. 下面主要说明一下,集成sdk后报"系统繁忙 请稍后再试(A ...
- CloudStack 4.2 新功能:集成SNMP进行系统监控(原理篇)
作者微博:http://weibo.com/tianchunfeng CloudStack 4.2 版本发布在即,相信不久后对 4.2 版本新功能(共有13个)的介绍会逐渐多起来.因为无论是从架构底层 ...
- FineReport集成到AWS系统中的方案
本人实施了北京炎黄盈动的BPM及OA系统,主要目标是对业务流程进行控制和管理,加快Oracle JDE的业务前端录单速度和弥补JDE在流程控制方面的不足,实现BPM数据能与JDE无缝互相结合,经过3个 ...
- hive集成sentry的sql使用语法
Sentry权限控制通过Beeline(Hiveserver2 SQL 命令行接口)输入Grant 和 Revoke语句来配置.语法跟现在的一些主流的关系数据库很相似.需要注意的是:当sentry服务 ...
- impala集成sentry
1.安装配置sentry 详细步骤见上一篇安装配置sentry. 2.配置impala 注:以下配置未集成kerberos安全认证 在/etc/imapla/conf目录下创建sentry-site. ...
随机推荐
- 十. Python基础(10)--装饰器
十. Python基础(10)--装饰器 1 ● 装饰器 A decorator is a function that take a function as an argument and retur ...
- core1.1 升级到 2.0
1.直接修改项目 1.1 改成 2.0 Startup 的修改 去除构造函数中下面的代码 var builder = new ConfigurationBuilder() .SetBasePath(e ...
- 安装google 框架
使用 root exporer很方便 su cp /sdcard/google/busybox /data/local/tmp chmod 0755 /data/local/tmp/busybo ...
- Domination(概率DP)
Domination 题目链接:https://odzkskevi.qnssl.com/9713ae1d3ff2cc043442f25e9a86814c?v=1531624384 Edward is ...
- 禁止textarea拉伸
添加css属性: style="resize:none" ;
- loader 的理解
[ webpack3.0.0刚刚出来 所以文章是跟着低版本 教程 操作熟悉 结果好多对不上喔] 四:理解less-loader加载器的使用 我们先来理解下less-loader加载器,其他的sas ...
- <Spark><Programming><Key/Value Pairs><RDD>
Working with key/value Pairs Motivation Pair RDDs are a useful building block in many programs, as t ...
- python Django rest-framework 创建序列化工程步骤
11创建项目 2创建应用 3stting添加应用(apps)-添加制定数据库-修改显示汉字(zh-hans)-上海时区(Asia/Shanghai) 4主路由添加子路由 5应用里创建子路由 6创建数据 ...
- winform 子窗体调用父窗体中的方法
在父窗体里定义委托 public delegate void inis(string str); 在父窗体中定义要调用的方法 public void inigs(string gs) { textBo ...
- 小白学习Python遇到的一些2.7与3.X之间的不同问题
1.输入字母出错问题 原本跟着视频一起学习,currency_str_value=input(‘请输入带单位货币金额’) 但是运行的时候,输入数字就没有问题,只要带上了字母就会报错,后来百度,pyth ...