2023年最新prometheus + grafana搭建和使用+gmail郵箱告警配置

一、安裝prometheus

1.1 安裝

prometheus官網下載地址

sudo -i
mkdir -p /opt/prometheus
#移動解壓后的文件名到/opt/,并改名prometheus
mv prometheus-2.45 /opt/prometheus/
#創建一個專門的prometheus用戶: -M 不創建家目錄, -s 不讓登錄
useradd -M -s /usr/sbin/nologin prometheus##更改prometheus用戶的文件夾權限:
chown prometheus:prometheus -R /opt/prometheus
1.2 修改配置
global:scrape_interval: 30s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 30s # Evaluate rules every 15 seconds. The default is every 1 minute.# 其他全局配置...scrape_configs:# Prometheus 自身的監控配置- job_name: "prometheus"static_configs:- targets: ["localhost:9070"]- job_name: 'node_widgets'scheme: https  # 使用 HTTPStls_config:insecure_skip_verify: true  # 忽略證書驗證static_configs:- targets: ['xxxxx.xxx.com:443']  # 替換為您的服務器 B 地址和端口metrics_path: '/prometheus/metrics'  # Node Exporter 的路徑

如果修改了配置可以驗證配置

./promtool check config new_prometheus.yml

熱更新

curl -X POST http://localhost:9070/-/reload
1.3 配置自啟動
vim /etc/systemd/system/prometheus.service
寫入數據
[Unit]
Description=Prometheus Server
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
WorkingDirectory=/opt/prometheus/prometheus-2.45
ExecStart=/opt/prometheus/prometheus-2.45/prometheus --web.listen-address ":9070" --config.file /opt/prometheus/prometheus-2.45/new_prometheus.yml --storage.tsdb.path /opt/prometheus/prometheus-2.45/data --storage.tsdb.retention.time=20d --web.enable-lifecycle
[Install]
WantedBy=multi-user.target

開機自啟動

sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl restart prometheus
sudo systemctl status prometheus

二、安裝node_exporter

2.1 官網下載地址 https://prometheus.io/download/
2.2 開機自啟動

添加

sudo vim /etc/systemd/system/node_exproter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=ubuntu
Group=ubuntu
ExecStart=/opt/prometheus/node_exproter-1.7.0/node_exporter --web.listen-address=":9101"
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable node_exproter
sudo systemctl restart node_exproter
sudo systemctl status node_exproter

三、安裝grafana

3.1 官網下載地址 https://grafana.com/grafana/download?edition=oss&platform=linux
3.2 添加開機啟動

添加service

sudo vim /etc/systemd/system/grafana.service
[Unit]
Description=Grafana server
Documentation=http://docs.grafana.org
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/grafana-v10.2.2/bin/grafana-server \--config=/opt/prometheus/grafana-v10.2.2/conf/grafana.ini \--homepath=/opt/prometheus/grafana-v10.2.2 \--http-port=3000
[Install]
WantedBy=multi-user.target
3.2 修改 grafana.init 郵箱配置
[smtp]
enabled = true
host = smtp.gmail.com:587
user = xuzan@lippu.ltd
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = 授權碼
cert_file =
key_file =
skip_verify = true
from_address = xuzan@lippu.ltd
from_name = Grafana
ehlo_identity =
startTLS_policy =
sudo systemctl daemon-reload
sudo systemctl enable grafana
sudo systemctl restart grafana
sudo systemctl status grafana

四、alertmanager 安裝

4.1 安裝官網地址 https://prometheus.io/download/
4.2 新增啟動項

編輯

sudo vim /etc/systemd/system/alertmanager.service
[Unit]
Description=Alert Manager
Wants=network-online.target
After=network-online.target[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/alertmanager-0.26.0/alertmanager \--config.file=/opt/prometheus/alertmanager-0.26.0/alertmanager.yml \--storage.path=/opt/prometheus/alertmanager-0.26.0/data \--web.listen-address=:9071 \--cluster.listen-address=:9072Restart=always[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable alertmanager
sudo systemctl restart alertmanager
sudo systemctl status alertmanager -l
4.3 使用了prometheus 需要修改 new_prometheus.yml

新增

# Alertmanager configuration
alerting:alertmanagers:- static_configs:- targets:- alertmanager:9071# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:- "alert.yml"

在項目更目錄下新增 新增alert.yml

groups:
- name: Prometheus alertrules:# 對任何實例超過30s無法聯系的情況發出警報- alert: 服務告警expr: up == 0for: 30slabels:severity: criticalannotations:instance: "{{ $labels.instance }}"description: "{{ $labels.job }} 服務已關閉"
具體告警規則:alert: 這是告警的名稱,在這個例子中命名為 "服務告警"。
expr: 這是觸發告警的表達式。在這個例子中,表達式 up == 0 檢查 up 指標是否等于 0。up 指標是 Prometheus 用來表示目標實例可達性的標準指標,其中 0 表示不可達,1 表示可達。
for: 這個條件指定了在觸發告警之前必須滿足告警條件的持續時間。在這里設置為 30s,意味著只有當 up 指標持續為 0 超過 30 秒時,才會觸發告警。
labels: 這部分定義了附加到告警上的標簽。在這個例子中,它設置了一個嚴重性標簽(severity: critical),表示這是一個嚴重的告警。
annotations:
這部分提供了關于告警的更多信息,通常用于在告警通知中顯示。在這個例子中,它包括兩個注解:
instance: "{{ $labels.instance }}":這將顯示觸發告警的實例。
description: "{{ $labels.job }} 服務已關閉":這提供了一個描述性的消息,指出哪個服務(job)已經關閉。
4.4 驗證配置
./promtool check config new_prometheus.yml

在這里插入圖片描述
重新熱加載配置

curl -X POST http://localhost:9070/-/reload

五、grafana 添加數據源

5.1 添加數據來源

這里填寫prometheus 的數據源地址,因為grafana 和 prometheus 放到一臺服務器上了,所以我填寫的是localhost
在這里插入圖片描述

5.2 添加dashboards,添加地址: https://grafana.com/grafana/dashboards/

選擇一個dashborads
在這里插入圖片描述
copy dashborads 的ID
在這里插入圖片描述
在grafana 界面導入dashborad ,可以通過ID導入
在這里插入圖片描述

最后選擇剛剛的數據源
在這里插入圖片描述

最終顯示
在這里插入圖片描述

六、配置gmail告警

6.1 打開gmail 配置

在這里插入圖片描述
點擊查看所有配置
在這里插入圖片描述

在這里插入圖片描述
最后保存

6.2 還需要打開二次驗證生成授權碼

在這里插入圖片描述
打開專用密碼
在這里插入圖片描述
創建一個自定義名稱的應用,這個授權碼,就是發送郵箱設置的密碼,會隨機生成一段字符串

七、通過alertmanager 配置郵箱告警

7.1 alertmanager.yml配置
global:# 全局配置smtp_smarthost: 'smtp.gmail.com:587'  # 指定SMTP服務器和端口,這里使用的是Gmail的SMTP服務器和587端口smtp_from: 'xuzan@lippu.ltd'          # 發送告警郵件時使用的發件人郵箱地址smtp_auth_username: 'xuzan@lippu.ltd' # SMTP認證時使用的用戶名,這里是郵箱地址smtp_auth_password: '二次認證上面生成auth密碼' # SMTP認證時使用的密碼route:# 路由配置group_by: ['critical','warning']   # 告警分組依據,這里按照 'server_alert' 標簽分組group_wait: 30s              # 分組后等待30秒,如果這段時間內有新的相同分組的告警則一起發送group_interval: 5m           # 分組告警發送間隔,即每5分鐘發送一次同一組的告警repeat_interval: 1h          # 重復告警發送間隔,即相同的告警每小時重復發送一次receiver: 'email-notifications' # 默認接收器,用于處理沒有匹配特定路由的告警routes:- match:severity: 'warning'     # 匹配規則,當告警級別為warning時receiver: 'email-notifications' # 使用此接收器處理告警group_by: ['warning']     # 告警分組依據,這里按照 'warning' 標簽分組- match:severity: 'critical'    # 匹配規則,當告警級別為critical時receiver: 'email-notifications' # 使用此接收器處理告警group_by: ['critical']    # 告警分組依據,這里按照 'critical' 標簽分組group_wait: 10s           # 分組后等待10秒,如果這段時間內有新的相同分組的告警則一起發送
receivers:# 接收器定義- name: 'email-notifications'     # 接收器名稱email_configs:- to: 'xuzan@lippu.ltd'       # 告警接收的郵箱地址send_resolved: true         # 告警解決后是否發送通知
7.2 prometheus.yml 修改
global:scrape_interval: 30s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 30s # Evaluate rules every 15 seconds. The default is every 1 minute.# 其他全局配置...scrape_configs:# Prometheus 自身的監控配置- job_name: "prometheus"static_configs:- targets: ["localhost:9070"]- job_name: 'node_widgets'scheme: https  # 使用 HTTPStls_config:insecure_skip_verify: true  # 忽略證書驗證static_configs:- targets: ['xxx:443']  # 替換為您的服務器 B 地址和端口metrics_path: '/prometheus/metrics'  # Node Exporter 的路徑- job_name: '正式服'scheme: https  # 使用 HTTPStls_config:insecure_skip_verify: true  # 忽略證書驗證static_configs:- targets: ['xxx.com:443']  # 替換為您的服務器 B 地址和端口metrics_path: '/v1/app/metrics'  # Node Exporter 的路徑- job_name: '測式服'scheme: http  # 使用 HTTPSstatic_configs:- targets: ['23.8323.373.2437:8063']  # 替換為您的服務器 B 地址和端口metrics_path: '/v1/app/metrics'  # Node Exporter 的路徑# Alertmanager configuration
alerting:alertmanagers:- static_configs:- targets:- localhost:9071# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:- "alert.yml"# 測試的#- "test_alert.yml"
7.3 報警配置

alert.yml 配置服務是否down機,內存,cpu和 磁盤使用告警

groups:- name: Prometheus alertrules:# 對任何實例超過30s無法聯系的情況發出警報- alert: 服務是否down機expr: up == 0for: 30slabels:severity: criticalannotations:instance: "{{ $labels.instance }}"description: "{{ $labels.job }} 服務down機了,緊急查看"# 內存使用率超過 80% 的告警- alert: 內存使用情況expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100 > 80for: 30slabels:severity: warningannotations:instance: "{{ $labels.instance }}"description: "內存使用率超過 80%,當前值:{{ $value }}%"# CPU 使用率超過 80% 的告警- alert: cpu使用情況expr: 100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80for: 30slabels:severity: criticalannotations:instance: "{{ $labels.instance }}"description: "CPU 使用率超過 80%,當前值:{{ $value }}%"# 磁盤使用率超過 80% 的告警- alert: 磁盤使用情況expr: (node_filesystem_size_bytes - node_filesystem_free_bytes) / node_filesystem_size_bytes * 100 > 80for: 30slabels:severity: warningannotations:instance: "{{ $labels.instance }}"description: "磁盤使用率超過 80%,當前值:{{ $value }}%"#  - name: myapp_alerts_down
#    rules:
#      - alert: 程序掛掉了(緊急查看)
#        expr: myapp_up == 1
#        for: 30s
#        labels:
#          severity: warning
#        annotations:
#          summary: "程序掉了 down,超過了30s了"
#          description: "instance {{ $labels.instance }} with job {{ $labels.job }}"
7.4 測試報警 test.alert
groups:- name: test_alertsrules:- alert: TestAlertexpr: vector(1)labels:severity: warning
7.5 告警模版也可以自定義,下面這個是官方的模版

https://raw.githubusercontent.com/prometheus/alertmanager/master/template/email.html

<!--
Style and HTML derived from https://github.com/mailgun/transactional-email-templatesThe MIT License (MIT)Copyright (c) 2014 MailgunPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{{ template "__subject" . }}</title>
<style>
/* -------------------------------------GLOBALA very basic CSS reset
------------------------------------- */
* {margin: 0;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;box-sizing: border-box;font-size: 14px;
}img {max-width: 100%;
}body {-webkit-font-smoothing: antialiased;-webkit-text-size-adjust: none;width: 100% !important;height: 100%;line-height: 1.6em;/* 1.6em * 14px = 22.4px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients *//*line-height: 22px;*/
}/* Let's make sure all tables have defaults */
table td {vertical-align: top;
}/* -------------------------------------BODY & CONTAINER
------------------------------------- */
body {background-color: #f6f6f6;
}.body-wrap {background-color: #f6f6f6;width: 100%;
}.container {display: block !important;max-width: 600px !important;margin: 0 auto !important;/* makes it centered */clear: both !important;
}.content {max-width: 600px;margin: 0 auto;display: block;padding: 20px;
}/* -------------------------------------HEADER, FOOTER, MAIN
------------------------------------- */
.main {background-color: #fff;border: 1px solid #e9e9e9;border-radius: 3px;
}.content-wrap {padding: 30px;
}.content-block {padding: 0 0 20px;
}.header {width: 100%;margin-bottom: 20px;
}.footer {width: 100%;clear: both;color: #999;padding: 20px;
}
.footer p, .footer a, .footer td {color: #999;font-size: 12px;
}/* -------------------------------------TYPOGRAPHY
------------------------------------- */
h1, h2, h3 {font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;color: #000;margin: 40px 0 0;line-height: 1.2em;font-weight: 400;
}h1 {font-size: 32px;font-weight: 500;/* 1.2em * 32px = 38.4px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients *//*line-height: 38px;*/
}h2 {font-size: 24px;/* 1.2em * 24px = 28.8px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients *//*line-height: 29px;*/
}h3 {font-size: 18px;/* 1.2em * 18px = 21.6px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients *//*line-height: 22px;*/
}h4 {font-size: 14px;font-weight: 600;
}p, ul, ol {margin-bottom: 10px;font-weight: normal;
}
p li, ul li, ol li {margin-left: 5px;list-style-position: inside;
}/* -------------------------------------LINKS & BUTTONS
------------------------------------- */
a {color: #348eda;text-decoration: underline;
}.btn-primary {text-decoration: none;color: #FFF;background-color: #348eda;border: solid #348eda;border-width: 10px 20px;line-height: 2em;/* 2em * 14px = 28px, use px to get airier line-height also in Thunderbird, and Yahoo!, Outlook.com, AOL webmail clients *//*line-height: 28px;*/font-weight: bold;text-align: center;cursor: pointer;display: inline-block;border-radius: 5px;text-transform: capitalize;
}/* -------------------------------------OTHER STYLES THAT MIGHT BE USEFUL
------------------------------------- */
.last {margin-bottom: 0;
}.first {margin-top: 0;
}.aligncenter {text-align: center;
}.alignright {text-align: right;
}.alignleft {text-align: left;
}.clear {clear: both;
}/* -------------------------------------ALERTSChange the class depending on warning email, good email or bad email
------------------------------------- */
.alert {font-size: 16px;color: #fff;font-weight: 500;padding: 20px;text-align: center;border-radius: 3px 3px 0 0;
}
.alert a {color: #fff;text-decoration: none;font-weight: 500;font-size: 16px;
}
.alert.alert-warning {background-color: #E6522C;
}
.alert.alert-bad {background-color: #D0021B;
}
.alert.alert-good {background-color: #68B90F;
}/* -------------------------------------INVOICEStyles for the billing table
------------------------------------- */
.invoice {margin: 40px auto;text-align: left;width: 80%;
}
.invoice td {padding: 5px 0;
}
.invoice .invoice-items {width: 100%;
}
.invoice .invoice-items td {border-top: #eee 1px solid;
}
.invoice .invoice-items .total td {border-top: 2px solid #333;border-bottom: 2px solid #333;font-weight: 700;
}/* -------------------------------------RESPONSIVE AND MOBILE FRIENDLY STYLES
------------------------------------- */
@media only screen and (max-width: 640px) {body {padding: 0 !important;}h1, h2, h3, h4 {font-weight: 800 !important;margin: 20px 0 5px !important;}h1 {font-size: 22px !important;}h2 {font-size: 18px !important;}h3 {font-size: 16px !important;}.container {padding: 0 !important;width: 100% !important;}.content {padding: 0 !important;}.content-wrap {padding: 10px !important;}.invoice {width: 100% !important;}
}
</style>
</head><body itemscope itemtype="https://schema.org/EmailMessage"><table class="body-wrap"><tr><td></td><td class="container" width="600"><div class="content"><table class="main" width="100%" cellpadding="0" cellspacing="0"><tr>{{ if gt (len .Alerts.Firing) 0 }}<td class="alert alert-warning">{{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for {{ range .GroupLabels.SortedPairs }}{{ .Name }}={{ .Value }}{{ end }}</td>{{ else }}<td class="alert alert-good">{{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for {{ range .GroupLabels.SortedPairs }}{{ .Name }}={{ .Value }} {{ end }}</td>{{ end }}</tr><tr><td class="content-wrap"><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="content-block"><a href='{{ template "__alertmanagerURL" . }}' class="btn-primary">View in {{ template "__alertmanager" . }}</a></td></tr>{{ if gt (len .Alerts.Firing) 0 }}<tr><td class="content-block"><strong>[{{ .Alerts.Firing | len }}] Firing</strong></td></tr>{{ end }}{{ range .Alerts.Firing }}<tr><td class="content-block"><strong>Labels</strong><br />{{ range .Labels.SortedPairs }}{{ .Name }} = {{ .Value }}<br />{{ end }}{{ if gt (len .Annotations) 0 }}<strong>Annotations</strong><br />{{ end }}{{ range .Annotations.SortedPairs }}{{ .Name }} = {{ .Value }}<br />{{ end }}<a href="{{ .GeneratorURL }}">Source</a><br /></td></tr>{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}{{ if gt (len .Alerts.Firing) 0 }}<tr><td class="content-block"><br /><hr /><br /></td></tr>{{ end }}<tr><td class="content-block"><strong>[{{ .Alerts.Resolved | len }}] Resolved</strong></td></tr>{{ end }}{{ range .Alerts.Resolved }}<tr><td class="content-block"><strong>Labels</strong><br />{{ range .Labels.SortedPairs }}{{ .Name }} = {{ .Value }}<br />{{ end }}{{ if gt (len .Annotations) 0 }}<strong>Annotations</strong><br />{{ end }}{{ range .Annotations.SortedPairs }}{{ .Name }} = {{ .Value }}<br />{{ end }}<a href="{{ .GeneratorURL }}">Source</a><br /></td></tr>{{ end }}</table></td></tr></table><div class="footer"><table width="100%"><tr><td class="aligncenter content-block"><a href='{{ .ExternalURL }}'>Sent by {{ template "__alertmanager" . }}</a></td></tr></table></div></div></td><td></td></tr>
</table></body>
</html>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/213567.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/213567.shtml
英文地址,請注明出處:http://en.pswp.cn/news/213567.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

女士內衣市場分析:預計2028年將達到643.08億美元

內衣 (英文名:Underwear)&#xff0c;是指貼身穿的衣物。內衣有保暖及污穢的危害作用&#xff0c;有時會被視為性征。女士內衣行業生產的主要原料是各類織布或無紡布&#xff0c;成分有海綿、邊、定型紗、骨膠、肩帶等&#xff0c;布面料在內衣企業的生產成本中所占比重較大。女…

Python基礎(四、探索迷宮游戲)

Python基礎&#xff08;四、探索迷宮游戲&#xff09; 游戲介紹游戲說明 游戲介紹 在這個游戲中&#xff0c;你將扮演一個勇敢的冒險者&#xff0c;進入了一個神秘的迷宮。你的任務是探索迷宮的每個房間&#xff0c;并最終找到隱藏在其中的寶藏。 游戲通過命令行界面進行交互…

web 前端之標簽練習+知識點

目錄 實現過程&#xff1a; 結果顯示 1、HTML語法 2、注釋標簽 3、常用標簽 4、新標簽 5、特殊標簽 6、在網頁中使用視頻和音頻、圖片 7、表格標簽 8、超鏈接標簽 使用HTML語言來實現該頁面 實現過程&#xff1a; <!DOCTYPE html> <html><head>…

泡沫包裝市場分析:預計2029年將達到659億元

泡沫包裝&#xff0c;簡單地講&#xff0c;就是用數學方法對無線電測量或光學測量所獲得的彈道數據進行檢驗、整理、校正、計算&#xff0c;減小或消除數據的誤差&#xff0c;得出反映運載火箭運動軌跡的精確彈道參數。通常所說的泡沫包裝&#xff0c;主要是指由可發性聚苯乙烯…

面試操作系統八股文五問五答第二期

面試操作系統八股文五問五答第二期 作者&#xff1a;程序員小白條&#xff0c;個人博客 相信看了本文后&#xff0c;對你的面試是有一定幫助的&#xff01; ?點贊?收藏?不迷路&#xff01;? 1.怎么解決死鎖&#xff1f; 1、預防死鎖&#xff1a;通過設置一些限制條件&am…

JAVA面試題8

1.Java中的線程是什么&#xff1f; 它有什么作用&#xff1f; 答案&#xff1a;線程是程序執行流的最小單位&#xff0c;用于實現多任務并發執行。Java中的線程可以實現并發編程&#xff0c;提高程序的性能和響應性。 2.什么是Java中的同步&#xff08;Synchronization&#x…

超靜音的兩相步進電機驅動芯片GC6609,GC6610的性能分析

兩相步進電機驅動芯片GC6609&#xff0c;GC6610它們是一款超靜音的兩相步進電機驅動芯片&#xff0c;內置最大 256 細分的步進驅動模式&#xff0c; 超靜音&#xff0c;低振動。芯片可以工作在 4~36V 的寬工作電壓范圍內&#xff0c;平均工作電流可以達到 2A和2.5A &#xff0c…

大數據機器學習算法項目——基于Django/協同過濾算法的房源可視化分析推薦系統的設計與實現

大數據機器學習算法項目——基于Django/協同過濾算法的房源可視化分析推薦系統的設計與實現 技術棧&#xff1a;大數據爬蟲/機器學習學習算法/數據分析與挖掘/大數據可視化/Django框架/Mysql數據庫 本項目基于 Django框架開發的房屋可視化分析推薦系統。這個系統結合了大數據…

STM32-01-認識單片機

文章目錄 一、單片機簡介二、Cortex-M系列介紹三、初識STM32四、STM32原理圖設計五、搭建開發環境六、STM32初體驗七、MDK5使用技巧 一、單片機簡介 單片機是什么&#xff1f; 單片機&#xff1a;Single-Chip Microcomputer&#xff0c;單片微型計算機&#xff0c;是一種集成電…

python獲得曲線峰值的個數

import numpy as np from scipy.signal import find_peaks import matplotlib.pyplot as plt# 生成示例數據 x np.linspace(0, 10, 100) y np.sin(x)# 查找峰值 peaks, _ find_peaks(y)# 繪制曲線和峰值點 plt.plot(x, y) plt.plot(x[peaks], y[peaks], ro)# 顯示峰值個數 n…

Golang channle(管道)基本介紹、快速入門

channel(管道)-基本介紹 為什么需要channel&#xff1f;前面使用全局變量加鎖同步來解決goroutine的通訊&#xff0c;但不完美 1)主線程在等待所有goroutine全部完成的時間很難確定&#xff0c;我們這里設置10秒&#xff0c;僅僅是估算。 2)如果主線程休眠時間長了&#xff0c…

【計算機網絡】HTTP響應報文Cookie原理

目錄 HTTP響應報文格式 一. 狀態行 狀態碼與狀態碼描述 二. 響應頭 Cookie原理 一. 前因 二. Cookie的狀態管理 結束語 HTTP響應報文格式 HTTP響應報文分為四部分 狀態行&#xff1a;包含三部分&#xff1a;協議版本&#xff0c;狀態碼&#xff0c;狀態碼描述響應頭&a…

如何選擇LED天幕屏的型號

隨著LED屏幕技術的不斷成熟&#xff0c;其應用范圍也日益擴大&#xff0c;從傳統的墻面固定安裝&#xff0c;到落地式、租賃移動式&#xff0c;再到LED互動地磚屏和安裝在天花板上的LED天幕屏等&#xff0c;安裝方式多種多樣。那么&#xff0c;在面對如此多元化的選擇時&#x…

PHP基礎 - 類型比較

在 PHP 中,作為一種弱類型語言,它提供了松散比較和嚴格比較兩種方式來比較變量的值和類型。 松散比較: 使用兩個等號(==)進行比較,只會比較變量的值,而不會考慮它們的數據類型。例如: $a = 5; // 整數 $b = 5; // 字符串if ($a == $b) {echo "相等"; // 輸…

C/C++ 編程規范總結

目錄 前言 一、編程規范的作用 二、規范的三種形式 三、規范的內容 1. 基本原則 原則1-1 原則1-2 原則1-3 原則1-4 原則1-5 原則1-6 原則1-7 2. 布局 規則2-1-1 規則2-1-2 規則2-1-3 規則2-1-4 規則2-1-5 規則2-1-6 規則2-2-1 規則2-2-2 規則2-2-3 建議2…

簡單聊聊使用lombok 的爭議

大家好&#xff0c;我是G探險者。 項目里&#xff0c;因為我使用了Lombok插件&#xff0c;然后代碼走查的時候被領導點名了。 我心想&#xff0c;這么好用的插件&#xff0c;為啥不推廣呢&#xff0c;整天寫那些煩人的setter&#xff0c;getter方法就不嫌煩么&#xff1f; 領導…

AidLux:手機/平板上的Linux環境與AI開發利器

AidLux是一個基于ARM架構的跨生態&#xff08;鴻蒙/AndroidLinux&#xff09;一站式智能物聯網&#xff08;AIoT&#xff09;應用開發和部署平臺&#xff0c;正受到越來越多開發者和用戶的青睞。既可以作為手機/平板上的一個Linux環境使用&#xff0c;也可以作為AI開發利器以發…

Python Django Suit:構建現代化的Django后臺管理

概要 Django Suit是一款為Django后臺管理提供現代、優雅界面的第三方應用&#xff0c;它致力于提升Django開發者的管理體驗。本文將深入介紹Django Suit的安裝、配置和高級功能&#xff0c;提供詳實的示例代碼&#xff0c;幫助大家更好地使用和定制Django后臺管理界面。 安裝與…

無法解除Word文檔限制編輯?上干貨

方法一&#xff1a;新建一個文檔-點擊“插入”-點擊“對象”-點擊選擇中的倒三角-然后選擇“文件中的文字”-找到相應文檔即可 具體操作界面如下圖這個方法會導致格式出現稍稍微的變化 方法二&#xff1a;將受編輯的文件另存為 文件類型一定要選擇*.xml 另存好之后是這樣的 打…

智能優化算法應用:基于法醫調查算法無線傳感器網絡(WSN)覆蓋優化 - 附代碼

智能優化算法應用&#xff1a;基于法醫調查算法無線傳感器網絡(WSN)覆蓋優化 - 附代碼 文章目錄 智能優化算法應用&#xff1a;基于法醫調查算法無線傳感器網絡(WSN)覆蓋優化 - 附代碼1.無線傳感網絡節點模型2.覆蓋數學模型及分析3.法醫調查算法4.實驗參數設定5.算法結果6.參考…