SkyWalking全链路监控java项目

一、安装elasticsearch

1、创建文件夹:# mkdir /usr/local/skywalking

2、上传apache-skywalking-apm-6.5.0.tar.gz 和 elasticsearch-6.4.2.tar.gz到服务器

3、解压文件:# tar -zxvf elasticsearch-6.4.2.tar.gz

4、修改linux系统限制配置,ES至少需要65536的文件创建数的权限和4096的线程预备

      # vim /etc/security/limits.conf

新增内容:
es soft nofile 65536 es hard nofile 65536 es soft nproc 4096 es hard nproc 4096

5、开辟65536字节以上的内存空间:# vi /etc/sysctl.conf

新增内容:
vm.max_map_count=262144

6、使配置生效:# sysctl -p 

7、增加es用户 # useradd es

8、添加用户密码 # passwd es

9、修改elasicsearch拥有者 # chown -R es elasticsearch-6.4.2

10、切换用户# su es

11、进入bin目录启动:./elasticsearch -d

12、查看日志# tail -f logs/ elasticsearch.log

13、访问:curl http://localhost:9200

运行正常:
{
"name" : "kDV1-PC", "cluster_name" : "elasticsearch", "cluster_uuid" : "cNMLPvzNQsuYOKIEOtQJrQ", "version" : { "number" : "6.4.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "04711c2", "build_date" : "2018-09-26T13:34:09.098244Z", "build_snapshot" : false, "lucene_version" : "7.4.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }

 二、安装skywalking

1、解压安装包 # tar -zxvf apache-skywalking-apm-6.5.0.tar.gz

2、进入目录 # cd apache-skywalking-apm-bin

3、编辑application文件:#  vim config/application.yml

# 将enableDatabaseSession注释请除,将h2添加注释
enableDatabaseSession: ${SW_CORE_ENABLE_DATABASE_SESSION:true}
storage:
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:"../es_keystore.jks"}
    trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""}
    user: ${SW_ES_USER:""}
    password: ${SW_ES_PASSWORD:""}
    indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
    indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
#    # Those data TTL settings will override the same settings in core module.
    recordDataTTL: ${SW_STORAGE_ES_RECORD_DATA_TTL:7} # Unit is day
    otherMetricsDataTTL: ${SW_STORAGE_ES_OTHER_METRIC_DATA_TTL:45} # Unit is day
    monthMetricsDataTTL: ${SW_STORAGE_ES_MONTH_METRIC_DATA_TTL:18} # Unit is month
#    # Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
    bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests
    flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
    concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
    resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
    metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
    segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
#  h2:
#   driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
#  url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db}
# user: ${SW_STORAGE_H2_USER:sa}
#metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}

4、编辑webapp.yml文件# vim webapp/webapp.yml

# 修改端口
server: port: 9010

5、进入bin目录启动:./startup.sh

三、agent探针

1、目录说明:config存放配置文件,plugins存放执行的jar包,optional-plugins存放备用jar包(需要放入plugins才能执行)

2、修改探测的应用名称 # vim config/agent.conf

agent.service_name=${SW_AGENT_NAME:skywalking_xxx}

 3、在tomcat中引入探针监控,修改文件tomcat/bin/catalina.sh,在文件头部加入以下内容:

CATALINA_OPTS="CATALINA_OPTS -javaagent:/usr/loacl/skywalking/apache-skywalking-apm-bin-skywalking/agent/skywalking.jar";export CATALINA_OPTS

4、监控Spring boot项目

java -javaagnet:/usr/loacl/skywalking/apache-skywalking-apm-bin-skywalking/agent/skywalking-agent.jar -Dserver.port=9092 -jar xxxx.jar &

5、配置覆盖启动

以探针的方式启动(不需要去agent.conf指定名字)
java -javaagnet:/usr/loacl/skywalking/apache-skywalking-apm-bin-skywalking/agent/skywalking-agent.jar=agent.server_name=config_xxx -Dserver.port=9092 -jar xxxx.jar &

以系统配置方式启动(不需要去agent.conf指定名字)
java -javaagnet:/usr/loacl/skywalking/apache-skywalking-apm-bin-skywalking/agent/skywalking-agent.jar -Dskywalking.agent.server_name=config_xxx -Dserver.port=9092 -jar xxxx.jar &

 6、其他插件使用

  获取追踪id:首先在项目工程中加入依赖包apm-toolkit-trace,对应的版本需要和skywalking一致,在代码中使用装饰器的形式获取traceid

  过滤不需要的端点:将/agent/optional-plugins/apm-trace-ignore-plugins-6.4.2.jar拷贝到plugins目录中,重启skywalking,在代码中需要使用装饰器的形式忽略端点

7、告警

  告警规则查看:config/alarm-settings.yml,需要在代码中配置webhooks方法并配置查看方法或者邮件触发等方法 

rules:
  # Rule unique name, must be ended with `_rule`.
  service_resp_time_rule: # 规则名称
    metrics-name: service_resp_time # 监控数据
    op: ">"  # 比较值
    threshold: 1000 # 阈值
    period: 10 # 多久检查一次 min
    count: 3  # 达到多少次之后告警
    silence-period: 5  # 多久之内不会忽略相同的告警
    message: Response time of service {name} is more than 1000ms in 3 minutes of last 10 minutes. # 告警消息

  webhooks:
   - http://127.0.0.1:9090/webhooks/ 

posted on 2021-04-16 21:51  灬菜鸟灬  阅读(1925)  评论(0编辑  收藏  举报

导航