美文网首页
2021-07-29 Prometheus部署及基本使用

2021-07-29 Prometheus部署及基本使用

作者: 阿丧小威 | 来源:发表于2021-07-29 16:08 被阅读0次

    1. Prometheus介绍

    Prometheus(普罗米修斯)是一个最初在SoundCloud上构建的监控系统。自2012年成为社区开源项目,拥有非常活跃的开发人员和用户社区。为强调开源及独立维护,Prometheus于2016年加入云原生云计算基金会(CNCF),成为继Kubernetes之后的第二个托管项目。
    https://prometheus.io
    https://github.com/prometheus

    Prometheus 特点:

    • 多维数据模型:由度量名称和键值对标识的时间序列数据
    • PromQL:一种灵活的查询语言,可以利用多维数据完成复杂的查询
    • 不依赖分布式存储,单个服务器节点可直接工作
    • 基于HTTP的pull方式采集时间序列数据
    • 推送时间序列数据通过PushGateway组件支持
    • 通过服务发现或静态配置发现目标
    • 多种图形模式及仪表盘支持(grafana)

    2. Prometheus组件与架构

    Prometheus组件与架构

    • Prometheus Server:收集指标和存储时间序列数据,并提供查询接口
    • ClientLibrary:客户端库
    • Push Gateway:短期存储指标数据。主要用于临时性的任务
    • Exporters:采集已有的第三方服务监控指标并暴露metrics
    • Alertmanager:告警
    • Web UI:简单的Web控制台

    3. Prometheus部署

    从官网下载Linux安装包:https://prometheus.io/download/

    tar zxf prometheus-2.22.2.linux-amd64.tar.gz
    mv prometheus-2.22.2.linux-amd64 /usr/local/prometheus
    cd /usr/local/prometheus
    ./premetheus    ---启动
    

    启动可用选参数:
    ./premetheus -h 命令行常用参数:
    • --config.file="prometheus.yml" # 指定配置文件
    • --web.listen-address= "0.0.0.0:9090" # 监听地址和端口
    • --log.level=info # 日志级别
    • --alertmanager.timeout=10s # 与报警组件的超时时间
    • --storage.tsdb.path="data/ " # 数据目录
    • --storage.tsdb.retention.time=15d # 数据保存时间,默认15天
    配置为系统服务管理:

    vi /usr/lib/systemd/system/prometheus.service
    [Unit]
    Description=prometheus
    [Service]
    ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=process
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    
    systemctl daemon-reload    ---修改完后重新加载一下
    systemctl start prometheus
    systemctl enable prometheus
    

    4. Prometheus 配置文件

    配置文件:prometheus.yml


    配置文件

    配置文件解释:
    • global:全局配置
    scrape_interval: 15s # 采集数据时间间隔
    evaluation_interval: 15s # 评估告警规则时间间隔,默认1分钟
    scrape_timeout: 5s # 采集数据超时时间,默认10秒

    • rule_files:告警规则
    • scrape_configs:配置被监控端,称为target,每个target用
    job_name分组管理,又分为静态配置和服务发现
    • alerting:告警配置
    • remote_write/remote_read:从远程数据库读写
    参考文档:https://prometheus.io/docs/prometheus/latest/configuration/configuration/

    配置被监控端:
    目标(targets):被监控端
    实例(Instances):每个被监控端称为实例
    作业(Job):具有相同目标的实例集合称为作业

    vi prometheus.yml
    scrape_configs:    ---在scrape_configs下配置,localhost:9090是prometheus程序
      - job_name: 'prometheus'
        static_configs:
        - targets: ['localhost:9090']
    

    网页访问Prometheus:IP:9090

    image.png

    4. 监控指标数据模型

    数据模型:
    • Prometheus将所有数据存储为时间序列;
    • 具有相同度量名称以及标签属于同一个指标;
    • 每个时间序列都由度量标准名称和一组键值对(称为标签)唯一标识,
    通过标签查询指定指标。
    指标格式:
    <metric name>{<label name>=<label value>,...}

    数据模型

    相关文章

      网友评论

          本文标题:2021-07-29 Prometheus部署及基本使用

          本文链接:https://www.haomeiwen.com/subject/bihzmltx.html