首页 > 其他分享 >搭建prometheus监控系统

搭建prometheus监控系统

时间:2023-06-01 10:22:46浏览次数:40  
标签:__ http grafana prometheus 监控 docker config 搭建

搭建prometheus监控系统

安装prometheus

sudo mkdir /docker/compose/prometheus -p
cd /docker/compose/prometheus
touch docker-compose.yml
#如果复制换行错误
:set paste
version: '3.7'
services:
   prometheus:
      image: prom/prometheus:latest
      container_name: prometheus
      restart: on-failure:1
      ports:
         - "9090:9090"
      volumes:
         - /docker/config/prometheus/:/etc/prometheus/
      command:
            - '--config.file=/etc/prometheus/prometheus.yml'
            - '--web.enable-admin-api'
            - '--web.enable-lifecycle'

创建配置文件

cd /docker/config/prometheus
touch 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:
          - 127.0.0.1:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
    - "rules/*.yml"
  # - "first_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=<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: "service_status_http"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    http_sd_configs:
      - url: http://127.0.0.1:5220/api/Monitor/GetMonitorServiceTargets
        
  - job_name: "service_status_https"
    scheme: https
    http_sd_configs:
      - url: http://127.0.0.1:5220/api/Monitor/GetMonitorServiceTargets?scheme=https     
     
     
  - job_name: 'http_status'  # 配置job名
    metrics_path: /probe     # 定义metric获取的路径
    params:
      module: [http_2xx]     # 这里就是我们在black_exporter中定义的模块名
    #file_sd_configs:         # 因需要监控的地址很多,我们这里将所有地址独立出来,后面会介绍该文件
    #  - files: 
    #    - '/etc/prometheus/job_web.yaml'
    #    refresh_interval: 30s # 30秒刷新一次,当有新的监控地址时,会自动加载进来不需要重启
    http_sd_configs:
      - url: http://127.0.0.1:5220/api/Monitor/GetMonitorSiteTargets
    relabel_configs:
      - source_labels: [__address__]  # 当前target的访问地址,比如监控百度则为 https://baidu.com
        target_label: __param_target  # __param是默认参数前缀,target为参数,这里可以理解为把__address__ 的值赋给__param_target,若监控百度,则target=https://baidu.com
      - source_labels: [__param_target]
        target_label: instance        # 可以理解为把__param_target的值赋给instance标签
      - target_label: __address__
        replacement: 127.0.0.1:9115 # web监控原本的target为站点的地址,但Prometheus不是直接去请求该地址,而是去请求black_exporter,故需要把目标地址替换为black_exporter的地址

docker-compose

安装docker-compose参考

# 2. 安装docker-compose
pip install docker-compose

docker-compose up -d

安装grafana

#先安装原版,拿配置文件
docker run -d --name grafana \
-p 3000:3000 \
grafana/grafana:latest


docker cp grafana:/etc/grafana/ /docker/config/
docker cp grafana:/var/lib/grafana/ /docker/volumes/

docker run -d --name grafana \
-p 3000:3000 \
-v /docker/config/grafana/:/etc/grafana/ \
-v /docker/volumes/grafana/:/var/lib/grafana/ \
grafana/grafana:latest


#如果权限不足
# chmod -R 777 . 


#如果登录报错 /docker/config/grafana/grafana.ini
[log]
# Either "console", "file", "syslog". Default is console and  file
# Use space to separate multiple modes, e.g. "console file"
mode = console file

# Either "debug", "info", "warn", "error", "critical", default is "info"
level = debug


添加datasource

image-20230530163518972

安装alertManager

docker run --name alertmanager -d -p 9093:9093 --restart=always \
prom/alertmanager


docker cp alertmanager:/etc/alertmanager /docker/config/alertmanager
docker rm -f alertmanager

docker run --name alertmanager -d -p 9093:9093 --restart=always \
-v /docker/config/alertmanager/:/etc/alertmanager/ \
prom/alertmanager


http://10.0.17.178:9090/   #prometheus
http://10.0.17.178:3000/   #grafana
http://10.0.17.178:9093/   #altermessage

配置站点监控

参考

安装配置black_expoter

mkdir -p /docker/compose/prometheus/black_expoter
touch docker-compose.yml

#重启普罗米修斯
curl -XPOST http://127.0.0.1:9090/-/reload
#docker-compose.yml
version: '3.7'
services:
  blackbox_exporter:
    container_name: blackbox_exporter
    image: prom/blackbox-exporter:master
    volumes:
      - /docker/config/blackbox_exporter/config.yml:/etc/blackbox_exporter/config.yml
    ports:
      - 9115:9115
#config.yml
modules:
  http_2xx:      # 给模块取名,后面在Prometheus的配置文件中会用到该名称
    prober: http # 探针类型,探针有多种类型如http、tcp、icmp、dns,不同的探针具有不同的功能
    timeout: 5s  # 探针检测超时时间
    http:
      valid_status_codes: [] # 有效的状态码,默认为200,也可以自己定义,比如你的站点304也可能是正常的
      method: GET            # http使用get请求
      fail_if_body_not_matches_regexp: [] # 对返回结果进行正则匹配,如果未匹配成功则认为失败
      tls_config:
        insecure_skip_verify: true        # 不安全的https跳过确认,如某些证书不合法或者过期,如果你在浏览器访问,那浏览器会让你确认是否继续,这里也是类似的意思。

dashbord

https://grafana.com/grafana/dashboards/10915-asp-net-core-controller-summary-prometheus/

https://grafana.com/grafana/dashboards/10427-prometheus-net/

https://grafana.com/grafana/dashboards/12526-asp-net-core-services/

https://grafana.com/grafana/dashboards/17039-prometheus-net-process-metrics/

标签:__,http,grafana,prometheus,监控,docker,config,搭建
From: https://www.cnblogs.com/xinzhyu/p/17448195.html

相关文章

  • 使用SpringMVC搭建第一个项目
    概述使用SpringMVC搭建第一个项目,入门教程,分享给大家。详细一、概述1、什么是SpringMVC?SpringMVC属于SpringFrameWork的后续产品,已经融合在SpringWebFlow里面。Spring框架提供了构建Web应用程序的全功能MVC模块。使用Spring可插入的MVC架构,从而在使用Sp......
  • 【博学谷学习记录】超强总结,用心分享 | 系统资源监控-psutil
    【博学谷IT技术支持】一、介绍psutil(python系统和进程实用程序)是一个跨平台库,用于在Python中检索有关正在运行的进程和系统利用率(CPU、内存、磁盘、网络、传感器)的信息。它主要用于系统监控、分析、限制进程资源和管理正在运行的进程。二、相关api获取CPU信息cpu_count:......
  • 搭建jenkins实现自动化部署
    一、安装jenkins1、添加yumrepos,然后安装12sudo wget-O /etc/yum.repos.d/jenkins.repohttps://pkg.jenkins.io/redhat/jenkins.reposudo rpm--import https://pkg.jenkins.io/redhat/jenkins.io.key注:如果上边的执行成功就不用再执行这两......
  • jenkin环境搭建
     Jenkins是一个用Java编写的开源的持续集成(CI)工具,可持续、自动地构建/测试软件项目,监控一些定时执行的任务。具有开源,支持多平台和插件扩展,安装简单,界面化管理等特点。1.下载并解压Tomcat  (windows)Tomcat官方网站:http://tomcat.apache.org/2.下载并安装适合自己电脑系统......
  • 2、一个TOMCAT服务器搭建两个网站,并在主网站下搭建子业务
    在一个服务器上搭建多个网站如何实现三种方案:IP来区分、端口号来区分、host来区分如nginx中IP来区分:server{listen1.1.1.1:80;}server{listen2.2.2.2:80;}端口号来区分:server{listen1.1.1.1:80;}server{listen1.1.1.1:81;}host(主机头)来区分:ser......
  • kafka单独集群搭建
     查看kafka配置下面配置是由ambari配置生成。catconf/server.properties#GeneratedbyApacheAmbari.TueOct2510:40:072022auto.create.topics.enable=trueauto.leader.rebalance.enable=truecompression.type=producercontrolled.shutdown.enable=truecontro......
  • k8s 环境搭建
    1.k8s安装systemctlstopfirewalldsystemctldisablefirewalld#修改hostnamehostnamectlset-hostnamek8s-01#查看修改结果hostnamectlstatus#设置hostname解析echo"127.0.0.1$(hostname)">>/etc/hosts#关闭selinux:sed-i's/enforcing/disabled......
  • oracle 最大IOPS使用率和IOMBPS使用率监控 19c
    pdb最大iops使用率监控指标获取通过字典DBA_HIST_RSRC_PDB_METRIC分析具体字段为IOPS_THROTTLE_EXEMPT、IOMBPS_THROTTLE_EXEMPT一般最大值超过5就要告警了参数iops_throttle_exempt IndicateshowmuchoftheI/OpersecondinthecurrentPDBwasexemptedfromt......
  • Windows编程:文件监控
    最近在做虚拟打印机时,需要实时监控打印文件的到达,并移动文件到另外的位置。一开始我使用了线程,在线程里去检测新文件的到达。实际上Windows提供了一个文件监控接口函数ReadDIrectoryChangesW。这个函数可以对所有文件操作进行监控。 ReadDirectoryChangesW函数声明1BOOLR......
  • 5.portainer与容器监控
    9.portainer9.1.介绍官网:https://www.portainer.io/Portainer是一款轻量级的应用,它提供了图形化界面,用于方便地管理Docker环境,包括单机环境和集群环境。9.2.安装dockerrun-d-p8000:8000-p9000:9000--nameportainer--restart=always-v/var/run/docker.s......