日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
自從上了SkyWalking,睡覺真香?。?!

圖片來自 Pexels

創(chuàng)新互聯(lián)公司主營贛州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,贛州h5微信小程序開發(fā)搭建,贛州網(wǎng)站營銷推廣歡迎贛州等地區(qū)企業(yè)咨詢

除了應(yīng)用指標(biāo)監(jiān)控以外,它還能對分布式調(diào)用鏈路進行追蹤。類似功能的組件還有:Zipkin、Pinpoint、CAT 等。

上幾張圖,看看效果,然后再一步一步搭建并使用:

概念與架構(gòu)

SkyWalking 是一個開源監(jiān)控平臺,用于從服務(wù)和云原生基礎(chǔ)設(shè)施收集、分析、聚合和可視化數(shù)據(jù)。

SkyWalking 提供了一種簡單的方法來維護分布式系統(tǒng)的清晰視圖,甚至可以跨云查看。它是一種現(xiàn)代 APM,專門為云原生、基于容器的分布式系統(tǒng)設(shè)計。

SkyWalking 從三個維度對應(yīng)用進行監(jiān)視:

  • service(服務(wù))
  • service instance(實例)
  • endpoint(端點)

服務(wù)和實例就不多說了,端點是服務(wù)中的某個路徑或者說 URI:

SkyWalking allows users to understand the topology relationship between Services and Endpoints, to view the metrics of every Service/Service Instance/Endpoint and to set alarm rules.

SkyWalking 允許用戶了解服務(wù)和端點之間的拓撲關(guān)系,查看每個服務(wù)/服務(wù)實例/端點的度量,并設(shè)置警報規(guī)則。

架構(gòu)如下圖:

SkyWalking 邏輯上分為四個部分:

  • Probes(探針)
  • Platform backend(平臺后端)
  • Storage(存儲)
  • UI

這個結(jié)構(gòu)就很清晰了,探針就是 Agent 負責(zé)采集數(shù)據(jù)并上報給服務(wù)端,服務(wù)端對數(shù)據(jù)進行處理和存儲,UI 負責(zé)展示。

下載與安裝

SkyWalking 有兩中版本,ES 版本和非 ES 版。如果我們決定采用 ElasticSearch 作為存儲,那么就下載 ES 版本。

 
 
 
  1. https://skywalking.apache.org/downloads/ 
  2. https://archive.apache.org/dist/skywalking/ 

如上圖:

  • agent 目錄將來要拷貝到各服務(wù)所在機器上用作探針。
  • bin 目錄是服務(wù)啟動腳本。
  • config 目錄是配置文件。
  • oap-libs 目錄是 oap 服務(wù)運行所需的 jar 包。
  • webapp 目錄是 web 服務(wù)運行所需的 jar 包。

接下來,要選擇存儲了,支持的存儲有:

  • H2
  • ElasticSearch 6,7
  • MySQL
  • TiDB
  • InfluxDB

作為監(jiān)控系統(tǒng),首先排除 H2 和 MySQL,這里推薦 InfluxDB,它本身就是時序數(shù)據(jù)庫,非常適合這種場景。但是 InfluxDB 我不是很熟悉,所以這里先用 ElasticSearch7。

 
 
 
  1. https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backend-storage.md 

①安裝 ElasticSearch

鏈接如下:

 
 
 
  1. https://www.elastic.co/guide/en/elasticsearch/reference/7.10/targz.html 
 
 
 
  1. # 啟動 
  2. ./bin/elasticsearch -d -p pid 
  3. # 停止 
  4. pkill -F pid 

ElasticSearch 7.x 需要 Java 11 以上的版本,但是如果你設(shè)置了環(huán)境變量 JAVA_HOME 的話,它會用你自己的 Java 版本。

通常,啟動過程中會報以下三個錯誤:

 
 
 
  1. [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] 
  2. [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 
  3. [3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured 

解決方法:在 /etc/security/limits.conf 文件中追加以下內(nèi)容。

 
 
 
  1. * soft nofile 65536 
  2. * hard nofile 65536 
  3. * soft nproc  4096 
  4. * hard nproc  4096 

可通過以下四個命令查看修改結(jié)果:

 
 
 
  1. ulimit -Hn 
  2. ulimit -Sn 
  3. ulimit -Hu 
  4. ulimit -Su 

修改 /etc/sysctl.conf 文件,追加以下內(nèi)容:

 
 
 
  1. vm.max_map_count=262144 

修改 ES 配置文件 elasticsearch.yml 取消注釋,保留一個節(jié)點:

 
 
 
  1. cluster.initial_master_nodes: ["node-1"] 

為了能夠 ip:port 方式訪問,還需修改網(wǎng)絡(luò)配置:

 
 
 
  1. network.host: 0.0.0.0 

修改完是這樣的:

至此,ElasticSearch 算是啟動成功了。一個節(jié)點還不夠,這里用三個節(jié)點搭建一個集群。

192.168.100.14 config/elasticsearch.yml:

 
 
 
  1. cluster.name: my-monitor 
  2. node.name: node-1 
  3. network.host: 192.168.100.14 
  4. http.port: 9200 
  5. discovery.seed_hosts: ["192.168.100.14:9300", "192.168.100.15:9300", "192.168.100.19:9300"] 
  6. cluster.initial_master_nodes: ["node-1"] 

192.168.100.15 config/elasticsearch.yml:

 
 
 
  1. cluster.name: my-monitor 
  2. node.name: node-2 
  3. network.host: 192.168.100.15 
  4. http.port: 9200 
  5. discovery.seed_hosts: ["192.168.100.14:9300", "192.168.100.15:9300", "192.168.100.19:9300"] 
  6. cluster.initial_master_nodes: ["node-1"] 

192.168.100.19 config/elasticsearch.yml:

 
 
 
  1. cluster.name: my-monitor 
  2. node.name: node-3 
  3. network.host: 192.168.100.19 
  4. http.port: 9200 
  5. discovery.seed_hosts: ["192.168.100.14:9300", "192.168.100.15:9300", "192.168.100.19:9300"] 
  6. cluster.initial_master_nodes: ["node-1"] 

同時,建議修改三個節(jié)點 config/jvm.options:

 
 
 
  1. -Xms2g 
  2. -Xmx2g 

依次啟動三個節(jié)點:

 
 
 
  1. pkill -F pid 
  2. ./bin/elasticsearch -d -p pid 

接下來,修改 skywalking下config/application.yml 中配置 es 地址即可:

 
 
 
  1. storage: 
  2.   selector: ${SW_STORAGE:elasticsearch7} 
  3.   elasticsearch7: 
  4.     nameSpace: ${SW_NAMESPACE:""} 
  5.     clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.100.14:9200,192.168.100.15:9200,192.168.100.19:9200} 

②安裝 Agent

地址如下:

 
 
 
  1. https://github.com/apache/skywalking/blob/v8.2.0/docs/en/setup/service-agent/java-agent/README.md 

將 agent 目錄拷貝至各服務(wù)所在的機器上:

 
 
 
  1. scp -r ./agent chengjs@192.168.100.12:~/ 

這里,我將它拷貝至各個服務(wù)目錄下:

plugins 是探針用到各種插件,SkyWalking 插件都是即插即用的,可以把 optional-plugins 中的插件放到 plugins 中。

修改 agent/config/agent.config 配置文件,也可以通過命令行參數(shù)指定。主要是配置服務(wù)名稱和后端服務(wù)地址:

 
 
 
  1. agent.service_name=${SW_AGENT_NAME:user-center} 
  2. collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.100.17:11800} 

當(dāng)然,也可以通過環(huán)境變量或系統(tǒng)屬性的方式來設(shè)置,例如:

 
 
 
  1. export SW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800 

最后,在服務(wù)啟動的時候用命令行參數(shù) -javaagent 來指定探針:

 
 
 
  1. java -javaagent:/path/to/skywalking-agent/skywalking-agent.jar -jar yourApp.jar 

例如:

 
 
 
  1. java -javaagent:./agent/skywalking-agent.jar -Dspring.profiles.active=dev -Xms512m -Xmx1024m -jar demo-0.0.1-SNAPSHOT.jar 

啟動服務(wù)

修改 webapp/webapp.yml 文件,更改端口號及后端服務(wù)地址:

 
 
 
  1. server: 
  2.   port: 9000 
  3.  
  4. collector: 
  5.   path: /graphql 
  6.   ribbon: 
  7.     ReadTimeout: 10000 
  8.     # Point to all backend's restHost:restPort, split by , 
  9.     listOfServers: 127.0.0.1:12800 

啟動服務(wù):

 
 
 
  1. bin/startup.sh 

或者分別依次啟動:

 
 
 
  1. bin/oapService.sh 
  2. bin/webappService.sh 

查看 logs 目錄下的日志文件,看是否啟動成功。瀏覽器訪問 :

 
 
 
  1. http://127.0.0.1:9000 

告警

編輯 alarm-settings.yml 設(shè)置告警規(guī)則和通知:

 
 
 
  1. https://github.com/apache/skywalking/blob/v8.2.0/docs/en/setup/backend/backend-alarm.md 

重點說下告警通知:

為了使用釘釘機器人通知,接下來,新建一個項目:

 
 
 
  1.  
  2.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  3.     4.0.0 
  4.      
  5.         org.springframework.boot 
  6.         spring-boot-starter-parent 
  7.         2.4.0 
  8.           
  9.      
  10.     com.wt.monitor 
  11.     skywalking-alarm 
  12.     1.0.0-SNAPSHOT 
  13.     skywalking-alarm 
  14.  
  15.      
  16.         1.8 
  17.      
  18.  
  19.      
  20.          
  21.             org.springframework.boot 
  22.             spring-boot-starter-web 
  23.          
  24.  
  25.          
  26.             com.aliyun 
  27.             alibaba-dingtalk-service-sdk 
  28.             1.0.1 
  29.          
  30.  
  31.          
  32.             commons-codec 
  33.             commons-codec 
  34.             1.15 
  35.          
  36.  
  37.          
  38.             com.alibaba 
  39.             fastjson 
  40.             1.2.75 
  41.          
  42.  
  43.          
  44.             org.projectlombok 
  45.             lombok 
  46.             true 
  47.          
  48.      
  49.  
  50.      
  51.          
  52.              
  53.                 org.springframework.boot 
  54.                 spring-boot-maven-plugin 
  55.              
  56.          
  57.      
  58.  
  59.  

可選依賴(不建議引入):

 
 
 
  1.     org.apache.skywalking 
  2.     server-core 
  3.     8.2.0 
  4.  

定義告警消息實體類:

 
 
 
  1. package com.wt.monitor.skywalking.alarm.domain; 
  2.  
  3. import lombok.Data; 
  4.  
  5. import java.io.Serializable; 
  6.  
  7. /** 
  8.  * @author ChengJianSheng 
  9.  * @date 2020/12/1 
  10.  */ 
  11. @Data 
  12. public class AlarmMessageDTO implements Serializable { 
  13.  
  14.     private int scopeId; 
  15.  
  16.     private String scope; 
  17.  
  18.     /** 
  19.      * Target scope entity name 
  20.      */ 
  21.     private String name; 
  22.  
  23.     private String id0; 
  24.  
  25.     private String id1; 
  26.  
  27.     private String ruleName; 
  28.  
  29.     /** 
  30.      * Alarm text message 
  31.      */ 
  32.     private String alarmMessage; 
  33.  
  34.     /** 
  35.      * Alarm time measured in milliseconds 
  36.      */ 
  37.     private long startTime; 
  38.  

發(fā)送釘釘機器人消息:

 
 
 
  1. package com.wt.monitor.skywalking.alarm.service; 
  2.  
  3. import com.dingtalk.api.DefaultDingTalkClient; 
  4. import com.dingtalk.api.DingTalkClient; 
  5. import com.dingtalk.api.request.OapiRobotSendRequest; 
  6. import com.taobao.api.ApiException; 
  7. import lombok.extern.slf4j.Slf4j; 
  8. import org.apache.commons.codec.binary.Base64; 
  9. import org.springframework.beans.factory.annotation.Value; 
  10. import org.springframework.stereotype.Service; 
  11.  
  12. import javax.crypto.Mac; 
  13. import javax.crypto.spec.SecretKeySpec; 
  14. import java.io.UnsupportedEncodingException; 
  15. import java.net.URLEncoder; 
  16. import java.security.InvalidKeyException; 
  17. import java.security.NoSuchAlgorithmException; 
  18.  
  19. /** 
  20.  * https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq 
  21.  * @author ChengJianSheng 
  22.  * @data 2020/12/1 
  23.  */ 
  24. @Slf4j 
  25. @Service 
  26. public class DingTalkAlarmService { 
  27.  
  28.     @Value("${dingtalk.webhook}") 
  29.     private String webhook; 
  30.     @Value("${dingtalk.secret}") 
  31.     private String secret; 
  32.  
  33.     public void sendMessage(String content) { 
  34.         try { 
  35.             Long timestamp = System.currentTimeMillis(); 
  36.             String stringToSign = timestamp + "\n" + secret; 
  37.             Mac mac = Mac.getInstance("HmacSHA256"); 
  38.             mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")); 
  39.             byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8")); 
  40.             String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8"); 
  41.  
  42.             String serverUrl = webhook + "×tamp=" + timestamp + "&sign=" + sign; 
  43.             DingTalkClient client = new DefaultDingTalkClient(serverUrl); 
  44.             OapiRobotSendRequest request = new OapiRobotSendRequest(); 
  45.             request.setMsgtype("text"); 
  46.             OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); 
  47.             text.setContent(content); 
  48.             request.setText(text); 
  49.  
  50.             client.execute(request); 
  51.         } catch (ApiException e) { 
  52.             e.printStackTrace(); 
  53.             log.error(e.getMessage(), e); 
  54.         } catch (NoSuchAlgorithmException e) { 
  55.             e.printStackTrace(); 
  56.             log.error(e.getMessage(), e); 
  57.         } catch (UnsupportedEncodingException e) { 
  58.             e.printStackTrace(); 
  59.             log.error(e.getMessage(), e); 
  60.         } catch (InvalidKeyException e) { 
  61.             e.printStackTrace(); 
  62.             log.error(e.getMessage(), e); 
  63.         } 
  64.     } 

AlarmController.java:

 
 
 
  1. package com.wt.monitor.skywalking.alarm.controller; 
  2.  
  3. import com.alibaba.fastjson.JSON; 
  4. import com.wt.monitor.skywalking.alarm.domain.AlarmMessageDTO; 
  5. import com.wt.monitor.skywalking.alarm.service.DingTalkAlarmService; 
  6. import lombok.extern.slf4j.Slf4j; 
  7. import org.springframework.beans.factory.annotation.Autowired; 
  8. import org.springframework.web.bind.annotation.PostMapping; 
  9. import org.springframework.web.bind.annotation.RequestBody; 
  10. import org.springframework.web.bind.annotation.RequestMapping; 
  11. import org.springframework.web.bind.annotation.RestController; 
  12.  
  13. import java.text.MessageFormat; 
  14. import java.util.List; 
  15.  
  16. /** 
  17.  * @author ChengJianSheng 
  18.  * @date 2020/12/1 
  19.  */ 
  20. @Slf4j 
  21. @RestController 
  22. @RequestMapping("/skywalking") 
  23. public class AlarmController { 
  24.  
  25.     @Autowired 
  26.     private DingTalkAlarmService dingTalkAlarmService; 
  27.  
  28.     @PostMapping("/alarm") 
  29.     public void alarm(@RequestBody List alarmMessageDTOList) { 
  30.        log.info("收到告警信息: {}", JSON.toJSONString(alarmMessageDTOList)); 
  31.        if (null != alarmMessageDTOList) { 
  32.            alarmMessageDTOList.forEach(e->dingTalkAlarmService.sendMessage(MessageFormat.format("-----來自SkyWalking的告警-----\n【名稱】: {0}\n【消息】: {1}\n", e.getName(), e.getAlarmMessage()))); 
  33.        } 
  34.     } 

參考文檔:

 
 
 
  1. https://skywalking.apache.org/ 
  2. https://skywalking.apache.org/zh/\ https://github.com/apache/skywalking/tree/v8.2.0/docs 
  3. https://archive.apache.org/dist/ 
  4. https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html  
  5. https://www.elastic.co/guide/en/elasticsearch/reference/7.10/modules-discovery-bootstrap-cluster.html 
  6. https://www.elastic.co/guide/en/elasticsearch/reference/7.10/modules-discovery-hosts-providers.html 

作者:廢物大師兄

編輯:陶家龍

出處:https://urlify.cn/Zfy2ia


網(wǎng)站欄目:自從上了SkyWalking,睡覺真香!??!
新聞來源:http://m.5511xx.com/article/djjceep.html