普罗米修斯(Prometheus)

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 一、普罗米修斯(Prometheus)是什么?
    • 1.下载Prometheus工具(切记和操作系统版本对应)
    • 2.解压命令
    • 3.修改prometheus.yml配置
    • 4.免密版(默认端口9090)
    • 4.加密版(默认端口9090)
  • 二、告警(Alertmanager)是什么?
    • 1.下载地址
    • 2.解压命令
    • 3.修改配置文件
    • 4.配置Alertmanager启动文件(默认端口9093)
  • 三、钉钉(dingtalk)是什么?
    • 1.下载地址:
    • 2.解压命令
    • 3.修改配置文件
    • 4.启动钉钉服务(默认端口8060)
  • 总结


一、普罗米修斯(Prometheus)是什么?

prometheus是由谷歌研发的一款开源的监控软件,它通过安装在远程机器上的exporter,通过HTTP协议从远程的机器收集数据并存储在本地的时序数据库上。目前已经被云计算本地基金会托管,是继k8s托管的第二个项目,号称是下一代监控。
普罗米修斯(Prometheus)_第1张图片

1.下载Prometheus工具(切记和操作系统版本对应)

下载地址:https://prometheus.io/download/

操作系统 版本
x86 prometheus-2.45.0.linux-amd64.tar.gz
linux prometheus-2.45.0.linux-amd64.tar.gz
window prometheus-2.45.0.windows-amd64.zip

2.解压命令

tar -zxvf prometheus-2.45.0.linux-amd64.tar.gz

普罗米修斯(Prometheus)_第2张图片

3.修改prometheus.yml配置

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration 告警信息服务配置,用来发送告警信息,敲黑板:很重要
alerting:
  alertmanagers:
    - static_configs:
        - targets:
           - 192.168.10.111:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
# 自定义规则,会获取指定目录下的所有规则配置文件
rule_files:
  - "rules/*.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=` 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: 'gateway'
    static_configs:
      - targets: ['192.168.10.111:11200']
  - job_name: 'eureka'
    static_configs:
      - targets: ['192.168.10.111:11300']
  - job_name: 'object'
    scrape_interval: 15s
    scrape_timeout: 10s
    metrics_path: '/object-library-api-service/actuator/prometheus'
    static_configs:
      - targets: ['192.168.10.111:11198']
  - job_name: 'sync'
    static_configs:
      - targets: ['192.168.10.111:11025']
# 监听服务信息,定义服务名称,暴露接口给普罗米修斯进行验证,配置指定的gargets信息
  - job_name: 'user'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['192.168.11.2:7777']
#  - job_name: 'alertmanager'
#    static_configs:
#      - targets: ['192.168.10.111:9093']

4.免密版(默认端口9090)

[Unit]
Description=prometheus

[Service]
Restart=on-failure
ExecStart=/longjin/prometheus/prometheus --config.file=/longjin/prometheus/prometheus.yml

4.加密版(默认端口9090)

[Unit]
Description=prometheus

[Service]
Restart=on-failure
ExecStart=/longjin/prometheus/prometheus --config.file=/longjin/prometheus/prometheus.yml --web.config.file=/longjin/prometheus/web.yml 

web.yml配置文件

basic_auth_users:
        # 密码生成地址:https://www.bejson.com/encrypt/bcrpyt_encode/,格式为 [ admin: 123456 ]
        admin: $2a$10$6TUBoDndlIkyTVimXSv7COac2fC9HpT4CCA7gnwNrvTRmkA0YURWO

check验证
在这里插入图片描述

二、告警(Alertmanager)是什么?

Alertmanager 主要用于接收 Prometheus 发送的告警信息,它支持丰富的告警通知渠道,而且很容易做到告警信息进行去重,降噪,分组等,是一款前卫的告警通知系统。

1.下载地址

下载地址:https://prometheus.io/download/

2.解压命令

tar -zxvf alertmanager-0.26.0.linux-amd64.tar.gz

普罗米修斯(Prometheus)_第3张图片

3.修改配置文件

route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 1h
  receiver: 'dingding.alertname'
receivers:
# 配置调用钉钉服务接口,用来推送消息
  - name: 'dingding.alertname'
    webhook_configs:
      - url: 'http://192.168.10.111:8060/dingtalk/alertname/send'
        send_resolved: true
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

4.配置Alertmanager启动文件(默认端口9093)

[Unit]
Description=alertmanager

[Service]
Restart=on-failure
ExecStart=/longjin/prometheus/alert/alertmanager --config.file=/longjin/prometheus/alert/alertmanager.yml --storage.path=/longjin/prometheus/alert/data/

三、钉钉(dingtalk)是什么?

钉钉(DingTalk)是阿里巴巴集团专为中国企业打造的免费沟通和协同的多端平台,提供PC版,Web版,Mac版和手机版,支持手机和电脑间文件互传。

1.下载地址:

下载地址:https://github.com/timonwong/prometheus-webhook-dingtalk/releases

2.解压命令

tar -zxvf prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz

普罗米修斯(Prometheus)_第4张图片

3.修改配置文件

cp一份配置文件出来,切记改成你们自己钉钉机器人的配置。查看钉钉机器人基本信息就可以了

## Request timeout
timeout: 5s

## Uncomment following line in order to write template from scratch (be careful!)
#no_builtin_template: true

## Customizable templates path
templates:
 - contrib/templates/legacy/template.tmpl

## You can also override default template using `default_message`
## The following example to use the 'legacy' template from v0.3.0
#default_message:
#  title: '{{ template "legacy.title" . }}'
#  text: '{{ template "legacy.content" . }}'

## Targets, previously was known as "profiles"
targets:
  alertname:
    url: https://oapi.dingtalk.com/robot/send?access_token=0145833c0ef253ac16cf0c65284b312548a6f2b35d630400a85584b00e860e
    # secret for signature
    secret: SECbb5316787dc845ec6d93f36ba4b186ed642d3e9267cfd702fce8961cbe26a
    mention:
      mobiles: ['178****3721']
  webhook1:
    url: https://oapi.dingtalk.com/robot/send?access_token=0145833c0ef253ac16cf0c65284b312548a6f2b35d630400a85584b00e860e
    # secret for signature
    secret: SECbb5316787dc845ec6d93f36ba4b186ed642d3e9267cfd702fce8961cbe26a
  webhook2:
    url: https://oapi.dingtalk.com/robot/send?access_token=0145833c0ef253ac16cf0c65284b312548a6f2b35d630400a85584b00e860e
  webhook_legacy:
    url: https://oapi.dingtalk.com/robot/send?access_token=0145833c0ef253ac16cf0c65284b312548a6f2b35d630400a85584b00e860e
    # Customize template content
    message:
      # Use legacy template
      title: '{{ template "legacy.title" . }}'
      text: '{{ template "legacy.content" . }}'
  webhook_mention_all:
    url: https://oapi.dingtalk.com/robot/send?access_token=0145833c0ef253ac16cf0c65284b312548a6f2b35d630400a85584b00e860e
    secret: SECbb5316787dc845ec6d93f36ba4b186ed642d3e9267cfd702fce8961cbe26a
    mention:
      all: true
  webhook_mention_users:
    url: https://oapi.dingtalk.com/robot/send?access_token=0145833c0ef253ac16cf0c65284b312548a6f2b35d630400a85584b00e860e
    mention:
      mobiles: ['178****3721']

4.启动钉钉服务(默认端口8060)

[Unit]
Description=dingtalk

[Service]
Restart=on-failure
WorkingDirectory=/longjin/prometheus/dingtalk
ExecStart=/longjin/prometheus/dingtalk/prometheus-webhook-dingtalk --config.file=/longjin/prometheus/dingtalk/config.yml
[Install]
WantedBy=multi-user.target

总结

人生物语:自己不努力上进,何来的得心应手?不是娇靥,就可以有馥郁的芳香;不是有刀戟就可以百战百胜。你不是急流,不能湍飞;你不是花儿,你没有自带的芳香;你不是海洋,不可海纳百川。

你可能感兴趣的:(prometheus)