Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get started with Prometheus

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to get started with Prometheus, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Introduction to Prometheus

Prometheus started as a monitoring software open source by SoundCloud. Since its establishment in 2012, many companies and organizations have been using Prometheus.

The official GitHub address is https://github.com/prometheus/prometheus

Official address: https://prometheus.io/

2. Characteristics of Prometheus

A multidimensional data model that contains time series data identified by metric names and key/value pairs

PromQL, a flexible query language, can take advantage of this dimension

Independent of distributed storage, a single server node can work directly

Collecting time series by pull based on HTTP

Push time series is supported by PushGateway components

Discover targets through service discovery or static configuration

Multiple graphics and dashboard support modes (grafana)

module

Prometheus Server, mainly used for crawling data and storing time series data, but also provides query and Alert Rule configuration management.

Alertmanager is mainly responsible for realizing the alarm function.

Push Gateway, a collection node for batch and short-term monitoring data, can receive various index data from Client push and be accessed and crawled by the main program at a specified time interval.

* _ exporter, all kinds of data reporting.

Infrastructure construction

From this architecture diagram, you can also see that the main modules of Prometheus include Server, Exporters, Pushgateway, PromQL, Alertmanager, WebUI, and so on.

It uses logic roughly like this:

Prometheus server periodically pulls data from statically configured targets or service-discovered targets.

When the newly pulled data is larger than the configured memory cache, Prometheus persists the data to disk (if you use Remote Storage to persist it to the cloud).

Prometheus can configure rules, and then query the data regularly, and when the condition is triggered, the alert will be pushed to the configured Alertmanager.

When Alertmanager receives a warning, it can be configured, aggregated, de-duplicated, reduced noise, and finally sent a warning.

You can query and aggregate data using API, Prometheus Console, or Grafana.

Prometheus vs Zabbix

Zabbix uses C and PHP, and Prometheus uses Golang. Overall, Prometheus runs faster.

Zabbix belongs to traditional host monitoring, which is mainly used for physical host, switch, network and other monitoring. Prometheus is not only suitable for host monitoring, but also suitable for Cloud, SaaS, Openstack,Container monitoring.

Zabbix has richer plug-ins in traditional host monitoring.

Zabbix can configure many things in WebGui, but Prometheus needs to manually modify the file configuration

3. Prometheus deployment

1. Download the installation package prometheus-2.4.0.linux-amd64.tar.gz

Github download address: https://github.com/prometheus/prometheus/releases/tag/v2.4.0

two。 Decompression

$tar xf prometheus-2.14.0.linux-amd64.tar.gz-C / usr/local/$ ln-s / usr/local/prometheus-2.14.0.linux-amd64/ / usr/local/prometheus

Create system

$vim / etc/systemd/system/prometheus.service [root@linux-node1 ~] # vim / etc/systemd/system/prometheus.service [Unit] Description=PrometheusWants=network-online.targetAfter=network-online.target [Service] User=rootGroup=rootType=simpleExecStart=/usr/local/prometheus/prometheus\-- config.file=/usr/local/prometheus/ prometheus.yml [install] WantedBy=multi-user.target

3. Configure prometheus.yml (keep the default configuration)

$vim / usr/local/prometheus/prometheus.yml # my global configglobal: 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 configurationalerting: 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= `to any timeseries scraped from this config. -job_name: 'prometheus' # metrics_path defaults to' / metrics' # scheme defaults to 'http'. Static_configs:-targets: ['localhost:9090']

4. Start

$systemctl daemon-reload$ systemctl start prometheus.service $systemctl enable prometheus.service / / Prometheus Server launches the default port-9090$ netstat-lntup | grep "9090" tcp6 0: 9090:: * LISTEN 3393/./prometheus

5. Access the monitoring interface included with http://ip:9090/Prometheus

4. Grafana deployment

Grafana is an open source application written in go language, which is mainly used for the visualization of large-scale index data. It is the most popular time series data display tool in network architecture and application analysis. At present, it has supported most of the commonly used time series databases.

Grafana supports many different data sources. Each data source has a specific query editor whose customized features and functions are exposed specific data sources. The following data sources are officially supported: Graphite,Elasticsearch,InfluxDB,Prometheus,Cloudwatch,MySQL, OpenTSDB, etc.

Grafana documents: https://grafana.com/docs/grafana/latest/installation/rpm/

1. Install Grafana

Install using the rpm package here

$wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-6.3.7-1.x86_64.rpm$ rpm-I-- nodeps grafana-6.3.7-1.x86_64.rpm

two。 Start Grafana and join the auto-boot

$systemctl start grafana-server.service $systemctl enable grafana-server.service / / Grafana launches the default port-3000$ netstat-lntup | grep "3000" tcp6 00:: 3000:: * LISTEN 3585/grafana-server

3. Visit grafana

The browser accesses the IP:3000 port to open the grafana page. The default user name and password are all admin. The default login password will be changed for the first login.

4. Add data source

(1) Click "Add data source" on the main interface

(2) Select Prometheus

(3) Select Prometheus 2.0 Stats for Dashboards page

(4) enter the Prometheus address on the Settings page and save it

(5) switch to the Prometheus 2.0 Stats we just added to see the entire monitoring page.

So now Prometheus does not have any monitoring data.

5. Node-Exporter deployment

If you need to monitor server CPU, memory, disk, IZP O and other information, you need to install node_exporter first.

The role of node_exporter is for machine system data collection.

Download address:

Https://github.com/prometheus/node_exporter/releases/

Https://prometheus.io/download/

1. Install node_exporter

$tar xf node_exporter-0.18.1.linux-amd64.tar.gz-C / usr/local/$ ln-s / usr/local/node_exporter-0.18.1.linux-amd64/ / usr/local/node_exporter

Create a system service

$vim / etc/systemd/system/node_ exporter.service[ Unit] Description=node_exporterAfter= network.target[ service] Type=simpleUser=rootExecStart=/usr/local/node_exporter/node_exporterRestart=on-failure [Install] WantedBy=multi-user.target

two。 Start node-exporter

$systemctl daemon-reload$ systemctl start node_exporter.service $systemctl enable node_exporter.service// Node Exporter default port-9100$ netstat-lntup | grep "9100" tcp6 00:: 9100:: * LISTEN 5122/node_exporter

The default crawl address for 3.Node Exporter is http://IP:9100/metrics.

$curl http://127.0.0.1:9100/metrics

4.Prometheus profile adds monitored machines

/ / the default node-exporter port is 9100$ vim / usr/local/prometheus/prometheus.yml-job_name: 'prometheus' static_configs:-targets: [' localhost:9100']-job_name: 'node_exporter_centos' scrape_interval: 5s static_configs:-targets: [' 10.0.0.171usr/local/prometheus/prometheus.yml 9100']

There are two monitors defined in prometheus.yml: one is to monitor prometheus's own service, and the other is to monitor the Linux server.

5. Restart the prometheus service

$systemctl restart prometheus

6.Grafana installs dashboards of Node Exporter

Download address: https://grafana.com/grafana/dashboards/11074/revisions

(1) Import the downloaded .json ending file into Grafana, and select the corresponding data source

(2) you can see a lot of charts through Node Exporter's dashboards.

The above content is how to get started with Prometheus. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report