Ubuntu 20.04 安装prometheus

下载

官网下载链接

wget https://github.com/prometheus/prometheus/releases/download/v2.36.0/prometheus-2.36.0.linux-amd64.tar.gz

解压

解压到当前目录:

tar xvfz prometheus-2.36.0.linux-amd64.tar.gz

进入prometheus目录:

cd prometheus-2.36.0.linux-amd64

查看监控配置(默认开启监控当前机器)

vim 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:
          # - 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: ["localhost:9090"]

在默认配置中,只有一个名为 prometheus 的作业,它会抓取 Prometheus 服务器公开的时间序列数据。
该作业包含一个静态配置的目标,即端口 9090 上的 localhost

运行普罗米修斯

# Start Prometheus.
# By default, Prometheus stores its database in ./data (flag --storage.tsdb.path).
./prometheus --config.file=prometheus.yml

后台运行

nohup ./prometheus --config.file=prometheus.yml &

普罗米修斯应该启动了,你可以通过浏览器访问localhost:9090查看状态页。等待几十秒钟从它自身的http测度端点收集数据
在这里插入图片描述
你也可以确认普罗米修斯正在提供自身测度的服务访问:localhost:9090/metrics

在这里插入图片描述

使用表达式浏览器

让我们浏览普罗米修斯收集的数据。使用普罗米修内建的表达式浏览器,导航到http://localhost:9090/graph 然后Graph标签页的Table视图。
就像你从localhost:9090/metrics收集到的,普罗米修斯上报一个名叫prometheus_target_interval_length_seconds(实际从目标抓取的时间间隔)的测度。输入以下内容到表达式控制台并点击Execute:

prometheus_target_interval_length_seconds

在这里插入图片描述
返回一组不同的时间序列(与最近的数值记录一起),每个都有相同的测度名称prometheus_target_interval_length_seconds,但是有不同的标签。这些标签指明不同的延迟百分比和目标组间隔。

如果我们只对第99百分比延迟感兴趣,我们可以使用以下查询:

prometheus_target_interval_length_seconds{quantile="0.99"}

在这里插入图片描述
想统计时间序列的总数,可以编写以下表达式:

count(prometheus_target_interval_length_seconds)

在这里插入图片描述

更多关于表达式语法, 查看表达式语法文档

使用图形化接口

使用图形化表达式,导航到http://localhost:9090/graph使用Graph标签页。
示例,输入以下表达式展示图形:抓取普罗米修斯自身每秒的文件创建速率:

rate(prometheus_tsdb_head_chunks_created_total[1m])

在这里插入图片描述

实验图形化区间参数和其它设置

参考文档

Ubuntu 20.04安装 Prometheus
官方GETTING STARTED

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu安装和部署Prometheus,您可以按照以下步骤进行操作: 1. 首先,您需要从Prometheus的官方网站下载最新版本的安装包。您可以访问https://prometheus.io/download/下载页面来获取下载链接。\[1\] 2. 下载完成后,您需要解压安装包并将其移动到适当的位置。您可以使用以下命令完成这些操作: ``` cd /export/ wget https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1.linux-amd64.tar.gz tar -zxvf prometheus-2.13.1.linux-amd64.tar.gz mv prometheus-2.13.1.linux-amd64 prometheus ``` 这将解压并移动Prometheus安装包到/export/prometheus目录下。\[1\] 3. 接下来,您需要进行一些配置。您可以使用文本编辑器(如vim)打开/etc/systemd/system/prometheus.service文件,并添加以下内容: ``` \[Unit\] Description=Prometheus Documentation=https://prometheus.io/ After=network.target \[Service\] Type=simple User=prometheus ExecStart=/export/prometheus/prometheus --config.file=/export/prometheus/prometheus.yml --storage.tsdb.path=/export/prometheus/data Restart=on-failure \[Install\] WantedBy=multi-user.target ``` 这将创建一个systemd服务单元,用于启动和管理Prometheus服务。\[2\] 4. 保存并关闭文件后,您可以使用以下命令启动Prometheus服务: ``` sudo systemctl start prometheus ``` 5. 最后,您可以使用以下命令将Prometheus设置为开机启动: ``` sudo systemctl enable prometheus ``` 现在,您已经成功在Ubuntu安装和部署了Prometheus。您可以通过访问http://localhost:9090来访问Prometheus的Web界面,并开始配置和监控您的目标。请确保您的防火墙允许9090端口的访问。\[1\] #### 引用[.reference_title] - *1* *2* [Prometheus安装部署说明](https://blog.csdn.net/m0_38100619/article/details/119931664)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Ubuntu 20.04 安装prometheus](https://blog.csdn.net/nuptaxin/article/details/125119470)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值