基本アーキテクチャ
Prometheus は SoundCloud によってリリースされ、go 言語で開発されたオープンソースのモニタリング、アラーム、時系列データベースを組み合わせたものです。
Prometheus の基本原理は、HTTP プロトコルを通じて監視対象のコンポーネントのステータスを定期的に取得することであり、対応する HTTP インターフェースを提供する限り、どのコンポーネントにもアクセスして監視できます。SDK やその他の統合プロセスは必要ありません。これは、VM、Docker、Kubernetes などの仮想化環境監視システムに非常に適しています。
Prometheus の主なコンポーネントの機能は次のとおりです。
- Prometheus サーバー: サーバーの主な役割は、静的に構成されたターゲットまたはサービス検出ターゲット (主に DNS、consul、k8s、mesos など) から定期的にデータを取得することです。
- エクスポーター: 主にプロメテウス サーバーへのデータのレポートを担当します。異なるデータ レポートは異なるエクスポータによって実装されます。たとえば、監視ホストにはノード エクスポータがあり、mysql には MySQL サーバー エクスポータがあります。
- プッシュゲートウェイ: Prometheus は、対応するエクスポーターにプルしてデータを取得するだけでなく、最初にサービスをプッシュゲートウェイにプッシュさせ、次にサーバーがプッシュゲートウェイに移動してデータをプルすることによってもデータを取得できます。
- Alertmanager: prometheus のアラーム機能を実装します。
- webui: webui 表示は主に grafana を通じて実装されます。
実際に使用する際の基本的なプロセスは次のとおりです。
各サービスが監視データを対応するインジケーター (後述のエクスポーターなど) にプッシュします --> Prometheus Server が定期的にデータを収集し、保存します --> Grafana を設定してデータを表示し、アラーム ルールを設定します アラーム
Helm が Prometheus プラットフォームをデプロイ
Helm を使用して kube-prometheus-stack をデプロイします
helm アドレス:ポータル
github アドレス:ポータル
まず、サーバーに Helm ツールをインストールする必要があります。インストール方法の詳細については説明しませんが、インターネット上には多くのチュートリアルがあります。Helm を使用して prometheus をインストールする具体的な操作は次のとおりです。
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install [RELEASE_NAME] prometheus-community/kube-prometheus-stack
輸出者
ターゲット監視データを収集するには、まずターゲットの場所に収集コンポーネントをインストールする必要があります。この収集コンポーネントはエクスポータと呼ばれます。prometheus.io 公式 Web サイトには、公式エクスポーター リストを含め、そのようなエクスポーターが多数あります。
収集後にPrometheusに転送するにはどうすればよいですか?
エクスポーターは HTTP インターフェイスを公開し、プロメテウスはプル モードを通じてデータをプルし、HTTP プロトコルを通じて監視対象のコンポーネント データを定期的にキャプチャします。
ただし、prometheus はプッシュ モードをサポートする方法も提供しており、データをプッシュ ゲートウェイにプッシュすることができ、プロメテウスはプルを通じてプッシュ ゲートウェイからデータを取得します。
Golang アプリケーションのコレクション コンポーネントにアクセスする
クレイトスフレームワーク
Prometheus コレクション コンポーネントをマイクロサービス フレームワーク kratos に接続する例、kratos 公式チュートリアル:
package main
import (
"context"
"fmt"
"log"
prom "github.com/go-kratos/kratos/contrib/metrics/prometheus/v2"
"github.com/go-kratos/kratos/v2/middleware/metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/go-kratos/examples/helloworld/helloworld"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/transport/grpc"
"github.com/go-kratos/kratos/v2/transport/http"
"github.com/prometheus/client_golang/prometheus"
)
// go build -ldflags "-X main.Version=x.y.z"
var (
// Name is the name of the compiled software.
Name = "metrics"
// Version is the version of the compiled software.
// Version = "v1.0.0"
_metricSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "server",
Subsystem: "requests",
Name: "duration_sec",
Help: "server requests duration(sec).",
Buckets: []float64{
0.005, 0.01, 0.025, 0.05, 0.1, 0.250, 0.5, 1},
}, []string{
"kind", "operation"})
_metricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "client",
Subsystem: "requests",
Name: "code_total",
Help: "The total number of processed requests",
}, []string{
"kind", "operation", "code", "reason"})
)
// server is used to implement helloworld.GreeterServer.
type server struct {
helloworld.UnimplementedGreeterServer
}
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) {
return &helloworld.HelloReply{
Message: fmt.Sprintf("Hello %+v", in.Name)}, nil
}
func init() {
prometheus.MustRegister(_metricSeconds, _metricRequests)
}
func main() {
grpcSrv := grpc.NewServer(
grpc.Address(":9000"),
grpc.Middleware(
metrics.Server(
metrics.WithSeconds(prom.NewHistogram(_metricSeconds)),
metrics.WithRequests(prom.NewCounter(_metricRequests)),
),
),
)
httpSrv := http.NewServer(
http.Address(":8000"),
http.Middleware(
metrics.Server(
metrics.WithSeconds(prom.NewHistogram(_metricSeconds)),
metrics.WithRequests(prom.NewCounter(_metricRequests)),
),
),
)
httpSrv.Handle("/metrics", promhttp.Handler())
s := &server{
}
helloworld.RegisterGreeterServer(grpcSrv, s)
helloworld.RegisterGreeterHTTPServer(httpSrv, s)
app := kratos.New(
kratos.Name(Name),
kratos.Server(
httpSrv,
grpcSrv,
),
)
if err := app.Run(); err != nil {
log.Fatal(err)
}
}
最後に、http://127.0.0.1:8000/metrics
Prometheus が監視データを取得できる HTTP インターフェイスが公開されます。
ジンフレームワーク
Prometheus コレクション コンポーネントを軽量 HTTP フレームワーク Gin に接続する例:
package main
import (
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
handler = promhttp.Handler()
_metricSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "server",
Subsystem: "requests",
Name: "duration_sec",
Help: "server requests duration(sec).",
Buckets: []float64{
0.005, 0.01, 0.025, 0.05, 0.1, 0.250, 0.5, 1},
}, []string{
"method", "path"})
_metricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "client",
Subsystem: "requests",
Name: "code_total",
Help: "The total number of processed requests",
}, []string{
"method", "path", "code"})
)
func init() {
prometheus.MustRegister(_metricSeconds, _metricRequests)
}
func HandlerMetrics() func(c *gin.Context) {
return func(c *gin.Context) {
handler.ServeHTTP(c.Writer, c.Request)
}
}
func WithProm() gin.HandlerFunc {
return func(c *gin.Context) {
var (
method string
path string
code int
)
startTime := time.Now()
method = c.Request.Method
path = c.Request.URL.Path
c.Next()
code = c.Writer.Status()
_metricSeconds.WithLabelValues(method, path).Observe(time.Since(startTime).Seconds())
_metricRequests.WithLabelValues(method, path, strconv.Itoa(code)).Inc()
}
}
func main() {
r := gin.Default()
r.Use(WithProm())
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.GET("/metrics", HandlerMetrics())
r.Run() // 监听并在 0.0.0.0:8080 上启动服务
}
最後に、http://127.0.0.1:8080/metrics
Prometheus が監視データを取得できる HTTP インターフェイスが公開されます。
クラスターから外部データソースをフェッチする
背景: 1 つはサーバーとサービスを監視するために既存の K8s クラスターに
helm
デプロイされましたkube-prometheus-stack
。これで、k8s クラスター内のノード、ポッド、およびその他のコンポーネントが prometheus に接続されました。k8s クラスターの外部にデプロイされた他のアプリケーション サービスを prometheus に接続することも必要です。
prometheus が k8s クラスターの外部でデータをキャプチャする場合、次の方法があります。
- サービスモニター
- 追加のスクレイピング構成
サービスモニター
ServiceMonitor は、Prometheus がクロールするサービス エンドポイントとクロール間隔を定義する CRD です。
ServiceMonitor を通じてクラスター外のサービスを監視するには、サービス、エンドポイント、および ServiceMonitor を構成する必要があります。
192.168.1.100:8000
バックエンド サービスがデプロイされ、/metrics
監視メトリクスを通じて公開されました。Prometheus に接続してみます。具体的な操作は次のとおりです。
コマンドラインに入力してください
$ touch external-application.yaml
$ vim external-application.yaml
次に、次の yaml ファイルの内容をコピーします。
---
apiVersion: v1
kind: Service
metadata:
name: external-application-exporter
namespace: monitoring
labels:
app: external-application-exporter
app.kubernetes.io/name: application-exporter
spec:
type: ClusterIP
ports:
- name: metrics
port: 9101
protocol: TCP
targetPort: 9101
---
apiVersion: v1
kind: Endpoints
metadata:
name: external-application-exporter
namespace: monitoring
labels:
app: external-application-exporter
app.kubernetes.io/name: application-exporter
subsets:
- addresses:
- ip: 192.168.1.100 # 这里是外部的资源列表
ports:
- name: metrics
port: 8000
- addresses:
- ip: 192.168.1.100 # 这里是外部的资源列表2
ports:
- name: metrics
port: 8080
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: external-application-exporter
namespace: monitoring
labels:
app: external-application-exporter
release: prometheus
spec:
selector:
matchLabels: # Service选择器
app: external-application-exporter
namespaceSelector: # Namespace选择器
matchNames:
- monitoring
endpoints:
- port: metrics # 采集节点端口(svc定义)
interval: 10s # 采集频率根据实际需求配置,prometheus默认10s
path: /metrics # 默认地址/metrics
ファイルを保存した後、次のコマンドを実行します。
kubectl apply -f external-application.yaml
次に、prometheus コンソールを開き、Targets ディレクトリに入ります。新しい external-application-exporter が表示されていることがわかります。
追加のスクレイピング構成
ip plus port によって提供される HTTP サービスに加えて、ドメイン名を介してアクセスできる他のサーバーにも HTTPS サービスを展開しました。今度は同じ方法で接続したいと思います。
まずそれを変更してみて、 k8s の公式ドキュメントをEndpoints
探してみると、それがサポートしているだけで、プロトコルを設定する場所がないことがわかりました。そこで、別のアプローチを試してみましょう。Endpoints
ip
HTTPS
最初の方法
まず、公式ドキュメントを確認し、 prometheus クローリング設定に関する箇所を見つけます。キーワードが prometheus クローリング設定であることがわかります。scrape_config
今回のプロメテウスは、helm 経由でkube-prometheus-stack
コマンドを入力します:
$ cat values.yaml | grep -C 20 scrape_config
次の結果が得られます。
コメントからわかるように、kube-prometheus はAdditionalScrapeConfigs を通じてクローリング戦略を構成します。
そこで、helm がデプロイした prometheus のリリースを更新するための構成ファイルを作成しました。
$ touch prometheus.yml
$ vim prometheus.yml
次の内容を書きます。
prometheus:
prometheusSpec:
additionalScrapeConfigs:
- job_name: external-application-exporter-https
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ["www.baidu.com:443"]
最終更新リリース:
$ helm upgrade -nmonitoring -f prometheus.yaml prometheus kube-prometheus-stack-40.0.0.tgz
prometheus.yaml
更新されたリリースを使用します。これは、 kube-prometheus-stack-40.0.0.tgz
prometheus をデプロイするときにローカルにヘルムプルしたチャートファイルです。
新しく追加されたデータ ソースは、prometheus コンソールの Targets ディレクトリに表示されます。
実際にはここで終了することもできますが、欠点の 1 つは、監視用に新しいドメイン名が追加されるたびに、helm のリリースを再度更新する必要があり、特に便利ではないことです。
2番目の方法
prometheus-operator のソース コードを調べてみると、説明の中に、構成のホット アップデートのキャプチャに関するチュートリアルがあることがわかりました。簡単にまとめると、シークレットを設定することで、prometheus によってキャプチャされたデータ ソースを制御します。シークレットの内容が変更されると、プロメテウスのフェッチ構成をホット アップデートできます。スクリーンショットを撮って確認してください。
最初のステップはprometheus-additional.yaml
ファイルを生成することです
$ touch prometheus-additional.yaml
$ vim prometheus-additional.yaml
prometheus-additional.yaml
コンテンツ:
- job_name: external-application-exporter-https
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ["www.baidu.com:443"]
2 番目のステップはシークレットを生成することです
シークレットの作成に使用する構成ファイルを生成します。
$ kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run=client -oyaml > additional-scrape-configs.yaml
$ cat additional-scrape-configs.yaml
生成されたコンテンツは次のようにして確認できますadditional-scrape-configs.yaml
。
apiVersion: v1
data:
prometheus-additional.yaml: LSBqb2JfbmFtZTogZXh0ZXJuYWwtYXBwbGljYXRpb24tZXhwb3J0ZXItaHR0cHMKICBzY3JhcGVfaW50ZXJ2YWw6IDEwcwogIHNjcmFwZV90aW1lb3V0OiAxMHMKICBtZXRyaWNzX3BhdGg6IC9tZXRyaWNzCiAgc2NoZW1lOiBodHRwcwogIHRsc19jb25maWc6CiAgICBpbnNlY3VyZV9za2lwX3ZlcmlmeTogdHJ1ZQogIHN0YXRpY19jb25maWdzOgogICAgLSB0YXJnZXRzOiBbImNpYW10ZXN0LnNtb2EuY2M6NDQzIl0K
kind: Secret
metadata:
creationTimestamp: null
name: additional-scrape-configs
このコードをデコードして内容を見てください。
$ echo "LSBqb2JfbmFtZTogZXh0ZXJuYWwtYXBwbGljYXRpb24tZXhwb3J0ZXItaHR0cHMKICBzY3JhcGVfaW50ZXJ2YWw6IDEwcwogIHNjcmFwZV90aW1lb3V0OiAxMHMKICBtZXRyaWNzX3BhdGg6IC9tZXRyaWNzCiAgc2NoZW1lOiBodHRwcwogIHRsc19jb25maWc6CiAgICBpbnNlY3VyZV9za2lwX3ZlcmlmeTogdHJ1ZQogIHN0YXRpY19jb25maWdzOgogICAgLSB0YXJnZXRzOiBbImNpYW10ZXN0LnNtb2EuY2M6NDQzIl0K" | base64 -d
得る:
- job_name: external-application-exporter-https
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ["www.baidu.com:443"]
構成ファイルが正しく生成されたことを確認し、シークレットを生成できます。
$ kubectl apply -f additional-scrape-configs.yaml -n monitoring
Monitoring は prometheus がデプロイされる名前空間であり、同じ名前空間に配置します。
シークレットが生成されたことを確認します。
$ kubectl get secret -n monitoring
出力:
最後にCRDを変更します。
最後に、prometheus.yaml CRD でこの追加構成を参照します。
公式ドキュメントでは、prometheus の構成を変更することができます。
まず、prometheus の CRD を見つけます。
$ kubectl get prometheus -n monitoring
NAME VERSION REPLICAS AGE
prometheus-kube-prometheus-prometheus v2.38.0 1 2d18h
それを修正してください
$ kubectl edit prometheus prometheus-kube-prometheus-prometheus -n monitoring
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
labels:
prometheus: prometheus
spec:
...
additionalScrapeConfigs:
name: additional-scrape-configs
key: prometheus-additional.yaml
...
最後に、prometheus コンソールで効果を確認してください:
ドメイン名サービスが監視されました。将来他のドメイン名監視を追加したい場合は、シークレットを変更するだけです。素晴らしいです! !!
警報
アラームに関しては、prometheus+alertmanager ソリューションを使用します。アラーム情報の監視からアラーム イベントの処理までの主なプロセスは次のとおりです。
私たちのビジネス要件は、サービスがダウンしたときに通知を受け取り、タイムリーに対処することです。したがって、ここで設定する必要があるアラーム ルールは、アプリケーションの生存情報を収集することであり、非生存状態が検出された場合、アラーム メッセージのステータスは に設定されますpeding
。firing
ペーディング継続時間が特定の時間しきい値に達すると、アラームがトリガーされるように設定されており、アラーム情報alertmanager
は AlertManager に送信され、ルールに従ってアラーム メッセージが消息接收者
Qiwei、DingTalk、電子メールなどに送信されます。
具体的な方法は以下のとおりです。
ステップ 1 プロメテウスアラームトリガー
helm でデプロイしたのでkube-prometheus-stack
、バージョンの整合性を保つために、事前に chart: をローカルにkube-prometheus-stack-40.0.0.tgz
ダウンロード ( ) しておきました。helm pull prometheus-community/kube-prometheus-stack --version=40.0.0
解凍後、次の関連エントリkube-prometheus-stack
が にあります。values.yaml
PrometheusRules
## Deprecated way to provide custom recording or alerting rules to be deployed into the cluster.
##
# additionalPrometheusRules: []
# - name: my-rule-file
# groups:
# - name: my_group
# rules:
# - record: my_record
# expr: 100 * my_record
## Provide custom recording or alerting rules to be deployed into the cluster.
##
#additionalPrometheusRulesMap: {}
# rule-name:
# groups:
# - name: my_group
# rules:
# - record: my_record
# expr: 100 * my_record
変更values.yaml
:
## Deprecated way to provide custom recording or alerting rules to be deployed into the cluster.
##
# additionalPrometheusRules: []
# - name: my-rule-file
# groups:
# - name: my_group
# rules:
# - record: my_record
# expr: 100 * my_record
## Provide custom recording or alerting rules to be deployed into the cluster.
##
additionalPrometheusRulesMap:
rule-name:
groups:
- name: Instance
rules:
# Alert for any instance that is unreachable for >5 minutes.
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: "Instance {
{ $labels.instance }} down"
description: "{
{ $labels.instance }} of job {
{ $labels.job }} has been down for more than 5 minutes."
次に Helm リリースを更新します
helm upgrade -nmonitoring prometheus --values=values.yaml ../kube-prometheus-stack-40.0.0.tgz
更新が完了したら、prometheus コンソールで結果を確認します:設定が成功した
ことがわかります。アラーム ルールに従って、インスタンスのステータスが でないalert rules
限り、アラート ステータスはそれに応じて peding に変更されます。 5 分経過しても回復しない場合は、ステータスが「起動」に変わり、アラーム メッセージが表示されます。up == 0
ステップ 2 アラートマネージャーのアラーム通知
Prometheus トリガーがアラーム メッセージを収集した後、統合管理のためにアラート マネージャーに送信されます。alertmanager は、アラート メッセージをさまざまな受信者に配布するための特定のルールを構成します。
で次のkube-prometheus-stack
関連エントリを見つけます。特定の構成をカスタマイズできるように、指定された構成が提供されています。元の構成は次のとおりです。values.yaml
alertmanager.config
alertmanager.config
altermanager
receivers
## Configuration for alertmanager
## ref: https://prometheus.io/docs/alerting/alertmanager/
##
alertmanager:
...
## Alertmanager configuration directives
## ref: https://prometheus.io/docs/alerting/configuration/#configuration-file
## https://prometheus.io/webtools/alerting/routing-tree-editor/
##
config:
global:
resolve_timeout: 5m
inhibit_rules:
- source_matchers:
- 'severity = critical'
target_matchers:
- 'severity =~ warning|info'
equal:
- 'namespace'
- 'alertname'
- source_matchers:
- 'severity = warning'
target_matchers:
- 'severity = info'
equal:
- 'namespace'
- 'alertname'
- source_matchers:
- 'alertname = InfoInhibitor'
target_matchers:
- 'severity = info'
equal:
- 'namespace'
route:
group_by: ['namespace']
group_wait: 30s
group_interval: 5m
repeat_interval: 12h
receiver: 'null'
routes:
- receiver: 'null'
matchers:
- alertname =~ "InfoInhibitor|Watchdog"
receivers:
- name: 'null'
templates:
- '/etc/alertmanager/config/*.tmpl'
これを次のように変更します。
## Configuration for alertmanager
## ref: https://prometheus.io/docs/alerting/alertmanager/
##
alertmanager:
...
## Alertmanager configuration directives
## ref: https://prometheus.io/docs/alerting/configuration/#configuration-file
## https://prometheus.io/webtools/alerting/routing-tree-editor/
##
config:
global:
resolve_timeout: 5m
inhibit_rules:
- source_matchers:
- 'severity = critical'
target_matchers:
- 'severity =~ warning|info'
equal:
- 'namespace'
- 'alertname'
- source_matchers:
- 'severity = warning'
target_matchers:
- 'severity = info'
equal:
- 'namespace'
- 'alertname'
- source_matchers:
- 'alertname = InfoInhibitor'
target_matchers:
- 'severity = info'
equal:
- 'namespace'
route:
group_by: ['instance']
group_wait: 30s
group_interval: 5m
repeat_interval: 12h
receiver: 'wx-webhook'
routes:
receivers:
- name: 'wx-webhook'
webhook_configs:
- url: "http://wx-webhook:80/adapter/wx"
send_resolved: true
templates:
- '/etc/alertmanager/config/*.tmpl'
その中のアドレスwebhook_configs[0].url: "http://wx-webhook:80/adapter/wx"
は、アラームメッセージを受信するエンタープライズ WeChat グループ ロボット Webhook であり、エンタープライズ WeChat グループ ロボット Webhook の確立については次に詳しく説明します。
次に Helm リリースを更新します
helm upgrade -nmonitoring prometheus --values=values.yaml ../kube-prometheus-stack-40.0.0.tgz
構成が完了したら、サービスをオフにして、エンタープライズ WeChat グループで結果を表示します。
ステップ 3: エンタープライズ WeChat グループ ロボット Webhook を構築する
Qiwei ロボットを生成する
グループ設定で、グループロボット機能を入力します。次に、グループロボットを追加し、
追加されたグループロボットのWebhook
アドレスをコピーします。
deployment
設定ファイルを書き込みますwx-webhook-deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wx-webhook
labels:
app: wx-webhook
spec:
replicas: 1
selector:
matchLabels:
app: wx-webhook
template:
metadata:
labels:
app: wx-webhook
spec:
containers:
- name: wx-webhook
image: guyongquan/webhook-adapter:latest
imagePullPolicy: IfNotPresent
args: ["--adapter=/app/prometheusalert/wx.js=/wx=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxxxxxxxxxxx"]
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: wx-webhook
labels:
app: wx-webhook
spec:
selector:
app: wx-webhook
ports:
- name: wx-webhook
port: 80
protocol: TCP
targetPort: 80
nodePort: 30904
type: NodePort
内容は、args: ["--adapter=/app/prometheusalert/wx.js=/wx=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxxxxxxxxxxx"]
前の手順で作成した Qiwei ロボットWebhook
のアドレスです。
次に、次のコマンドを実行します。
$ kubectl apply -f wx-webhook-deployment.yaml -nmonitoring
$ kubectl get pod -n monitoring | grep wx-webhook
wx-webhook-78d4dc95fc-9nsjn 1/1 Running 0 26d
$ kubectl get service -n monitoring | grep wx-webhook
wx-webhook NodePort 10.106.111.183 <none> 80:30904/TCP 27d
このようにして、エンタープライズ WeChat グループ ロボット Webhook の確立が完了します。
ここでは、アラート メッセージの受信者として Enterprise WeChat を使用しており、alertmanager は他のメッセージ受信者もサポートしています。この記事を参照してください: kube-promethues 監視アラームの詳細な説明 (電子メール、DingTalk、WeChat、Qiwei Robot、自己研究プラットフォーム)
発生した問題
- キャプチャ構成シークレットを更新した後、prometheus コンソールに効果が見られません。
ポッドを再起動してみてください:prometheus-prometheus-kube-prometheus-prometheus-0
、エラー:
ts=2023-07-29T09:30:54.188Z caller=main.go:454 level=error msg=「設定のロード中にエラーが発生しました (–config.file=/etc/prometheus/config_out/prometheus.env.yaml)」 file= /etc/prometheus/config_out/prometheus.env.yaml err=「YAML ファイルを解析中です /etc/prometheus/config_out/prometheus.env.yaml: ジョブ名「external-application-exporter-」のスクレイピング構成のスクレイピング タイムアウトがスクレイピング間隔を超えています。 https””
その理由は、カスタム インジケーターの設定エラーにより prometheus の起動に失敗し、scrape_interval とscrape_timeout に問題があるためです。
- job_name: external-application-exporter-https
scrape_interval: 10s
scrape_timeout: 30s
metrics_path: /metrics
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ["www.baidu.com:443"]
に変更する必要があります
- job_name: external-application-exporter-https
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ["www.baidu.com:443"]
引用
- Grafana とプロメテウスを始める
- Prometheus モニタリング + Grafana + Alertmanager アラームのインストールと使用 (詳細な画像とテキストの説明)
- プロメテウス公式チュートリアル
- Helm リポジトリ
- kube-prometheus プロジェクトの Github アドレス
- クレイトス公式チュートリアル
- K8sの公式ドキュメント
- prometheus-operatorのソースコード
- kube-prometheus-stack アラーム設定
- kube-prometheus-stack で AlertManager を構成する
- エンタープライズ WeChat ロボットを介したプロメテウス アラーム
- kube-promethuesの監視と警報の詳細な説明(電子メール、DingTalk、WeChat、Qiwei Robot、自己研究プラットフォーム)