prometheus的简单安装以及使用

下载你想安装的prometheus版本,地址为download prometheus

解压

tar xvfz prometheus-*.tar.gz
cd prometheus-*

配置监控对象(本文现在配置的监控对象是prometheus本身)

root@fabric-cli prometheus-2.2.1.linux-amd64]# ls -l
总用量 108100
drwxrwxr-x 2 1000 1000       38 3月  14 22:14 console_libraries
drwxrwxr-x 2 1000 1000      173 3月  14 22:14 consoles
-rw-rw-r-- 1 1000 1000    11357 314 22:14 LICENSE
-rw-rw-r-- 1 1000 1000     2769 314 22:14 NOTICE
-rwxr-xr-x 1 1000 1000 66176282 314 22:17 prometheus
-rw-rw-r-- 1 1000 1000      928 314 22:14 prometheus.yml
-rwxr-xr-x 1 1000 1000 44492910 314 22:18 promtool

prometheus.yml配置文件的内容可以看出,该配置文件就是让prometheus监控自己
关于配置文件的详细说明请参考prometheus configuration

# 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服务

[root@fabric-cli prometheus-2.2.1.linux-amd64]# ./prometheus --config.file="prometheus.yml"
level=info ts=2018-05-04T02:05:15.984674897Z caller=main.go:220 msg="Starting Prometheus" version="(version=2.2.1, branch=HEAD, revision=bc6058c81272a8d938c05e75607371284236aadc)"
level=info ts=2018-05-04T02:05:15.984789564Z caller=main.go:221 build_context="(go=go1.10, user=root@149e5b3f0829, date=20180314-14:15:45)"
level=info ts=2018-05-04T02:05:15.984816024Z caller=main.go:222 host_details="(Linux 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 fabric-cli (none))"
level=info ts=2018-05-04T02:05:15.984841453Z caller=main.go:223 fd_limits="(soft=1024, hard=4096)"
level=info ts=2018-05-04T02:05:15.997654037Z caller=main.go:504 msg="Starting TSDB ..."
level=info ts=2018-05-04T02:05:16.00942241Z caller=web.go:382 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-05-04T02:05:16.015855882Z caller=main.go:514 msg="TSDB started"
level=info ts=2018-05-04T02:05:16.015894187Z caller=main.go:588 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2018-05-04T02:05:16.017592228Z caller=main.go:491 msg="Server is ready to receive web requests."

通过访问http://10.4.93.141:9090/metrics,可以查看搜集的性能指标
prometheus

访问http://10.4.93.141:9090/graph可以查看图形界面
执行prometheus_target_interval_length_seconds,查看实际采集的时间
pro01

查看请求的数量count(prometheus_target_interval_length_seconds)
01

查看更多的表达式,请参考expression language documentation

启动简单的实例


git clone https://github.com/prometheus/client_golang.git
cd client_golang/examples/random
go get -d
go build

# 启动
./random -listen-address=:8080  &
./random -listen-address=:8081  &
./random -listen-address=:8082  &

修改prometheus.yml文件

[root@fabric-cli prometheus-2.2.1.linux-amd64]# cat 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:
  - job_name:       'example-random'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:8080', 'localhost:8081']
        labels:
          group: 'production'

      - targets: ['localhost:8082']
        labels:
          group: 'canary'

执行rpc_durations_seconds
03

配置收集规则

avg(rate(rpc_durations_seconds_count[5m])) by (job, service)

创建文件搜集规则文件prometheus.rules.yml

[root@fabric-cli prometheus-2.2.1.linux-amd64]# cat prometheus.rules.yml 
groups:
- name: example
  rules:
  - record: job_service:rpc_durations_seconds_count:avg_rate5m
    expr: avg(rate(rpc_durations_seconds_count[5m])) by (job, service)

修改配置文件prometheus.yml

[root@fabric-cli prometheus-2.2.1.linux-amd64]# cat prometheus.yml 
global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # Evaluate rules every 15 seconds.

  # Attach these extra labels to all timeseries collected by this Prometheus instance.
  external_labels:
    monitor: 'codelab-monitor'

rule_files:
  - 'prometheus.rules.yml'

scrape_configs:
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']

  - job_name:       'example-random'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:8080', 'localhost:8081']
        labels:
          group: 'production'

      - targets: ['localhost:8082']
        labels:
          group: 'canary'

重新启动prometheus服务
执行job_service:rpc_durations_seconds_count:avg_rate5m表达式

09
参考:
getting_started
END

https://blog.csdn.net/yevvzi/article/details/79561150

infludb集群安装
https://www.cnblogs.com/tianqing/p/7153023.html

Prometheus 是一个开源的监控系统,它可以用来收集、存储和查询各种不同类型的指标数据。下面是一个简要的 Prometheus 安装使用教程: 1. 下载 Prometheus 你可以从 Prometheus 的官网下载最新版本的二进制文件:https://prometheus.io/download/ 2. 解压 Prometheus 将下载的 Prometheus 压缩文件解压到你想要安装的目录中: ``` tar xvfz prometheus-*.tar.gz cd prometheus-* ``` 3. 配置 Prometheus Prometheus 的配置文件是 `prometheus.yml`,你需要根据你的需要编辑它。这个文件包含了 Prometheus 的所有配置信息,包括要监控的目标、指标的抓取频率等等。 例如,以下是一个简单Prometheus 配置文件: ``` global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] ``` 这个配置文件定义了一个名为 `prometheus` 的作业,它会每 15 秒抓取 localhost:9090 上的指标数据。 4. 启动 Prometheus 使用以下命令启动 Prometheus: ``` ./prometheus ``` 这将启动 Prometheus,并开始抓取指标数据。你可以在浏览器中访问 `http://localhost:9090`,查看 Prometheus 的 Web 界面。 5. 查询指标 在 Prometheus 的 Web 界面中,你可以使用 PromQL 查询语言查询指标数据。例如,以下查询会返回 Prometheus 目前存储的所有指标名称: ``` {__name__} ``` 这只是一个简单的例子,你可以在 Prometheus 的文档中找到更多的查询语言和示例。 这就是一个简单Prometheus 安装使用教程。希望能对你有所帮助!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值