代码改变世界

Prometheus安装配置

2022-03-25 23:34  youxin  阅读(182)  评论(0编辑  收藏  举报

Prometheus
proˈmiθɪəs/

 

Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。
2016年由Google发起Linux基金会旗下的原生云基金会(Cloud Native Computing Foundation), 将Prometheus纳入其下第二大开源项目。
Prometheus目前在开源社区相当活跃。
Prometheus和Heapster(Heapster是K8S的一个子项目,用于获取集群的性能数据。)相比功能更完善、更全面。Prometheus性能也足够支撑上万台规模的集群。

Prometheus的特点

  • 多维度数据模型。
  • 灵活的查询语言。
  • 不依赖分布式存储,单个服务器节点是自主的。
  • 通过基于HTTP的pull方式采集时序数据。
  • 可以通过中间网关进行时序列数据推送。
  • 通过服务发现或者静态配置来发现目标服务对象。
  • 支持多种多样的图表和界面展示,比如Grafana等。

官网地址:https://prometheus.io/

 

在Prometheus的架构设计中,Prometheus Server并不直接服务监控特定的目标,其主要任务负责数据的收集,存储并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如主机的CPU使用率,我们需要使用到Exporter。Prometheus周期性的从exporter暴露的HTTP服务地址(通常是/metrics)拉取监控样本数据

从上面的描述中可以看出exporter可以是一个相对开放的概念,其可以是一个独立运行的程序独立于监控目标以外,也可以是直接内置在监控目标中。只要能够向Prometheus提供标准格式的监控样本数据(TS时间序列)即可。

前面都是废话[皮],正题开始。这里为了能够采集到主机的运行指标如CPU, 内存,磁盘等信息。就需要用到node_exporter。

 

node_exporter – 用于机器系统数据收集, 以Prometheus理解的格式导出大量指标(如磁盘I / O统计数据,CPU负载,内存使用情况,网络统计数据等)

mysqld_exporter – 用于MySQL服务器数据收集

prometheus可以理解为一个数据库+数据抓取工具,工具从各处抓来统一的数据,放入prometheus这一个时间序列数据库中。那如何保证各处的数据格式是统一的呢?就是通过这个exporter。

exporter也是用GO写的程序,它开放一个http接口,对外提供格式化的数据。所以在不同的环境下,需要编写不同的exporter。

 

 

docker run -d --name prometheus -p 9090:9090 -v F:\Docker\dockerContainer\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

 

访问:

http://127.0.0.1:9090/graph

 

 

 

 

 

访问targets,url如下:http://127.0.0.1:9090/targets

 

 

 

 

prommetheus增加 node exporter

 

# 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:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "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: ["127.0.0.1:9090"]


  - job_name: "mynode1"
    static_configs:
      - targets: ["192.168.31.204:9100"]

在原本的配置文件加上

 

  - job_name: "mynode1"
    static_configs:
      - targets: ["192.168.31.204:9100"]

 

这里的192.168.31.204 改成对应的ip

 

scrape_configs:
# 添加作业并命名(这个名称自己随便定义,不过最好是和你监听的服务有关)
- job_name: 'node'
# 静态添加node
static_configs:
# 指定监控端 ip:你服务器的ip port:你启动mysql_exporter容器映射出来的端口(9104)
- targets: ['{ip}:{port}']
————————————————

 

 

参考:https://www.cnblogs.com/xiao987334176/p/9930517.html

 https://blog.csdn.net/weixin_45975639/article/details/123202900