Prometheus : introduction
Prometheus Is an open source monitoring system . Support flexible query language (PromQL), use http Agreed pull Mode pull data and other features make Prometheus
Easy to understand and powerful .
Prometheus Main features of
Multidimensional data model
Flexible query language
Independent of distributed storage , Single server node is autonomous
adopt pull Method to collect time series data
Time series data can be pushed through the intermediate gateway
Discover target service objects through service discovery or static configuration
Support multiple interface display schemes , such as grafana etc.
Prometheus from server, client, push gateway, exporter, alertmanager
And other core components .Prometheus server Mainly used to grab and store data .Client libraries Can be used to connect server
And query and other operations .Push gateway For batch , Summary node of short-term monitoring data , Mainly used for business data reporting, etc . different exporter
Used for data collection in different scenarios , For example, the node_exporter, collect MongoDB Informative MongoDB exporter wait . The figure below is
Prometheus Official architecture ：
From this diagram , We can see that its operation logic is like this ：
Prometheus server Pull data from data source regularly , Data is then persisted to disk .Prometheus Configurable
rules, Then query the data regularly , When the condition triggers , Will alert Push to configured Alertmanager.Alertmanager
When you receive a warning , According to the configuration , polymerization , duplicate removal , noise reduction , Last warning sent . You can also use API, Prometheus Console perhaps Grafana
Query and aggregate data .
This article will introduce ubuntu 16.04 Installed in the system Prometheus Server, And configure it to pull monitoring information from a host , And then through Prometheus
Server Easy to provide UI Query data .
stay Ubuntu 16.04 Installation in Prometheus Server
Please go from Prometheus Official download <https://prometheus.io/download/> linux
Version of binary compression package . Please select the operating system as linux.
Execute the following command prometheus server Install to /usr/local/share/prometheus catalog ：
$ tar -xf prometheus-1.7.2.linux-amd64.tar.gz $ sudo mv prometheus-1.7.2
In theory, that's the end of the installation , But anyway, it's too simple . Because every time you start Prometheus server Both require manual command execution ：
$ /usr/local/share/prometheus/prometheus -config.file
It's really inconvenient ! It should be configured as a service , use systemd To manage .
First create a file named prometheus Users of ：
$ sudo adduser prometheus
List /usr/local/share/prometheus/ The owner of is set to prometheus user ：
$ sudo chown -R prometheus:prometheus /usr/local/share/prometheus/
Then create the file /etc/systemd/system/prometheus.service, The content is as follows ：
[Unit] Description=Prometheus Server Documentation=https://
prometheus.io/docs/introduction/overview/ After=network.target [Service] User=
prometheus Restart=on-failure WorkingDirectory=/usr/local/share/prometheus/
ExecStart=/usr/local/share/prometheus/prometheus \ -config.file
=/usr/local/share/prometheus/prometheus.yml [Install] WantedBy=multi-user.target
okay , Now you can go through systemd To control Prometheus Service , Start service first ：
$ sudo systemctl daemon-reload $ sudo systemctl start prometheus
Then configure the service to start on startup ：
$ sudo systemctl enable prometheus
Check the status of the service ：
$ sudo systemctl status prometheus
only this and nothing more Prometheus Server It's already running . Then we can collect the data .
use Node Exporter Collect host information
The tasks of data collection are different exporter To complete , If you want to collect linux Host information , have access to node exporter. Then by Prometheus
Server from node exporter Pull up information . Next we will show you how to install and configure node exporter.
Please go from Prometheus Official download <https://prometheus.io/download/> node exporter
Binary compression package of . Execute the following command node exporter Install to /usr/local/share/ catalog ：
$ tar -xf node_exporter-0.14.0.linux-amd64.tar.gz $ sudo cp node_exporter-0.14.
In the same way, we put node exporter Also configured to pass systemd Administration . create a file
/etc/systemd/system/node-exporter.service, The content is as follows ：
[Unit] Description=Prometheus Node Exporter After=network.target [Service]
ExecStart=/usr/local/sbin/node_exporter User=nobody [Install] WantedBy
Execute the following command to start and start the service ：
$ sudo systemctl daemon-reload $ sudo systemctl enable node-exporter $ sudo
systemctl start node-exporter
node exporter Default listening 9100 port , Let's check the monitoring of the port ：
$ ss -tunl
Node exporter You can already collect information on the host , Next we need to configure Prometheus Server from node exporter
Pull data there .
to configure Prometheus from Node Exproter Pull data
Prometheus Server Can be from different exporter Pull up data , For the above node exporter We can use Prometheus
Of static_configs To pull node exporter Data for . edit Prometheus server Profile for ：
$ sudo vim /usr/local/share/prometheus/prometheus.yml
stay scrape_configs Add a The name is node Of static_configs：
- job_name: "node" static_configs: - targets: ["127.0.0.1:9100"]
be careful , You need to put the IP Replace address with run node exporter Of the host IP.
Save file and restart prometheus service ! After restart prometheus Every 15s from node exporter Pull up data once .
Prometheus Server Provides a simple WebUI Data query and display , The default listening port is
9090. Next, we will make a simple query to verify the system configured in this article .
Access in browser Prometheus Server Of 9090 port ：
Select from the drop-down menu "node_memory_Buffers", Then click "Execute" Button ：
The results are a little rough , Not even the unit . Please select "Graph" Tab ：
It's much better to view the query results through the chart !
Prometheus It is a popular open source monitoring tool , This is just a brief introduction to the installation process and a basic use case . But it's not hard to see Prometheus
Although it supports flexible query language , But it only supports simple display ability . If you want a friendly display Prometheus Query results for , More professional display tools are needed Grafana.