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 启动
    来自官方文档,就懒得翻译了
  1. 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.
  2. cp -n .env.example .env - create env config file
  3. docker-compose build - Build and tag the Docker services
  4. docker-compose run --rm web config generate-secret-key - Generate a secret key.
    Add it to .env as SENTRY_SECRET_KEY.
  5. docker-compose run --rm web upgrade - Build the database.
    Use the interactive prompts to create a user account.
  6. docker-compose up -d - Lift all services (detached/background mode).
  7. Access your instance at localhost:9000!
  • openresty 启动
    在启动sentry 的时候openresty 对应的镜像以及以及依赖的raven 已经同时处理了,基本可以不用管了

测试效果

打开http://localhsot:8080 即可

  • 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 异常系统的更多相关文章

  1. .net core 集成 sentry 进行异常报警

    .net core 集成 sentry 进行异常报警 Intro Sentry 是一个实时事件日志记录和汇集的平台.其专注于错误监控以及提取一切事后处理所需信息而不依赖于麻烦的用户反馈.它分为客户端和 ...

  2. hive集成sentry

    1.安装配置sentry 详细步骤见上一篇安装配置sentry 2.配置hive 2.1 Hive-server2集成Sentry 在 /etc/hive/conf/hive-site.xml中添加: ...

  3. 【flask】项目集成Sentry收集线上错误日志

    flask集成sentry分为4个步骤: 首先在sentry官网注册1个账号 然后创建1个新的项目,这里我选择的是flask,这会得到一些关于sdk的使用说明 接下来创建一个简单的flask项目使用s ...

  4. 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦

    听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何?        上周奥威公开 ...

  5. 支付宝sdk集成,报系统繁忙 请稍后再试(ALI64)

    移动快捷支付,往往需要集成支付宝的sdk,集成的过程相对简单,只要按照支付宝的文档,进行操作一般不会出问题.            下面主要说明一下,集成sdk后报"系统繁忙 请稍后再试(A ...

  6. CloudStack 4.2 新功能:集成SNMP进行系统监控(原理篇)

    作者微博:http://weibo.com/tianchunfeng CloudStack 4.2 版本发布在即,相信不久后对 4.2 版本新功能(共有13个)的介绍会逐渐多起来.因为无论是从架构底层 ...

  7. FineReport集成到AWS系统中的方案

    本人实施了北京炎黄盈动的BPM及OA系统,主要目标是对业务流程进行控制和管理,加快Oracle JDE的业务前端录单速度和弥补JDE在流程控制方面的不足,实现BPM数据能与JDE无缝互相结合,经过3个 ...

  8. hive集成sentry的sql使用语法

    Sentry权限控制通过Beeline(Hiveserver2 SQL 命令行接口)输入Grant 和 Revoke语句来配置.语法跟现在的一些主流的关系数据库很相似.需要注意的是:当sentry服务 ...

  9. impala集成sentry

    1.安装配置sentry 详细步骤见上一篇安装配置sentry. 2.配置impala 注:以下配置未集成kerberos安全认证 在/etc/imapla/conf目录下创建sentry-site. ...

随机推荐

  1. web service基础知识

    Web服务基础 用户访问网站的基本流程 我们每天都会用web客户端上网,浏览器就是一个web客户端,例如谷歌浏览器,以及火狐浏览器等. 当我们输入www.oldboyedu.com/时候,很快就能看到 ...

  2. java 2D图形绘制

    package jisuan; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; imp ...

  3. > Raiders 项目配置

    VS2010 新建一个工程,把 源码目录\Source\T3DIICHAP01中的*.h 和*.cpp文件都拷到新工程中并添加 双击  源码目录\DirectX \  dx9sdkcp.exe会自动解 ...

  4. Cracking The Coding Interview 2.5

    这题的思想来自于http://hawstein.com/posts/2.5.html,重新实现了一下 用hash来记录循环的起点 //Given a circular linked list, imp ...

  5. angular 离开页面相关操作

    $scope.$on("$destroy", function() { $interval.cancel(autoRefresh);})

  6. 《十天学会单片机和C语言编程》

    <十天学会单片机和C语言编程> 大家注意了这个文件只有最新版迅雷可以下载,下面的lesson几就是第几课.点击右键使用迅雷下载. ed2k://|file|[十天学会单片机和C语言编程]. ...

  7. java基础学习之final关键字

    final可以修饰类.方法.变量,一旦使用了final则将不能改变被修饰的对象的引用; 被final修饰的类不可以被继承 被final修饰的方法不可以被覆盖 被final修饰的变量一般为常量,只允许对 ...

  8. Python 私有

    class Person: __qie = "潘潘" # 类变量 def __init__(self, name, mimi): self.name = name self.__m ...

  9. 3d的 一些公式

    1. 3d围绕 z轴旋转 x,y 变换公式: // α β x = r cosα y = r sinα x' = r cos (α+β) y' = r sin (α+β) x' = r (cosα c ...

  10. 用XPath精确定位节点元素&selenium使用Xpath定位之完整篇

    在利用XSL进行转换的过程中,匹配的概念非常重要.在模板声明语句 xsl:template match = ""和模板应用语句xsl:apply-templates select ...