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.envasSENTRY_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. ...
随机推荐
- dedecms中调用隐藏栏目的方法
第一种情况用SQL标签如下: {dede:sql sql='Select * from dme_arctype where ishidden=1 and topid=2'} <span clas ...
- hustoj 管理员和后台设置
之前用过hustoj 的livecd版本,觉得有一些小问题,所以从头到尾搭建.主要包含的过程包括: 安装ubuntu系统 搭建hustoj 管理员和后台资源建设 本文介绍如何在搭建好hustoj的基础 ...
- 7.2 C++模板类实例化
参考:http://www.weixueyuan.net/view/6399.html 总结: array < int >表明用int类型来代替模板类中的类参数“T”,编译器会将模板类ar ...
- 安装gcc
yum -y install gcc yum -y install gcc-c++ yum install make -- 或者 yum groupinstall "Developmen ...
- Oracle存储过程基础
http://blog.sina.com.cn/s/blog_67e424340100iyg1.html
- jquery转换json对象为字符串
jquery转换json对象为字符串 JSON.stringify(jsonObject),可用于单个JSON对象,也可用于JSON数组 alert(JSON.stringify(jsonObject ...
- SpringBoot(2.0.4.RELEASE)+Elasticsearch(6.2.4)+Gradle简单整合
记录一下SpringBoot(2.0.4.RELEASE)+Elasticsearch(6.2.4)+Gradle整合的一个小例子. 1.在Gradle内加入相关jar包的依赖: compile('o ...
- JAVA数组与List相互转换
1.数组转成List 数组转成List可以用方法 :Arrays.asList,一起来了解一下 System.out.println(Arrays.asList(new String[] { &quo ...
- 学习Java JDBC,看这篇就够了
JDBC (Java DB Connection)---Java数据库连接 JDBC是一种可用于运行SQL语句的JAVA API(ApplicationProgramming Interface应用程 ...
- c++将数字转换成固定长度的字符串
c++将数字转换成固定长度的字符串 将数字转换为字符串,且设置为固定长度的,不足补零. string num2str(int i) { ]; sprintf(ss,"%04d",i ...