普罗米修斯之推荐- 初始安装 –

请务必谅解,本文将试着为不了解Prometheus的人提供包括排除错误在内的调查和记录。因此,这些信息可能会显得有点凌乱。

选择普罗米修斯的原因

在某家公司担任基础设施职责时,管理基础设施的工作并不统一,云账户被多个开发工程师共享,服务器随意设立,没有正确区分生产环境和开发环境等,导致有些事情变得一团糟,完全摸不着头脑。

暂时来说,虽然问题很多,但是我想先通过监控工具来检测实例的增加之类的,能行吗?正在烦恼之中的时候,我那位十年好友Google告诉我Prometheus很不错,于是决定进行调查和试验性引入。

尝试实际使用 Prometheus 进行下一代监控
“由于 Prometheus 的 service discovery 功能非常紧密地集成在其自身中,只需在配置文件中简单地进行一点点编写,即可获取到 EC2 的主机列表。简直太好了,不是吗?”

对,就是这样的,我就是想要这个。

普罗米修斯是什么?

个人认为以下网站是最易懂的。
“Prometheus”是一款全新的基础设施服务监控工具入门。

我想趁着看这个来试着构建一下。

首先,让我们设定一个目标,确保服务器和导出器能够相互识别并查看资源。

因此,试一试

因为Ubuntu版本所提供的功能与最新版本之间可能存在明显差异,所以尝试通过从官方网站下载二进制文件的方式来安装。

首先,我们试着参考以下步骤来构建二进制文件。
Prometheus 环境的构建步骤如下。

安装Prometheus Server。

只需要安装或配置二进制文件然后启动。

# wget https://github.com/prometheus/prometheus/releases/download/v2.3.1/prometheus-2.3.1.linux-amd64.tar.gz
# tar -zxvf prometheus-2.3.1.linux-amd64.tar.gz
# ls
prometheus-2.3.1.linux-amd64  prometheus-2.3.1.linux-amd64.tar.gz
# mv prometheus-2.3.1.linux-amd64 prometheus-2.3.1
# ls prometheus-2.3.1
console_libraries  LICENSE  prometheus      promtool
consoles           NOTICE   prometheus.yml
# ./prometheus -config.file=prometheus.yml &
[1] 1455
# Error parsing commandline arguments: unknown short flag '-c'
prometheus: error: unknown short flag '-c'
[1]+  Exit 1                  ./prometheus -config.file=prometheus.yml
#

出现了错误。我来查一下。。。。

啊。不是`-config.file`,感觉像是`–config.file`。

./prometheus --config.file=prometheus.yml &
[1] 1463
# level=info ts=2018-06-27T02:17:07.486654475Z caller=main.go:222 msg="Starting Prometheus" version="(version=2.3.1, branch=HEAD, revision=188ca45bd85ce843071e768d855722a9d9dabe03)"
level=info ts=2018-06-27T02:17:07.486835933Z caller=main.go:223 build_context="(go=go1.10.3, user=root@82ef94f1b8f7, date=20180619-15:56:22)"
level=info ts=2018-06-27T02:17:07.486942731Z caller=main.go:224 host_details="(Linux 4.4.0-1060-aws #69-Ubuntu SMP Sun May 20 13:42:07 UTC 2018 x86_64 ap-prometheus01 (none))"
level=info ts=2018-06-27T02:17:07.487053934Z caller=main.go:225 fd_limits="(soft=1024, hard=1048576)"
level=info ts=2018-06-27T02:17:07.488219753Z caller=main.go:514 msg="Starting TSDB ..."
level=info ts=2018-06-27T02:17:07.493209906Z caller=web.go:415 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-06-27T02:17:07.4940652Z caller=main.go:524 msg="TSDB started"
level=info ts=2018-06-27T02:17:07.494133486Z caller=main.go:603 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2018-06-27T02:17:07.494979401Z caller=main.go:500 msg="Server is ready to receive web requests."
#

我动了吗。先试试在浏览器上看看。
※还是先做好安全组之类的端口许可吧。

prometheus01.PNG

啊…居然没有登录界面啊…
还是应该限制能看的地方啊…

现在只有自己..?但是自己没有安装导出程序吗?
先看看配置文件吧。

# 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']

这真难懂啊。。可能需要时间适应。另外,对于服务的发现,该怎么办呢。。

不过,接下来我们先试着将exporter安装到另一个服务器上并进行确认。

好吧,再次看看这个地方…
Prometheus 环境设置步骤

二进制下载吗?
我在这里的同时,想到了一个问题,考虑到监视的服务器数量,我更倾向于使用apt-get来进行导出。
嗯,如果不行的话,也没关系,虽然不确定是否兼容,但还是试试apt-get。

※2021年6月28日追記
由于apt-get版本的收集器无法使用,所以正在重新安装二进制文件。
Prometheus推荐 – 引入exporter node-exporter (apt-get) –
顺便说一下,据说可以通过node-exporter的启动选项来更改端口、基本认证等。

安装Node Exporter(使用apt-get)。

首先,尝试将其放入相同的内部网络中的服务器。
※如果是外部的话,不要忘记在安全组中授予权限。
另外,请注意,因为任何人都可以通过http://IP:Port/metrics轻松查看内容,所以要小心。

# apt-get install prometheus-node-exporter
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  daemon
The following NEW packages will be installed:
  daemon prometheus-node-exporter
0 upgraded, 2 newly installed, 0 to remove and 33 not upgraded.
Need to get 1,837 kB of archives.
After this operation, 8,177 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 daemon amd64 0.6.4-1 [98.2 kB]
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 prometheus-node-exporter amd64 0.11.0+ds-1 [1,739 kB]
Fetched 1,837 kB in 0s (2,151 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 59475 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1_amd64.deb ...
Unpacking daemon (0.6.4-1) ...
Selecting previously unselected package prometheus-node-exporter.
Preparing to unpack .../prometheus-node-exporter_0.11.0+ds-1_amd64.deb ...
Unpacking prometheus-node-exporter (0.11.0+ds-1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up daemon (0.6.4-1) ...
Setting up prometheus-node-exporter (0.11.0+ds-1) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...

改变服务器端的设置。

# vi prometheus.yml
+      - targets: ['172.31.41.83:9100']
# killall prometheus
# ./prometheus --config.file=prometheus.yml &
prometheus02.PNG

状态已经变为UP,看起来已经被认可了。

我們來看一下圖表。
從”執行”旁的列表中隨意選擇一個,然後點擊”執行”。

スクリーンショット (1).png

暂时不管版本不同,看起来值已经被获取了。
时间显示为GMT。
想要改成JST,要查一下。。。。

似乎目前看来是不可能的。很遗憾。

暂时就这样结束吧,服务发现之类的以后再说吧。

请参考以下网址

长生村本郷工程师博客

bannerAds