$ brew install prometheus
prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
$ prometheus --config.file ./prometheus.yml
level=info ts=2019-11-07T14:45:47.188Z caller=main.go:293 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-11-07T14:45:47.188Z caller=main.go:329 msg="Starting Prometheus" version="(version=2.11.1, branch=non-git, revision=non-git)"
level=info ts=2019-11-07T14:45:47.188Z caller=main.go:330 build_context="(go=go1.12.7, user=brew@Mojave-2.local, date=20190711-02:47:26)"
level=info ts=2019-11-07T14:45:47.188Z caller=main.go:331 host_details=(darwin)
level=info ts=2019-11-07T14:45:47.188Z caller=main.go:332 fd_limits="(soft=4864, hard=unlimited)"
level=info ts=2019-11-07T14:45:47.188Z caller=main.go:333 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-11-07T14:45:47.189Z caller=main.go:652 msg="Starting TSDB ..."
level=info ts=2019-11-07T14:45:47.189Z caller=web.go:448 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-11-07T14:45:47.195Z caller=main.go:667 fs_type=19
level=info ts=2019-11-07T14:45:47.195Z caller=main.go:668 msg="TSDB started"
level=info ts=2019-11-07T14:45:47.195Z caller=main.go:738 msg="Loading configuration file" filename=./prometheus.yml
level=info ts=2019-11-07T14:45:47.707Z caller=main.go:766 msg="Completed loading of configuration file" filename=./prometheus.yml
level=info ts=2019-11-07T14:45:47.707Z caller=main.go:621 msg="Server is ready to receive web requests."
$ promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 0 rule files found
$ docker run -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
level=info ts=2019-11-07T14:51:10.156Z caller=main.go:296 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-11-07T14:51:10.156Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.1, branch=HEAD, revision=6f92ce56053866194ae5937012c1bec40f1dd1d9)"
level=info ts=2019-11-07T14:51:10.156Z caller=main.go:333 build_context="(go=go1.13.1, user=root@88e419aa1676, date=20191017-13:15:01)"
level=info ts=2019-11-07T14:51:10.156Z caller=main.go:334 host_details="(Linux 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64 765454899e9c (none))"
level=info ts=2019-11-07T14:51:10.156Z caller=main.go:335 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-11-07T14:51:10.156Z caller=main.go:336 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-11-07T14:51:10.158Z caller=main.go:657 msg="Starting TSDB ..."
level=info ts=2019-11-07T14:51:10.159Z caller=web.go:450 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-11-07T14:51:10.161Z caller=head.go:514 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2019-11-07T14:51:10.161Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
level=info ts=2019-11-07T14:51:10.162Z caller=main.go:672 fs_type=EXT4_SUPER_MAGIC
level=info ts=2019-11-07T14:51:10.162Z caller=main.go:673 msg="TSDB started"
level=info ts=2019-11-07T14:51:10.162Z caller=main.go:743 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2019-11-07T14:51:10.165Z caller=main.go:771 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2019-11-07T14:51:10.165Z caller=main.go:626 msg="Server is ready to receive web requests."
$ curl http://localhost:9090/metrics
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.9736e-05
go_gc_duration_seconds{quantile="0.25"} 5.9597e-05
go_gc_duration_seconds{quantile="0.5"} 0.000154742
go_gc_duration_seconds{quantile="0.75"} 0.000280268
go_gc_duration_seconds{quantile="1"} 0.00042205
go_gc_duration_seconds_sum 0.001300487
go_gc_duration_seconds_count 7
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 45
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.13.1"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_gc_duration_seconds{quantile="0.5"} 0.000154742
promhttp_metric_handler_requests_total
指标来看rate(prometheus_tsdb_head_samples_appended_total[1m])
sum(count by (__name__)({__name__=~".+"}))
100,000 * 2 bytes * 43200 seconds