1. 安装运行prometheusgrafana
  2. 编辑prometheus配置文件,增加采集prometheus自身数据的采集规则
  3. grafana导入prometheus相关图表dashboard

前面三步主要根据https://blog.csdn.net/shnu_cdk/article/details/132182858?spm=1001.2014.3001.5506

  1. 用Go编写一个prometheus exporter包含prometheus四种指标类型

这一部分直接查看官方文档使用说明

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)
}

  1. prometheus能够正常采集第四步中的exporter,并在grafana展示
    yml配置文件上配置相对应的端口,这一部分和配置一个node差不多:
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
  1. 了解alertmanager知道alertmanagerwebhook推送告警方式
    主要是要在prometheus上配置相应的端口
# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets: ['192.168.60.169:9093']

然后在altermanager里面配置相应的路由

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
主要熟悉以下两个方面:

  1. 通过kubectl创建资源

  2. 使用client-go通过代码创建资源
    https://blog.51cto.com/daixuan/5184509

原文地址:https://blog.csdn.net/qq_43458555/article/details/134727174

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_26964.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注