Introduction, installation and configuration of Promethus

This article mainly introduces the basic functions and features of Prometheus as well as the installation and configuration implementation process. Friends in need can refer to it. I hope it will be helpful. I wish you all a lot of progress and an early promotion and salary increase!

1. Overview of Prometheus
Prometheus (developed by go language (golang)) is a combination of open source monitoring & alarm & time series database. Suitable for monitoring docker containers.
Prometheus is an open source system monitoring and alerting toolkit originally built on SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now an independent open source project and maintained independently of any company. To emphasize this point and clarify the project's governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016, its second managed project after Kubernetes.
Prometheus is a time series database. However, it is more than just a time series database.
It covers the entire ecosystem of toolsets that can be bundled and their capabilities.
Prometheus is mainly used for infrastructure monitoring. Including servers, databases, VPS, almost everything can be monitored through Prometheus. Prometheus expects to retrieve metrics via HTTP calls made to certain endpoints defined in the Prometheus configuration.

Advantages of Prometheus:
Very few external dependencies, very simple to install and use.
There are already many system integrations, such as: docker, HAProxy, Nginx, JMX, etc.
Service automation discovery is
directly integrated into the code.
The design concept is implemented according to the distributed and microservice architecture and
can be adopted . The time series data is pushed to the Prometheus server through push gateway.
Monitoring targets can be obtained through service discovery or static configuration.
There are various visual graphical interfaces.
Easily retractable.
Features of Prometheus
A multidimensional data model that contains time series data identified by metric names and key/value pairs
PromQL, a flexible query language that leverages this dimension
No reliance on distributed storage; single server node is autonomous over
time Sequence collection is performed through the pull model over HTTP
Supports push time series through intermediate gateways Discover targets through service discovery or static configuration
Multiple graphs and dashboards support modes
2. Time Series Data
1. What is sequence data
Time Series Data (TimeSeries Data) : Data that records system and device status changes in chronological order is called time series data.
There are many application scenarios, such as:

The longitude, latitude, speed, direction, distance of nearby objects, etc. need to be recorded during the operation of the unmanned vehicle. Data must be recorded and analyzed at all times.
Driving trajectory data of each vehicle in a certain area,
real-time transaction data of the traditional securities industry,
real-time operation and maintenance monitoring data, etc.
2 Characteristics of time series data
Good performance
Relational databases have poor performance in processing large-scale data. NOSQL can handle large-scale data better, but it is still inferior to time series databases.

Low storage cost
. Efficient compression algorithm saves storage space and effectively reduces IO.
Prometheus has a very efficient time series data storage method. Each sampled data only takes up about 3.5 bytes of space. Millions of time series, 30 second interval, retains 60 Days, it probably took more than 200 G (from official data)

3. Prometheus principle architecture diagram
The following diagram illustrates the architecture of Prometheus and some of its ecosystem components:
Insert image description here

Prometheus removes metrics from instrumented jobs either directly or through an intermediary push gateway for ephemeral jobs. It stores all scrapped samples locally and runs rules on this data to aggregate and log new time series from existing data, or generate alerts. Grafana or other API consumers can be used to visualize the collected data.
Prometheus works well for recording any purely numeric time series. It is suitable for both machine-centric monitoring and monitoring of highly dynamic service-oriented architectures. In the world of microservices, its support for multidimensional data collection and querying is a particular advantage.
Prometheus is designed for reliability, making it the system to use during outages to enable you to diagnose problems quickly. Each Prometheus server is independent and does not rely on network storage or other remote services. You can rely on it when other parts of your infrastructure break, and you don't need to set up extensive infrastructure to use it.
Prometheus values ​​reliability. Even in the event of a failure, you can always view available statistics about your system. If you need 100% accuracy (such as per-request billing), Prometheus is not a good choice because the data collected may not be detailed and complete enough. In this case, it's better to use another system to collect and analyze data for billing and use Prometheus for the rest of the monitoring.
4. Deploy Prometheus

1. Installation on an external network
1.1. Install Docker
Install docker under the Linux operating system and execute it when the network is connected

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all yum makecache fastyum -y install docker-ce

Set up startup

systemctl enable docker

1.2. Install Prometheus
1.2.1 Load the Prometheus image

docker load -i prometheus_v2.14.0.tar

1.2.2 Running Prometheus

docker run –always –name prometheus -d -p 9090:9090 -v /root/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/prometheus/config/mysql.alerts.yml:/etc/prometheus/mysql.alerts.yml prom/prometheus:v2.14.0

2. Intranet installation (recommended)
2.1. Upload and decompress the program package
Upload the program package:

prometheus-2.16.0.linux-amd64.tar.gz

Unzip the package:

tar -xvf prometheus-2.16.0.linux-amd64.tar.gz -C /usr/local/

Insert image description here

2.2. Install Prometheus
and configure the prometheus.yml file (only configure the red content)
command:

vi /usr/local/rometheus-2.16.0.linux-amd64/prometheus.yml

Insert image description here

2.3 Start Prometheus
Start command:
nohup /usr/local/rometheus-2.16.0.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.16.0.linux-amd64/prometheus.yml >> /usr/local/prometheus-2.16.0.linux-amd64/prometheus.log 2>&1 &
or
nohup /usr/local/prometheus-2.16.0.linux-amd64/prometheus >> /usr/local/prometheus -2.16.0.linux-amd64/prometheus.log 2>&1 &

3. Install host monitoring exporter

3.1. Install
the package under Windows: wmi_exporter-0.9.0-amd64.msi.
Insert image description hereYou can check whether the process exists through the task manager.
Insert image description here
Is the service installed under running
Insert image description here
3.2.Linux
? Package: node_exporter-0.18.1.linux-amd64.tar.gz
(1) Install node-exporter on the monitored machine

tar -xvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/

(2) Start node-exporter
background startup:

nohup /usr/local/node_exporter-0.18.1.linux-amd64/node_exporter >> /usr/local/node_exporter-0.18.1.linux-amd64/node_exporter.log 2>&1 &

Insert image description here
(3) Check whether the startup is successful

ps aux|grep node_exporter

Insert image description here

Note: Check whether the server's firewall is turned on. Please turn it off.
LIUNX 7 open port command:

   firewall-cmd --zone=public --add-port=9100/tcp –permanent
或 systemctl stop firewalld**

3.3 Configure Prometheus and restart to take effect.
Each time you add an exporter, you need to add a target under the configuration file config/prometheus.yml. There are comments in the configuration file.

Order:cd /root/prometheus/config/

Insert image description here
The contents include one for configuring the LIUNX host and the other for configuring the windows host. If there are multiple hosts, just configure multiple IPs.

  - job_name: 'Linux主机'
    relabel_configs:
    - source_labels: [__address__]
      target_label: instance
      regex: ^(.+)(:[0-9]+)$
      replacement: ${1}
      action: replace
    static_configs:
- targets: ['172.16.20.28:9100']

  - job_name: 'Windows主机'
    relabel_configs:
    - source_labels: [__address__]
      target_label: instance
      regex: ^(.+)(:[0-9]+)$
      replacement: ${1}
      action: replace
    static_configs:
- targets: ['192.168.8.141:9182', '192.168.13.163:9182']

Restart after adding host configuration:

1. Intranet installation restart:
query process

ps aux|grep prometheus

Kill the process Kill -9 Start
the process number checked above

nohup /usr/local/rometheus-2.16.0.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.16.0.linux-amd64/prometheus.yml >> /usr/local/prometheus-2.16.0.linux-amd64/prometheus.log 2>&1 &

or

nohup /usr/local/prometheus-2.16.0.linux-amd64/prometheus >> /usr/local/prometheus-2.16.0.linux-amd64/prometheus.log 2>&1 &

2. Restart the external network installation:
Command: docker restart prometheus
Insert image description here
refer to view all docker: docker ps -a
Insert image description here
4. Verify that
open Prometheus on the web page, port 9090, you can find that the status of the exporter is UP

Visit: http://IP:9090/targets

Guess you like

Origin blog.csdn.net/weixin_47059371/article/details/125197955