本文介绍: 接下来熟练操作k8s,我们采用搭建minikube来学习k8s。然后在altermanager里面配置相应的路由树。使用client–go通过代码创建资源。这一部分直接查看官方文档使用说明。通过kubectl创建资源。
前面三步主要根据https://blog.csdn.net/shnu_cdk/article/details/132182858?spm=1001.2014.3001.5506
package main
import (
"fmt"
"math/rand"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
// 创建并注册指标
counter := prometheus.NewCounter(prometheus.CounterOpts{
Name: "my_counter",
Help: "A counter metric",
})
prometheus.MustRegister(counter)
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "my_gauge",
Help: "A gauge metric",
})
prometheus.MustRegister(gauge)
histogram := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "my_histogram",
Help: "A histogram metric",
})
prometheus.MustRegister(histogram)
summary := prometheus.NewSummary(prometheus.SummaryOpts{
Name: "my_summary",
Help: "A summary metric",
})
prometheus.MustRegister(summary)
// 定期更新指标值
go func() {
for {
counter.Inc()
gauge.Set(rand.Float64() * 100)
histogram.Observe(rand.Float64() * 100)
summary.Observe(rand.Float64() * 100)
time.Sleep(time.Second)
}
}()
// 启动HTTP服务,暴露指标
http.Handle("/metrics", promhttp.Handler())
fmt.Println("Exporter is running on http://localhost:8080/metrics")
http.ListenAndServe(":8080", nil)
}
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'export'
static_configs:
- targets: ['192.168.60.177:8080']
labels:
instance: export
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['192.168.60.169:9093']
route:
group_by: ['alertname']
group_wait: 1s
group_interval: 1s
repeat_interval: 1h
receiver: 'web.hook'
receivers:
- name: 'web.hook'
webhook_configs:
- url: 'http://192.168.60.188:8093/demo'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
接下来熟练操作k8s,我们采用搭建minikube来学习k8s
主要熟悉以下两个方面:
原文地址:https://blog.csdn.net/qq_43458555/article/details/134727174
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_26964.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。