What is the Prometheus
1. Brief introduction
Prometheus is an open-source systems monitoring and alerting toolkit originally built at 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 a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project’s governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.
Prometheus is an open source monitoring system derived from SoundCloud’s Warning toolkit. Starting in 2012, many companies and organizations began using Prometheus. The project’s developer and user community is very active, and more and more developers and users are participating in the project. It is currently a separate open source project and is not dependent on any company. To emphasize this and clarify the governance structure of the project, Prometheus joined the Cloud Native Computing Foundation in 2016, following Kurberntes.
- Official document
- Personal translation of Chinese documents
- Program source code
- Simple and easy to install
Characteristics of 2.
- Multidimensional data model
- Flexible query language
- Individual server nodes are independent of distributed storage
- Pull time series data through THE PULL model in HTTP mode
- The push model is also supported through an intermediate gateway
- Discover target service objects through service discovery or static configuration
- Support for a wide variety of charts and interface presentations, which is also supported by Grafana
The installation of the Prometheus
1. Install the pre-compiled binary compressed file
Tar -xzvf Prohetheus -xxx.tar.gz Go to the decompressed directory and run the prometheus.yml command to modify the configuration file. ./prometheus –config.file=prometheus.yml
The runtime console may say: transport: http2Client. NotifyError got notified that the client transport was broken unexpected of. The solution given by the official issue is to modify the bash configuration file and restart it to take effect.
2. Docker image installation
3. Source code installation (go environment required)
4. Configure the management system for three parties
The use of Prometheus
1. Components
Prometheus’ monitoring and alarm services are in the form of components and configurations. For a client to be monitored, it is necessary to install a component to obtain monitoring data or to implement Prometheus’ data interface and pass the monitoring data to the monitoring server. In the case of no special needs to choose the official provided by the official component or the official recommended tripartite component library, it is more convenient to use and stability is guaranteed.
- Alertmanager alarm components, receiving Prometheus to send the alarm data, and according to the configuration way of alarm (email, hipchat webhook, wechat, etc.) to send alarm information.
- Node_exporter Node monitoring component (an official core component for monitoring hardware). Running on a computer, node_exporter can collect hardware information and network information
- Pushgateway Proxy component for sending and receiving data, which is recommended for monitoring short-term tasks: tasks send data to PushGateway, from which Prometheus obtains monitoring data
- Blackbox_exporter monitors whether the network is normal and services are available. Example
- Mysqld_miner An official monitoring component provided by mysql that collects mysql monitoring data and is available to the Prometheus server. Many applications provide a monitoring component for getting their own data for Prometheus, so all you have to do is configure the component and run it to collect data.
- Grafana is not a component of Prometueus and the primary user presents monitoring data. The original Prometheus interface did not display well and has been officially deprecated in favor of the better grafana, *2.5.0 (2015-10-28)* and later versions of Ganfana support Prometheus well.
2. Configure Prometheus
Since Prmetheus is componentized, component composition depends entirely on configuration files. For details, see Premetheus Configuration configuring Monitored Objects Configuring Alarm Component Installation Configuring Grafana Installing Grafana
3. Monitoring data management
Data storage location Management official documents local storage, storage location specified at startup: / Prometheus –storage.tsdb.path=somePath Specifies the storage time management (default: 15 days) for remote storage. Check whether the server disk can store monitoring data files. Note Whether Prometheus has read and write permissions on remote files specified at startup:./ Prometheus –storage.tsdb.retention=15d
4. Environment construction example
prometheus + grafana + node + alert
Download the compressed software package:
Download the latest version of Prometheus from Prometheus website, Node_Exporter, AlertManager download the latest version of Grafana from The Grafana website
Configure node_EXPORTER to the monitoring server
Go to the directory where Prometheus decompressed,vim Prometheus. Yml, and add the following Settings:
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: -targets: ['127.0.0.1:9090'] -job_name: 'node' [' 127.0.0.1:9100]Copy the code
Start node_exporter: to extract node_exporter directory, execute: / node_exporter started after a successful open a browser and enter: http://127.0.0.1:9100/metrics after the success will be showed as follows:
To start Prometheus, go to the directory where Prometheus is decompressed, and run./ Prometheus –config.file= Prometheus. After the success of the http://127.0.0.1:9090/graph will display:
Click Status -> Targets. If you can see that there are two programs being monitored, and both of them are in
UP
Status, the configuration is successful
Add alarms for Prometheus
Configuration file processing
- Go to the AlertManager directory,
vim alertmanager.yml
Add:
global:
# The smarthost and SMTP sender used for mail notifications.
smtp_smarthost: 'you email host:587'
smtp_from: '[email protected]'
smtp_auth_username: '[email protected]'
smtp_auth_password: 'email_password'
resolve_timeout: 5m
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'web.hook'
receivers:
- name: 'web.hook'
email_configs:
- to: 'receive alert email account'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
Copy the code
- Go to Prometheus and create the alert.rules file
vim alert.rules
Add:
groups:
- name: example
rules:
# Alert for any instance that is unreachable for >5 minutes.
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
# Alert for any instance that has a median request latency >1s.
- alert: APIHighRequestLatency
expr: api_http_request_latencies_second{quantile="0.5"} > 1
for: 10m
annotations:
summary: "High request latency on {{ $labels.instance }}"
description: "{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)"
Copy the code
- Configure alarm rules and alarm components into Prometheus:
vim prometheus.yml
, add the following Settings:
rule_files:
- "test_alert.rules"
# Alerting specifies settings related to the Alertmanager.Alerting: AlertManagers: - Static_configs: -targets: ['127.0.0.1:9093']Copy the code
Start alertManager. Go to the directory where alertManager is decompressed and enter./ alertManager –config.file= AlertManager. yml. http://127.0.0.1:9093/#/alerts If the following information is displayed, the system is successfully started:
Restart premotheus (ctrl + c
After turning it off, press the command above to restart it.)
Added Grafana to beautify the output interface
- Start grafana and go to the grafana unzip directory and type:
./bin/grafana-server web
Enter:http://localhost:3000Username: admin Password: admin The page is displayed without changing the password - Configure Prometheus to DataSource:
- Add template: Click
+
-> import
Add the template ID to the box below and click Load to see the effect. Find the template here :grafana official template library
After the load succeeds, you need to specify which data source the template will be used for (check the data source you just configured).
After checking it, you can see that import can be clicked. After clicking it, the monitoring page is officially entered:
That’s it for simple use
Configuration case [other] www.cnblogs.com/iiiiher/p/8…