自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

自從上了SkyWalking,睡覺真香?。?!

安全 應(yīng)用安全
SkyWalking 是一個應(yīng)用性能監(jiān)控系統(tǒng),特別為微服務(wù)、云原生和基于容器(Docker,Kubernetes,Mesos)體系結(jié)構(gòu)而設(shè)計。

[[395152]]

圖片來自 Pexels

除了應(yīng)用指標監(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} 

當然,也可以通過環(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. <?xml version="1.0" encoding="UTF-8"?> 
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
  4.     <modelVersion>4.0.0</modelVersion> 
  5.     <parent> 
  6.         <groupId>org.springframework.boot</groupId> 
  7.         <artifactId>spring-boot-starter-parent</artifactId> 
  8.         <version>2.4.0</version> 
  9.         <relativePath/> <!-- lookup parent from repository --> 
  10.     </parent> 
  11.     <groupId>com.wt.monitor</groupId> 
  12.     <artifactId>skywalking-alarm</artifactId> 
  13.     <version>1.0.0-SNAPSHOT</version> 
  14.     <name>skywalking-alarm</name
  15.  
  16.     <properties> 
  17.         <java.version>1.8</java.version> 
  18.     </properties> 
  19.  
  20.     <dependencies> 
  21.         <dependency> 
  22.             <groupId>org.springframework.boot</groupId> 
  23.             <artifactId>spring-boot-starter-web</artifactId> 
  24.         </dependency> 
  25.  
  26.         <dependency> 
  27.             <groupId>com.aliyun</groupId> 
  28.             <artifactId>alibaba-dingtalk-service-sdk</artifactId> 
  29.             <version>1.0.1</version> 
  30.         </dependency> 
  31.  
  32.         <dependency> 
  33.             <groupId>commons-codec</groupId> 
  34.             <artifactId>commons-codec</artifactId> 
  35.             <version>1.15</version> 
  36.         </dependency> 
  37.  
  38.         <dependency> 
  39.             <groupId>com.alibaba</groupId> 
  40.             <artifactId>fastjson</artifactId> 
  41.             <version>1.2.75</version> 
  42.         </dependency> 
  43.  
  44.         <dependency> 
  45.             <groupId>org.projectlombok</groupId> 
  46.             <artifactId>lombok</artifactId> 
  47.             <optional>true</optional> 
  48.         </dependency> 
  49.     </dependencies> 
  50.  
  51.     <build> 
  52.         <plugins> 
  53.             <plugin> 
  54.                 <groupId>org.springframework.boot</groupId> 
  55.                 <artifactId>spring-boot-maven-plugin</artifactId> 
  56.             </plugin> 
  57.         </plugins> 
  58.     </build> 
  59.  
  60. </project> 

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

  1. <dependency 
  2.     <groupId>org.apache.skywalking</groupId> 
  3.     <artifactId>server-core</artifactId> 
  4.     <version>8.2.0</version> 
  5. </dependency> 

定義告警消息實體類:

  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 + "&timestamp=" + 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<AlarmMessageDTO> 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

 

責(zé)任編輯:武曉燕 來源: urlify
相關(guān)推薦

2022-03-11 10:29:22

監(jiān)控系統(tǒng)數(shù)據(jù)

2022-12-19 08:32:57

項目Feign框架

2022-02-23 11:47:57

CharlesFiddler抓包

2022-12-13 08:29:13

項目插入式注解

2024-09-14 09:59:04

2024-01-08 08:44:06

2020-03-02 15:48:26

戴爾

2020-07-03 15:10:35

Java Rust 開發(fā)

2021-06-30 09:20:18

NuShell工具Linux

2021-11-25 06:54:54

NginxHTTP服務(wù)器

2019-12-30 12:08:05

戴爾

2021-08-30 19:00:46

靜態(tài)CompletableCountDownLa

2024-09-30 10:11:04

2024-05-15 10:28:50

2024-01-06 09:58:22

2021-02-02 15:38:19

Disruptor緩存Java

2015-09-09 10:50:32

模擬駕駛

2013-03-25 14:29:23

Surface Pro

2023-11-28 08:53:15

2021-02-05 12:34:33

線程池系統(tǒng)
點贊
收藏

51CTO技術(shù)棧公眾號