Prometheus Up & Running
  • Introduction
  • PART I -- Introduction
    • 1.What Is Prometheus?
      • What Is Monitoring?
        • A Brief and Incomplete History of Monitoring
        • Categories of Monitoring
      • Prometheus Architecture
        • Client Libraries
        • Exporters
        • Service Discovery
        • Scraping
        • Storage
        • Dashboards
        • Recording Rules and Alerts
        • Alert Management
        • Long-Term Storage
      • What Prometheus Is Not
    • 2.Getting Started with Prometheus
      • Running Prometheus
      • Using the Expression Browser
      • Running the Node Exporter
      • Alerting
  • Part II. Application Monitoring(建议直接跳至5.Labels)
    • 3.Instrumentation
      • A Simple Program
      • The Counter
        • Counting Exceptions
        • Counting Size
      • The Gauge
        • Using Gauges
        • Callbacks
      • The Summary
      • The Histogram
        • Buckets
      • Unit Testing Instrumentation
      • Approaching Instrumentation
        • What Should I Instrument?
        • How Much Should I Instrument?
        • What Should I Name My Metrics?
    • 4. Exposition
      • Python
        • WSGI
        • Twisted
        • Multiprocess with Gunicorn
      • Go
      • Java
        • HTTPServer
        • Servlet
      • Pushgateway
      • Bridges
      • Parsers
      • Exposition Format
        • Metric Types
        • Labels
        • Escaping
        • Timestamps
        • check metrics
    • 5. Labels
      • What Are Labels?
      • Instrumentation and Target Labels
      • Instrumentation
        • Metric
        • Multiple Labels
        • Child
      • Aggregating
      • Label Patterns
        • Enum
        • Info
      • When to Use Labels
        • Cardinality
    • 6. Dashboarding with Grafana
      • Installation
      • Data Source
      • Dashboards and Panels
        • Avoiding the Wall of Graphs
      • Graph Panel
        • Time Controls
      • Singlestat Panel
      • Table Panel
      • Template Variables
  • Part III. Infrastructure Monitoring
    • 7.Node Exporter
      • CPU Collector
      • Filesystem Collector
      • Diskstats Collector
      • Netdev Collector
      • Meminfo Collector
      • Hwmon Collector
      • Stat Collector
      • Uname Collector
      • Loadavg Collector
      • Textfile Collector
        • Using the Textfile Collector
        • Timestamps
    • 8.Service Discovery
      • Service Discovery Mechanisms
        • Static
        • File
        • Consul
        • EC2
      • Relabelling
        • Choosing What to Scrape
        • Target Labels
      • How to Scrape
        • metric_relabel_configs
        • Label Clashes and honor_labels
    • 9.Containers and Kubernetes
      • cAdvisor
        • CPU
        • Memory
        • Labels
      • Kubernetes
        • Running in Kubernetes
        • Service Discovery
        • kube-state-metrics
    • 10.Common Exporters
      • Consul
      • HAProxy
      • Grok Exporter
      • Blackbox
        • ICMP
        • TCP
        • HTTP
        • DNS
        • Prometheus Configuration
    • 11.Working with Other Monitoring Systems
      • Other Monitoring Systems
      • InfluxDB
      • StatsD
    • 12.Writing Exporters
      • Consul Telemetry
      • Custom Collectors
        • Labels
      • Guidelines
  • Part IV. PromQL
    • 13.Introduction to PromQL
      • Aggregation Basics
        • Gauge
        • Counter
        • Summary
        • Histogram
      • Selectors
        • Matchers
        • Instant Vector
        • Range Vector
        • Offset
      • HTTP API
        • query
        • query_range
    • 14.Aggregation Operators
      • Grouping
        • without
        • by
      • Operators
        • sum
        • count
        • avg
        • stddev and stdvar
        • min and max
        • topk and bottomk
        • quantile
        • count_values
    • 15.Binary Operators
      • Working with Scalars
        • Arithmetic Operators
        • Comparison Operators
      • Vector Matching
        • One-to-One
        • Many-to-One and group_left
        • Many-to-Many and Logical Operators
      • Operator Precedence
    • 16.Functions
      • Changing Type
        • vector
        • scalar
      • Math
        • abs
        • ln, log2, and log10
        • exp
        • sqrt
        • ceil and floor
        • round
        • clamp_max and clamp_min
      • Time and Date
        • time
        • minute, hour, day_of_week, day_of_month, days_in_month, month, and year
        • timestamp
      • Labels
        • label_replace
        • label_join
      • Missing Series and absent
      • Sorting with sort and sort_des
      • Histograms with histogram_quantile
      • Counters
        • rate
        • increase
        • irate
        • resets
      • Changing Gauges
        • changes
        • deriv
        • predict_linear
        • delta
        • idelta
        • holt_winters
      • Aggregation Over Time
    • 17.Recording Rules
      • Using Recording Rules
      • When to Use Recording Rules
        • Reducing Cardinality
        • Composing Range Vector Functions
        • Rules for APIs
        • How Not to Use Rules
      • Naming of Recording Rules
  • Part V. Alerting
    • 18.Alerting
      • Alerting Rules
        • for
        • Alert Labels
        • Annotations and Templates
        • What Are Good Alerts?
      • Configuring Alertmanagers
        • External Labels
    • 19.Alertmanager
      • Notification Pipeline
      • Configuration File
      • Alertmanager Web Interface
  • Part VI. Deployment
    • 20.Putting It All Together
      • Planning a Rollout
        • Growing Prometheus
      • Going Global with Federation
      • Long-Term Storage
      • Running Prometheus
        • Hardware
        • Configuration Management
        • Networks and Authentication
      • Planning for Failure
        • Alertmanager Clustering
        • Meta- and Cross-Monitoring
      • Managing Performance
        • Detecting a Problem
        • Finding Expensive Metrics and Targets
        • Reducing Load
        • Horizontal Sharding
      • Managing Change
      • Getting Help
Powered by GitBook
On this page

Was this helpful?

  1. PART I -- Introduction
  2. 2.Getting Started with Prometheus

Running Prometheus

Previous2.Getting Started with PrometheusNextUsing the Expression Browser

Last updated 6 years ago

Was this helpful?

从Prometheus网站 获得编译好的Prometheus和其他组件。 转到该页面,使用amd64架构的下载可以适用于Linux操作系统的最新版本的Prometheus; 下载页面如图所示,我们下载下面的release而不是rc的。

这里我下载的是 prometheus-2.6.1.linux-amd64.tar.gz,任何2.x.x版本的Prometheus都足以满足本章的要求。解压文件并进入目录

$ wget https://github.com/prometheus/prometheus/releases/download/v2.6.1/prometheus-2.6.1.linux-amd64.tar.gz
$ tar -zxf prometheus-*.linux-amd64.tar.gz
$ cd prometheus-*.linux-amd64/

官方自带了个实例的配置文件,我们把它备份后用下面内容创建prometheus的配置文件prometheus.yml

global:
  scrape_interval: 10s
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets:
          - localhost:9090

Prometheus优先使用Yet Another Markup Language(YAML)作为配置文件,因为它既易于使用 人类可以通过工具加工。 格式对空白敏感,因此请确保准确复制示例并使用空格而不是制表符,并不会阻止你使用json。

附带有promtool可以检查配置文件的错误,检查文件是否正确

./promtool check config prometheus.yml
Checking prometheus.yml
  SUCCESS: 0 rule files found

默认prometheus会监听TCP的9090端口,配置文件里每隔10秒scrape自己的metrics,下面来运行prometheus

$ ./prometheus
level=info ts=2019-01-22T07:35:15.200658518Z caller=main.go:243 msg="Starting Prometheus" version="(version=2.6.1, branch=HEAD, revision=b639fe140c1f71b2cbad3fc322b17efe60839e7e)"
level=info ts=2019-01-22T07:35:15.200745786Z caller=main.go:244 build_context="(go=go1.11.4, user=root@4c0e286fe2b3, date=20190115-19:12:04)"
level=info ts=2019-01-22T07:35:15.200787708Z caller=main.go:245 host_details="(Linux 4.13.0-43-generic #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 258c0505930c (none))"
level=info ts=2019-01-22T07:35:15.200858577Z caller=main.go:246 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-01-22T07:35:15.200886497Z caller=main.go:247 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-01-22T07:35:15.201740888Z caller=web.go:429 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-01-22T07:35:15.201672651Z caller=main.go:561 msg="Starting TSDB ..."
level=info ts=2019-01-22T07:35:15.215188095Z caller=main.go:571 msg="TSDB started"
level=info ts=2019-01-22T07:35:15.215264666Z caller=main.go:631 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2019-01-22T07:35:15.216085652Z caller=main.go:657 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2019-01-22T07:35:15.216168709Z caller=main.go:530 msg="Server is ready to receive web requests."

这是表达式浏览器,您可以从中运行PromQL查询。 UI中还有其他几个页面可帮助您了解Prometheus正在执行的操作,例如Status选项卡下的Targets页面

在此页面上,只有一个Prometheus服务器处于UP状态,这意味着最后一次刮擦(scrape)成功。 如果上次刮擦出现问题,则“ERROR”字段中会显示一条消息 您应该看到的另一个页面是Prometheus本身的度量信息(metrics),因为Prometheus本身也配备了Prometheus指标。 可以通过访问http://localhost:9090/metrics查看可用的度量标准,并且是人类可读的,如图

请注意,不仅有Prometheus代码本身的指标,还有Go的runtimes和进程信息

如您所见,Prometheus在启动时的log里打印了各种有用的信息,包括其确切的版本和运行它的机器的详细信息。 现在,您可以在浏览器中访问的Prometheus用户界面,如下所示

http://localhost:9090/
https://prometheus.io/download/