华为云CES监控与飞书通知

华为云负载均衡连接数监控与飞书通知

在云服务的日常运维中,持续监控资源状态是保障系统稳定性的关键步骤之一。本文通过一个实际案例展示了如何使用华为云的Go SDK获取负载均衡器的连接数,并通过飞书Webhook发送通知到团队群组,以便运维人员及时获取最新的监控信息。本来准备直接使用ces告警,但是看了一下模版以及最佳实践貌似没有很好的支持webhook,就直接自己使用go sdk实现了!

背景知识

在华为云上,负载均衡服务(ELB)用于分发来自客户端的网络请求到多个云服务器,确保系统在面对不同的负载情况时,仍能够提供稳定、可靠的服务。ELB的性能指标,如每分钟连接数(CPS),是反映当前系统承载能力的重要数据。通常情况下,我们希望能够实时监控这些关键指标。

随着云服务技术的成熟,大型企业往往会将监控数据集成到实时通讯工具中,便于团队成员即时查看和响应潜在的问题。本案例中选择的通讯工具是飞书,华为云Go SDK则是我们与华为云服务交互的媒介。

环境准备

华为云提供的Go SDK是一套围绕华为云API构建的开发工具包,使得开发者可以在Go语言环境中便捷地调用云服务。在这里,我们利用Cloud Eye Service (CES) 的API,通过SDK检索ELB的CPS指标数据。

安装华为云Go SDK

首先需要安装华为云Go SDK。可以通过go get命令安装所需的SDK包:

go get -u github.com/huaweicloud/huaweicloud-sdk-go-v3

安装完成后,即可在项目中引入相关的SDK模块。

初始化客户端

要与华为云的服务交互,我们需要创建并初始化一个SDK客户端。如下示例中,我们创建了用于CES(Cloud Eye Service)服务的客户端,并使用了之前提到的AK和SK进行了认证。

package main// 导入相关的包
import ("fmt""bytes""json""http""ioutil""time""github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic""github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1"ces "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
)const (feishuWebhookURL = "xxxx" // 飞书Webhook URLak               = "xxx"  // Access Keysk               = "xxxxx" // Secret Key
)func main() {// 构建认证信息auth := basic.NewCredentialsBuilder().WithAk(ak).WithSk(sk).Build()// 初始化CES客户端client := ces.NewCesClient(ces.CesClientBuilder().WithRegion(region.ValueOf("cn-east-3")).WithCredential(auth).Build())// ...后续代码
}

设置定时器和执行任务

我们通过一个定时器来定期检查负载均衡器的最大连接数,例如:

    ticker := time.NewTicker(1 * time.Minute) // 每分钟触发检查for {select {case t := <-ticker.C:currentHour := t.Hour()// 只在既定的时间范围内执行if currentHour >= 7 && currentHour < 24 {// 我们设定在59分时收集数据if t.Minute() == 59 {go collectDataAndSendToFeishu(client)}}}}

这里限制了定时器发送的时间范围早上7点到24点执行,0点-7点默认不执行。并且执行的时间是每个小时的59分执行!

收集和发送数据

一旦定时器触发并满足条件,我们会收集负载均衡的最大连接数并发送给飞书,参考 华为云ces ShowMetricData接口:
image.png
具体实现如下,注意**ShowMetricDataRequest **中具体参数:

func collectDataAndSendToFeishu(client *ces.CesClient) {currentTime := time.Now().UTC()startTime := currentTime.Truncate(time.Hour).Add(time.Minute * 58)endTime := startTime.Add(time.Minute)startTimestamp := startTime.UnixNano() / int64(time.Millisecond)endTimestamp := endTime.UnixNano() / int64(time.Millisecond)request := &model.ShowMetricDataRequest{Namespace:  "SYS.ELB",MetricName: "m1_cps",Dim0:       "lbaas_instance_id,xxxxxx",Filter:     model.GetShowMetricDataRequestFilterEnum().MAX,Period:     int32(1),From:       startTimestamp,To:         endTimestamp,}response, err := client.ShowMetricData(request)if err != nil {fmt.Println("Error querying CES data:", err)return}fmt.Printf("CES response: %+v\n", response)// Extract max value and timestamp from the responsevar maxConnection float64var timestamp int64if response.Datapoints != nil && len(*response.Datapoints) > 0 {datapoints := *response.DatapointsmaxConnection = *datapoints[0].Maxtimestamp = datapoints[0].Timestamp}// Format the timestamp to a readable formreadableTime := time.Unix(timestamp/1000, (timestamp%1000)*int64(time.Millisecond)).Format("2006-01-02 15:04:05")// Prepare the message to send to FeishufeishuMessage := fmt.Sprintf("当前时间 %s 负载均衡最大连接数是 %.2f", readableTime, maxConnection)if err := sendToFeishuWebhook(feishuWebhookURL, feishuMessage); err != nil {fmt.Println("Error sending to Feishu webhook:", err)}
}

发送Webhook通知

最后,实现sendToFeishuWebhook方法以将消息推送到飞书。

func sendToFeishuWebhook(webhookURL string, message string) error {webhookMessage := FeishuWebhookMessage{MsgType: "text",}webhookMessage.Content.Text = messagejsonData, err := json.Marshal(webhookMessage)if err != nil {return fmt.Errorf("failed to marshal webhook message: %v", err)}req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonData))if err != nil {return fmt.Errorf("failed to create HTTP request: %v", err)}req.Header.Set("Content-Type", "application/json")client := &http.Client{}resp, err := client.Do(req)if err != nil {return fmt.Errorf("failed to send HTTP request: %v", err)}defer resp.Body.Close()responseBody, err := ioutil.ReadAll(resp.Body)if err != nil {return fmt.Errorf("failed to read webhook response body: %v", err)}fmt.Println("Feishu webhook response:", string(responseBody))return nil
}

完整代码:

每小时59分统计58-59分最大值发送统计到飞书:

package main
type FeishuWebhookMessage struct {MsgType string `json:"msg_type"`Content struct {Text string `json:"text"`} `json:"content"`
}const (// 定时器间隔,用于根据特定时间点触发数据检索。例如:59分时执行任务,就是(59 - 当前时间的分钟数) x 每分钟的秒数feishuWebhookURL = "xxxx"ak               = "xxx"sk               = "xxxxx"
)func main() {auth := basic.NewCredentialsBuilder().WithAk(ak).WithSk(sk).Build()client := ces.NewCesClient(ces.CesClientBuilder().WithRegion(region.ValueOf("cn-east-3")).WithCredential(auth).Build())ticker := time.NewTicker(1 * time.Minute) // Check every 10 minutes to adjust for the next 59th minute.for {select {case t := <-ticker.C:// 这里设置只在7-24点执行currentHour := t.Hour()if currentHour >= 7 && currentHour < 24 {if t.Minute() == 59 {go collectDataAndSendToFeishu(client)}}}}
}
func collectDataAndSendToFeishu(client *ces.CesClient) {currentTime := time.Now().UTC()startTime := currentTime.Truncate(time.Hour).Add(time.Minute * 58)endTime := startTime.Add(time.Minute)startTimestamp := startTime.UnixNano() / int64(time.Millisecond)endTimestamp := endTime.UnixNano() / int64(time.Millisecond)request := &model.ShowMetricDataRequest{Namespace:  "SYS.ELB",MetricName: "m1_cps",Dim0:       "lbaas_instance_id,xxxxxx",Filter:     model.GetShowMetricDataRequestFilterEnum().MAX,Period:     int32(1),From:       startTimestamp,To:         endTimestamp,}response, err := client.ShowMetricData(request)if err != nil {fmt.Println("Error querying CES data:", err)return}fmt.Printf("CES response: %+v\n", response)// Extract max value and timestamp from the responsevar maxConnection float64var timestamp int64if response.Datapoints != nil && len(*response.Datapoints) > 0 {datapoints := *response.DatapointsmaxConnection = *datapoints[0].Maxtimestamp = datapoints[0].Timestamp}// Format the timestamp to a readable formreadableTime := time.Unix(timestamp/1000, (timestamp%1000)*int64(time.Millisecond)).Format("2006-01-02 15:04:05")// Prepare the message to send to FeishufeishuMessage := fmt.Sprintf("当前时间 %s 负载均衡最大连接数是 %.2f", readableTime, maxConnection)if err := sendToFeishuWebhook(feishuWebhookURL, feishuMessage); err != nil {fmt.Println("Error sending to Feishu webhook:", err)}
}// sendToFeishuWebhook sends a message to Feishu webhook
func sendToFeishuWebhook(webhookURL string, message string) error {webhookMessage := FeishuWebhookMessage{MsgType: "text",}webhookMessage.Content.Text = messagejsonData, err := json.Marshal(webhookMessage)if err != nil {return fmt.Errorf("failed to marshal webhook message: %v", err)}req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonData))if err != nil {return fmt.Errorf("failed to create HTTP request: %v", err)}req.Header.Set("Content-Type", "application/json")client := &http.Client{}resp, err := client.Do(req)if err != nil {return fmt.Errorf("failed to send HTTP request: %v", err)}defer resp.Body.Close()responseBody, err := ioutil.ReadAll(resp.Body)if err != nil {return fmt.Errorf("failed to read webhook response body: %v", err)}fmt.Println("Feishu webhook response:", string(responseBody))return nil
}

运行以上代码:
img_v3_026i_b57d3d26-178b-4f64-8ade-5ecfcd3917dg.jpg

其它的扩展玩法:

每分钟检查一次,当连接数大于100报警触发

package mainimport ("bytes""encoding/json""fmt""github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"ces "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1""github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/region""io/ioutil""net/http""time"
)type FeishuWebhookMessage struct {MsgType string `json:"msg_type"`Content struct {Text string `json:"text"`} `json:"content"`
}const (feishuWebhookURL = "xxxx"ak               = "xxxx"sk               = "xxxxx"
)func main() {auth := basic.NewCredentialsBuilder().WithAk(ak).WithSk(sk).Build()client := ces.NewCesClient(ces.CesClientBuilder().WithRegion(region.ValueOf("cn-east-3")).WithCredential(auth).Build())ticker := time.NewTicker(1 * time.Minute) // Check every 10 minutes to adjust for the next 59th minute.for {select {case t := <-ticker.C:// 这里设置只在7-24点执行currentHour := t.Hour()if currentHour >= 7 && currentHour < 24 {go collectDataAndSendToFeishu(client)}}}
}
func collectDataAndSendToFeishu(client *ces.CesClient) {currentTime := time.Now().UTC().Truncate(time.Minute)startTime := currentTime.Add(-1 * time.Minute)endTime := currentTimestartTimestamp := startTime.UnixNano() / int64(time.Millisecond)endTimestamp := endTime.UnixNano() / int64(time.Millisecond)request := &model.ShowMetricDataRequest{Namespace:  "SYS.ELB",MetricName: "m1_cps",Dim0:       "lbaas_instance_id,xxxxx",Filter:     model.GetShowMetricDataRequestFilterEnum().MAX,Period:     int32(1),From:       startTimestamp,To:         endTimestamp,}response, err := client.ShowMetricData(request)if err != nil {fmt.Println("Error querying CES data:", err)return}fmt.Printf("CES response: %+v\n", response)// Extract max value and timestamp from the responsevar maxConnection float64var timestamp int64if response.Datapoints != nil && len(*response.Datapoints) > 0 {datapoints := *response.DatapointsmaxConnection = *datapoints[0].Maxtimestamp = datapoints[0].Timestamp}// Format the timestamp to a readable formreadableTime := time.Unix(timestamp/1000, (timestamp%1000)*int64(time.Millisecond)).Format("2006-01-02 15:04:05")// Prepare the message to send to Feishuif maxConnection > 100 {// Prepare the alert message to send to FeishufeishuMessage := fmt.Sprintf("警告:当前时间 %s 负载均衡连接数超越100,当前数值是 %.2f", readableTime, maxConnection)if err := sendToFeishuWebhook(feishuWebhookURL, feishuMessage); err != nil {fmt.Println("Error sending to Feishu webhook:", err)}}
}// sendToFeishuWebhook sends a message to Feishu webhook
func sendToFeishuWebhook(webhookURL string, message string) error {webhookMessage := FeishuWebhookMessage{MsgType: "text",}webhookMessage.Content.Text = messagejsonData, err := json.Marshal(webhookMessage)if err != nil {return fmt.Errorf("failed to marshal webhook message: %v", err)}req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonData))if err != nil {return fmt.Errorf("failed to create HTTP request: %v", err)}req.Header.Set("Content-Type", "application/json")client := &http.Client{}resp, err := client.Do(req)if err != nil {return fmt.Errorf("failed to send HTTP request: %v", err)}defer resp.Body.Close()responseBody, err := ioutil.ReadAll(resp.Body)if err != nil {return fmt.Errorf("failed to read webhook response body: %v", err)}fmt.Println("Feishu webhook response:", string(responseBody))return nil
}

为了方便代码的复用性,可读性。将100作为一个可配置常量提取出来:

package mainimport ("bytes""encoding/json""fmt""github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"ces "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1""github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/region""io/ioutil""net/http""time"
)type FeishuWebhookMessage struct {MsgType string `json:"msg_type"`Content struct {Text string `json:"text"`} `json:"content"`
}const (// 定时器间隔,用于根据特定时间点触发数据检索。例如:59分时执行任务,就是(59 - 当前时间的分钟数) x 每分钟的秒数feishuWebhookURL                = "xxxxx"ak                              = "xxxx"sk                              = "xxxx"loadBalancerConnectionThreshold = 100.00 // 负载均衡连接数阈值
)func main() {auth := basic.NewCredentialsBuilder().WithAk(ak).WithSk(sk).Build()client := ces.NewCesClient(ces.CesClientBuilder().WithRegion(region.ValueOf("cn-east-3")).WithCredential(auth).Build())ticker := time.NewTicker(1 * time.Minute) // Check every 10 minutes to adjust for the next 59th minute.for {select {case t := <-ticker.C:// 这里设置只在7-24点执行currentHour := t.Hour()if currentHour >= 7 && currentHour < 24 {go collectDataAndSendToFeishu(client)}}}
}
func collectDataAndSendToFeishu(client *ces.CesClient) {currentTime := time.Now().UTC().Truncate(time.Minute)startTime := currentTime.Add(-1 * time.Minute)endTime := currentTimestartTimestamp := startTime.UnixNano() / int64(time.Millisecond)endTimestamp := endTime.UnixNano() / int64(time.Millisecond)request := &model.ShowMetricDataRequest{Namespace:  "SYS.ELB",MetricName: "m1_cps",Dim0:       "lbaas_instance_id,xxxx",Filter:     model.GetShowMetricDataRequestFilterEnum().MAX,Period:     int32(1),From:       startTimestamp,To:         endTimestamp,}response, err := client.ShowMetricData(request)if err != nil {fmt.Println("Error querying CES data:", err)return}fmt.Printf("CES response: %+v\n", response)// Extract max value and timestamp from the responsevar maxConnection float64var timestamp int64if response.Datapoints != nil && len(*response.Datapoints) > 0 {datapoints := *response.DatapointsmaxConnection = *datapoints[0].Maxtimestamp = datapoints[0].Timestamp}// Format the timestamp to a readable formreadableTime := time.Unix(timestamp/1000, (timestamp%1000)*int64(time.Millisecond)).Format("2006-01-02 15:04:05")// Prepare the message to send to Feishuif maxConnection > loadBalancerConnectionThreshold {// Prepare the alert message to send to FeishufeishuMessage := fmt.Sprintf("警报:在%s,负载均衡器的连接数超过了%.2f,当前连接数:%.2f", readableTime, loadBalancerConnectionThreshold, maxConnection)if err := sendToFeishuWebhook(feishuWebhookURL, feishuMessage); err != nil {fmt.Println("Error sending to Feishu webhook:", err)}}
}// sendToFeishuWebhook sends a message to Feishu webhook
func sendToFeishuWebhook(webhookURL string, message string) error {webhookMessage := FeishuWebhookMessage{MsgType: "text",}webhookMessage.Content.Text = messagejsonData, err := json.Marshal(webhookMessage)if err != nil {return fmt.Errorf("failed to marshal webhook message: %v", err)}req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonData))if err != nil {return fmt.Errorf("failed to create HTTP request: %v", err)}req.Header.Set("Content-Type", "application/json")client := &http.Client{}resp, err := client.Do(req)if err != nil {return fmt.Errorf("failed to send HTTP request: %v", err)}defer resp.Body.Close()responseBody, err := ioutil.ReadAll(resp.Body)if err != nil {return fmt.Errorf("failed to read webhook response body: %v", err)}fmt.Println("Feishu webhook response:", string(responseBody))return nil
}

注意loadBalancerConnectionThresholdfloat64.

增加 MetricName多个条件

这里以弹性IP EIP与负载均衡为例,我想查询负载均衡连接数大于100报警,并根据负载均衡对应eip的四个指标:“upstream_bandwidth_usage”,“downstream_bandwidth_usage”,“upstream_bandwidth”,"downstream_bandwidth"报警,完整代码如下:

package mainimport ("bytes""encoding/json""fmt""github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"ces "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1""github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/region""io/ioutil""net/http""time"
)type FeishuWebhookMessage struct {MsgType string `json:"msg_type"`Content struct {Text string `json:"text"`} `json:"content"`
}const (// 定时器间隔,用于根据特定时间点触发数据检索。例如:59分时执行任务,就是(59 - 当前时间的分钟数) x 每分钟的秒数feishuWebhookURL                = "xxxxxxx"ak                              = "xxx"sk                              = "xxxx"upstreamBandwidthThreshold      = 40    // 出网带宽阈值,单位MbpsdownstreamBandwidthThreshold    = 80    // 入网带宽阈值,单位Mbps(示例中以百分比为单位,根据实际单位调整)upstreamUsageThreshold          = 20    // 出网带宽使用率阈值,单位百分比downstreamUsageThreshold        = 40    // 入网带宽使用率阈值,单位百分比
)var metricNames = []string{"upstream_bandwidth_usage","downstream_bandwidth_usage","upstream_bandwidth","downstream_bandwidth",
}func main() {auth := basic.NewCredentialsBuilder().WithAk(ak).WithSk(sk).Build()client := ces.NewCesClient(ces.CesClientBuilder().WithRegion(region.ValueOf("cn-east-3")).WithCredential(auth).Build())ticker := time.NewTicker(time.Minute) // Check every minute.for {select {case <-ticker.C:// 每分钟执行go collectDataAndSendToFeishu(client)}}
}func collectDataAndSendToFeishu(client *ces.CesClient) {currentTime := time.Now().UTC().Truncate(time.Minute)startTime := currentTime.Add(-1 * time.Minute)endTime := currentTimestartTimestamp := startTime.UnixMilli()endTimestamp := endTime.UnixMilli()dimensionValues := "bandwidth_id,xxxx"for _, metricName := range metricNames {request := &model.ShowMetricDataRequest{Namespace:  "SYS.VPC",MetricName: metricName,Dim0:       dimensionValues, // Replace with actual dimension valueFilter:     model.GetShowMetricDataRequestFilterEnum().MAX,Period:     int32(1),From:       startTimestamp,To:         endTimestamp,}response, err := client.ShowMetricData(request)if err != nil {fmt.Printf("Error querying CES data for %s: %v\n", metricName, err)continue}if response.Datapoints == nil || len(*response.Datapoints) == 0 {fmt.Printf("No datapoints received for %s\n", metricName)continue}datapoints := *response.Datapointsvar maxUsage float64for _, point := range datapoints {if point.Max != nil {if metricName == "upstream_bandwidth" || metricName == "downstream_bandwidth" {// Convert from bits to MbitsmaxUsage = *point.Max / 1000000.0} else {maxUsage = *point.Max // for utilization metrics, which are percentages}break // Assuming there's only 1 datapoint with MAX filter}}if (metricName == "upstream_bandwidth" && maxUsage > upstreamBandwidthThreshold) ||(metricName == "downstream_bandwidth" && maxUsage > downstreamBandwidthThreshold) ||(metricName == "upstream_bandwidth_usage" && maxUsage > upstreamUsageThreshold) ||(metricName == "downstream_bandwidth_usage" && maxUsage > downstreamUsageThreshold) {alertMessage := createAlertMessage(metricName, maxUsage, endTime)if err := sendToFeishuWebhook(feishuWebhookURL, alertMessage); err != nil {fmt.Printf("Error sending to Feishu webhook: %v\n", err)}}}
}func createAlertMessage(metricName string, usage float64, endTime time.Time) string {readableTime := endTime.Add(+8 * time.Hour).Format("2006-01-02 15:04:05")var alertMessage string// 注意阈值和单位已更新,具体文本格式根据实际需要调整switch metricName {case "upstream_bandwidth":alertMessage = fmt.Sprintf("警报:在%s,出网带宽超过了%.2fMbps,当前带宽:%.2fMbps", readableTime, upstreamBandwidthThreshold, usage)case "downstream_bandwidth":alertMessage = fmt.Sprintf("警报:在%s,入网带宽超过了%.2fMbps,当前带宽:%.2fMbps", readableTime, downstreamBandwidthThreshold, usage)case "upstream_bandwidth_usage":alertMessage = fmt.Sprintf("警报:在%s,出网带宽使用率超过了%.2f%%,当前使用率:%.2f%%", readableTime, upstreamUsageThreshold, usage)case "downstream_bandwidth_usage":alertMessage = fmt.Sprintf("警报:在%s,入网带宽使用率超过了%.2f%%,当前使用率:%.2f%%", readableTime, downstreamUsageThreshold, usage)}return alertMessage
}func sendToFeishuWebhook(webhookURL string, message string) error {webhookMessage := FeishuWebhookMessage{MsgType: "text",}webhookMessage.Content.Text = messagejsonData, err := json.Marshal(webhookMessage)if err != nil {return fmt.Errorf("failed to marshal webhook message: %v", err)}req, err := http.NewRequest("POST", webhookURL, bytes.NewBuffer(jsonData))if err != nil {return fmt.Errorf("failed to create HTTP request: %v", err)}req.Header.Set("Content-Type", "application/json")client := &http.Client{}resp, err := client.Do(req)if err != nil {return fmt.Errorf("failed to send HTTP request: %v", err)}defer resp.Body.Close()responseBody, err := ioutil.ReadAll(resp.Body)if err != nil {return fmt.Errorf("failed to read webhook response body: %v", err)}fmt.Printf("Feishu webhook response: %s\n", responseBody)return nil
}

测试报警如下:
image.png

其他

  1. 遍历负载均衡列表,批量查询所有负载均衡连接数?发送告警时候传入负载均衡的名称?
  2. 根据负载均衡列表查询绑定的eip实例,查询所有eip对应bandwidth_id,输出所有eip的指标?

总结

此文为你展示了如何通过Go SDK获取华为云上的负载均衡最大连接数and eip指标的多个条件查询,并通过飞书Webhook发送通知的过程。以上的实现可以根据你自己的需求进行调整,比如改变监测的指标或者消息发送的方式。希望本文能帮助你更好地监控和管理华为云上的资源。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/597206.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

福利来袭,.NET Core开发5大案例,30w字PDF文档大放送!!!

千里之行&#xff0c;始于足下&#xff0c;若想提高软件编程能力&#xff0c;最最重要的是实践&#xff0c;所谓纸上得来终觉浅&#xff0c;绝知此事要躬行。根据相关【艾宾浩斯遗忘曲线】研究表明&#xff0c;如果不动手实践&#xff0c;记住的东西会很快忘记。 为了便于大家查…

C#设计模式之观察者模式

前言 观察者&#xff08;Observer)模式也称发布-订阅&#xff08;Publish-Subscribe&#xff09;模式&#xff0c;定义了对象间一种一对多的依赖关系&#xff0c;当一个对象的状态发生改变时&#xff0c;所有依赖于它的对象都得到通知并被自动更新。 观察者模式的图解如下所示…

小程序测试和APP测试的区别

今天看了一下关于如何测试小程序的教学视频&#xff0c;里面讨论了一个很经典的面试题&#xff1a;小程序测试和APP测试的区别&#xff0c;包括在之前的面试过程中也确实是遇到过这个问题&#xff0c;所以这次打算把它记录下来&#xff0c;也算是知识巩固了。 首先从测试的内容…

android7以上 代码安装APK

一、所需权限 <!--请求安装APK的权限--> <uses-permission android:name"android.permission.REQUEST_INSTALL_PACKAGES" /> <!--写如外部存储的权限--> <uses-permission android:name"android.permission.WRITE_EXTERNAL_STORAGE"…

【DevOps-03】Build阶段-Maven安装配置

一、简要说明 下载安装JDK8下载安装Maven二、复制准备一台虚拟机 1、VM虚拟复制克隆一台机器 2、启动刚克隆的虚拟机,修改IP地址 刚刚克隆的虚拟机 ,IP地址和原虚拟的IP地址是一样的,需要修改克隆后的虚拟机IP地址,以免IP地址冲突。 # 编辑修改IP地址 $ vi /etc/sysconfig…

内存管理的概念-第四十一天

目录 前言 内存空间的分配与回收 内存空间的扩展 地址转换 存储保护 上下限寄存器 重定位寄存器和界地址寄存器 本节思维导图 前言 操作系统作为系统资源的管理者&#xff0c;当然也需要对内存进行管理&#xff0c;要管理什么呢&#xff1f; 操作系统复杂内存空间的分…

Lazada商品详情API(lazada.item_get)进行商品的实时更新

一、引言 在数字时代&#xff0c;电商平台如Lazada成为了商品交易的重要场所。为了保持竞争力&#xff0c;实时更新商品信息变得至关重要。Lazada提供的商品详情API&#xff08;lazada.item_get&#xff09;为开发者提供了一个高效的方式来获取并更新商品数据。本文将深入探讨…

SpringBoot全局Controller返回值格式统一处理

一、Controller返回值格式统一 1、WebResult类 在 Controller对外提供服务的时候&#xff0c;我们都需要统一返回值格式。一般定义一个 WebResult类。 统一返回值&#xff08;WebResult类&#xff09;格式如下&#xff1a; {"success": true,"code": 2…

express+mongoDB开发入门教程之mongoose使用讲解

系列文章 node.js express框架开发入门教程 expressmongoDB开发入门教程之mongoDB安装expressmongoDB开发入门教程之mongoose使用讲解 文章目录 系列文章前言一、Mongoose是什么&#xff1f;二、Mongoose安装三、Mongoose在express项目中使用步骤一、连接mongoDB数据库步骤二、…

模拟器怎么代理IP?代理IP对手机设置模拟器有哪些影响?

一、代理IP的基本概念和作用流冠代理IP是一种网络服务&#xff0c;可以帮助用户隐藏自己的真实IP地址&#xff0c;通过代理服务器进行网络请求&#xff0c;从而保护用户的隐私和安全。在模拟器中&#xff0c;代理IP的作用也是如此&#xff0c;可以帮助模拟器隐藏真实的IP地址&a…

javascript 常见工具函数(一)

1.将JSON数据根据相同值&#xff0c;进行归类划分&#xff1a; var arr [{ time: "1", img: "22222" }, { time: "2", img: "555" }, { time: "1", img: "888888" }, { time: "2", img: "4444&q…

MySQL Too many connections报错

MySQL 时不时出现Too many connections报错&#xff0c;重启MySQL就好了 但是过段时间又出现 一、解决方案&#xff1a; 1.修改mysql最大连接数 set global max_connections500; 以上是修改立即生效的&#xff0c;重启MySQL就会还原回去 在MySQL配置文件修改 max_connection…

力扣刷题-二叉树-二叉搜索树中的搜索

700 二叉搜索树中的搜索 给定二叉搜索树&#xff08;BST&#xff09;的根节点和一个值。 你需要在BST中找到节点值等于给定值的节点。 返回以该节点为根的子树。 如果节点不存在&#xff0c;则返回 NULL。 例如&#xff0c; 在上述示例中&#xff0c;如果要找的值是 5&#x…

UDP单播

CMakeLists.txt文件中添加如下行&#xff1a; link_libraries(ws2_32) 1.发送端 #include <iostream> #include <winsock2.h> #include <cstdio>#pragma comment(lib, "Ws2_32.lib") // Link with ws2_32.libint main() {1.Initialize winsock…

JS 手写 new 函数

工作中我们经常会用到 new 关键字&#xff0c;new 一个构造函数生成一个实例对象&#xff0c;那么new的过程中发生了什么呢&#xff0c;我们今天梳理下 创建一个对象对象原型继承绑定函数this返回对象 先创建一个构造函数&#xff0c;原型上添加一个方法 let Foo function (n…

03、Kafka ------ CMAK(Kafka 图形界面管理工具) 下载、安装、启动

目录 CMAK&#xff08;Kafka 图形界面管理工具&#xff09;下载安装启动打开 cmak 图形界面 CMAK&#xff08;Kafka 图形界面管理工具&#xff09; Kafka本身并没有提供Web管理工具&#xff0c;而是推荐使用bin目录下各种工具命令来管理Kafka&#xff0c; 这些工具命令其实用起…

vue3中标签form插件

想写一个系统&#xff0c;对八字进行标注&#xff0c;比如格局&#xff0c;有些八字就有很多格局&#xff0c;于是就想着使用el-tag但是&#xff0c;form表单中如何处理呢&#xff1f; 这个时候&#xff0c;就需要自己写一个,modelValue是表单的默认属性 <template><…

以 Serverfull 方式运行无服务器服务

当前 IT 架构中最流行的用例是从 Serverfull 转向 Serverless 设计。在某些情况下&#xff0c;我们可能需要以 Serverfull 方式设计服务或迁移到 Serverfull 作为运营成本的一部分。 在本文中&#xff0c;我们将展示如何将 Kumologica flow 作为 Docker 容器运行。通常&#x…

HarmonyOS页面和自定义组件生命周期

页面和自定义组件生命周期 在开始之前&#xff0c;我们先明确自定义组件和页面的关系&#xff1a; 自定义组件&#xff1a;Component装饰的UI单元&#xff0c;可以组合多个系统组件实现UI的复用。页面&#xff1a;即应用的UI页面。可以由一个或者多个自定义组件组成&#xff…

52、全连接 - 特征与样本空间的对应关系

上一节说到经过全连接层之后,神经网络学习到的特征,会从隐层特征空间逐步映射到样本空间,这主要是由于全连接层可以融合全局的特征。 在经过全连接层之后,在 ResNet50 这个神经网络中会输出1000个特征的得分值,这1000个特征的得分值,便可以对应到图像的分类。 怎么对应…