一、成功安裝
- 安裝docker
sudo yum -y install docker-io
- 啓動docker
service docker start
- docker換源
sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6616fe43.m.daocloud.io
- 將docker加入到開機啓動中
chkconfig docker on
- docker拉取redis postsql 和sentry
docker pull redis docker pull postgres docker pull sentry
- 啓動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
- 啓動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終端:
- 創建java採集project
- 創建一個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("[email protected]").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("[email protected]").build());
sentry.sendMessage("This is a test");
try {
unsafeMethod();
} catch (Exception e) {
// This sends an exception event to Sentry.
sentry.sendException(e);
}
}
}
- 配置文件centry.properties:
dsn=http://[email protected]:9000/3
備註:a48a254da2b34b04aea48b8a55174756
- 工程結構:
- 運行MySentry,java,在web頁面上看到:
監控js項目:
- 創建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://[email protected]:9000/2' });
myUndefinedFunction();
</script>
</head>
</html>
因爲myUndefinedFunction函數未定義,所以會出現js異常
- 在web頁面上,可以看到: