欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

安装centry

程序员文章站 2022-04-30 09:25:34
...

一、成功安装

  1. 安装docker
    sudo yum -y install docker-io 
    
  2. 启动docker
    service docker start
    
  3. docker换源
    sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6616fe43.m.daocloud.io
    
  4. 将docker加入到开机启动中
    chkconfig docker on
    
  5. docker拉取redis postsql 和sentry
    docker pull redis 
    docker pull postgres 
    docker pull sentry
    
  6. 启动redis和sentry
    docker run -d --name sentry-redis redis docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry postgres docker run --rm sentry config generate-secret-key
  7. 启动sentry(上一行得到secret-key,然后把key复制到下面四行的单引号中)
    docker run -it --rm -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry upgrade
    
    (这一步会提示输入邮箱和密码)
    docker run -d -p 9000:9000 --name my-sentry -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-redis:redis --link sentry-postgres:postgres sentry
    docker run -d --name sentry-cron -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry run cron 
    docker run -d --name sentry-worker-1 -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry run worker 
    

采集java终端:

  1. 创建java采集project 安装centry
  2. 创建一个java项目,创建MySentry.java:
package com.lenovo.ai.uuid.sentry;

import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.SentryClientFactory;
import io.sentry.context.Context;
import io.sentry.event.BreadcrumbBuilder;
import io.sentry.event.UserBuilder;

public class MySentry {
    private static SentryClient sentry;

    public static void main(String... args) {
        Sentry.init();
        sentry = SentryClientFactory.sentryClient();
        MySentry myClass = new MySentry();
        myClass.logWithStaticAPI();
        myClass.logWithInstanceAPI();
    }

    void unsafeMethod() {
        throw new UnsupportedOperationException("You shouldn't call this!");
    }

    void logWithStaticAPI() {
        Sentry.getContext().recordBreadcrumb(
                new BreadcrumbBuilder().setMessage("User made an action").build()
        );
        Sentry.getContext().setUser(
                new UserBuilder().setEmail("aaa@qq.com").build()
        );
        Sentry.getContext().addExtra("extra", "thing");
        Sentry.getContext().addTag("tagName", "tagValue");
        Sentry.capture("This is a test");
        try {
            unsafeMethod();
        } catch (Exception e) {
            Sentry.capture(e);
        }
    }

    /**
     * Examples that use the SentryClient instance directly.
     */
    void logWithInstanceAPI() {
        Context context = sentry.getContext();
        context.recordBreadcrumb(new BreadcrumbBuilder().setMessage("User made an action").build());
        context.setUser(new UserBuilder().setEmail("aaa@qq.com").build());
        sentry.sendMessage("This is a test");
        try {
            unsafeMethod();
        } catch (Exception e) {
            // This sends an exception event to Sentry.
            sentry.sendException(e);
        }
    }
}
  1. 配置文件centry.properties:
dsn=http://aaa@qq.com:9000/3

备注:a48a254da2b34b04aea48b8a55174756
安装centry

  1. 工程结构: 安装centry
  2. 运行MySentry,java,在web页面上看到:
    安装centry

监控js项目:

  1. 创建html
<html>
	<head>
		<script src="https://browser.sentry-cdn.com/5.5.0/bundle.min.js" crossorigin="anonymous"></script>
		<script type="text/javascript">
					Sentry.init({ dsn: 'http://aaa@qq.com:9000/2' });
					myUndefinedFunction();
		</script>		
</head>
</html>

因为myUndefinedFunction函数未定义,所以会出现js异常

  1. 在web页面上,可以看到:
    安装centry
相关标签: 监控