$ brew install node_exporter
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask-versions and homebrew/cask).
==> Downloading https://homebrew.bintray.com/bottles/node_exporter-0.18.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/ff/ff7b019285ebd031d6985bb06e4300518c9e07f01536ebb5281e4970818cb8a3?__gda__=exp=1573171435~hmac=467cbe2
######################################################################## 100.0%
==> Pouring node_exporter-0.18.1.mojave.bottle.tar.gz
==> Caveats
When used with `brew services`, node_exporter's configuration is stored as command line flags in
/usr/local/etc/node_exporter.args
Example configuration:
echo --web.listen-address :9101 > /usr/local/etc/node_exporter.args
For the full list of options, execute
node_exporter -h
To have launchd start node_exporter now and restart at login:
brew services start node_exporter
Or, if you don't want/need a background service you can just run:
node_exporter
==> Summary
? /usr/local/Cellar/node_exporter/0.18.1: 8 files, 16MB
$ node_exporter --version
node_exporter, version (branch: , revision: )
build user:
build date:
go version: go1.12.5
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz && tar -zxf node_exporter-0.18.1.linux-amd64.tar.gz && cd node_exporter-0.18.1.linux-amd64/ && sudo cp node_exporter /usr/local/bin/
$ node_exporter --web.listen-address=":9600" --web.telemetry-path="/node_metrics"
INFO[0000] Starting node_exporter (version=, branch=, revision=) source="node_exporter.go:156"
INFO[0000] Build context (go=go1.12.5, user=, date=) source="node_exporter.go:157"
INFO[0000] Enabled collectors: source="node_exporter.go:97"
INFO[0000] - boottime source="node_exporter.go:104"
INFO[0000] - cpu source="node_exporter.go:104"
INFO[0000] - diskstats source="node_exporter.go:104"
INFO[0000] - filesystem source="node_exporter.go:104"
INFO[0000] - loadavg source="node_exporter.go:104"
INFO[0000] - meminfo source="node_exporter.go:104"
INFO[0000] - netdev source="node_exporter.go:104"
INFO[0000] - textfile source="node_exporter.go:104"
INFO[0000] - time source="node_exporter.go:104"
INFO[0000] Listening on :9600 source="node_exporter.go:170"
$ curl http://localhost:9600/node_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"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 8
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.12.5"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
和
Disabled by default`),如node_exporter --no-collector.arp
Name | Description | OS |
---|---|---|
arp | Exposes ARP statistics from /proc/net/arp. | Linux |
bcache | Exposes bcache statistics from /sys/fs/bcache/. | Linux |
bonding | Exposes the number of configured and active slaves of Linux bonding interfaces. | Linux |
boottime | Exposes system boot time derived from the kern.boottimesysctl. | Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD, Solaris |
conntrack | Shows conntrack statistics (does nothing if no /proc/sys/net/netfilter/ present). | Linux |
cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux, Solaris |
cpufreq | Exposes CPU frequency statistics | Linux, Solaris |
diskstats | Exposes disk I/O statistics. | Darwin, Linux, OpenBSD |
edac | Exposes error detection and correction statistics. | Linux |
entropy | Exposes available entropy. | Linux |
exec | Exposes execution statistics. | Dragonfly, FreeBSD |
filefd | Exposes file descriptor statistics from /proc/sys/fs/file-nr. | Linux |
filesystem | Exposes filesystem statistics, such as disk space used. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD |
hwmon | Expose hardware monitoring and sensor data from /sys/class/hwmon/. | Linux |
infiniband | Exposes network statistics specific to InfiniBand and Intel OmniPath configurations. | Linux |
ipvs | Exposes IPVS status from /proc/net/ip_vs and stats from /proc/net/ip_vs_stats. | Linux |
loadavg | Exposes load average. | Darwin, Dragonfly, FreeBSD, Linux, NetBSD, OpenBSD, Solaris |
mdadm | Exposes statistics about devices in /proc/mdstat (does nothing if no /proc/mdstat present). | Linux |
meminfo | Exposes memory statistics. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD |
netclass | Exposes network interface info from /sys/class/net/ | Linux |
netdev | Exposes network interface statistics such as bytes transferred. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD |
netstat | Exposes network statistics from /proc/net/netstat. This is the same information as netstat -s. | Linux |
nfs | Exposes NFS client statistics from /proc/net/rpc/nfs. This is the same information as nfsstat -c. | Linux |
nfsd | Exposes NFS kernel server statistics from /proc/net/rpc/nfsd. This is the same information as nfsstat -s. | Linux |
pressure | Exposes pressure stall statistics from /proc/pressure/. | Linux (kernel 4.20+ and/or CONFIG_PSI) |
schedstat | Exposes task scheduler statistics from /proc/schedstat. | Linux |
sockstat | Exposes various statistics from /proc/net/sockstat. | Linux |
stat | Exposes various statistics from /proc/stat. This includes boot time, forks and interrupts. | Linux |
textfile | Exposes statistics read from local disk. The --collector.textfile.directory flag must be set. | any |
thermal_zone | Exposes thermal zone & cooling device statistics from /sys/class/thermal. | Linux |
time | Exposes the current system time. | any |
timex | Exposes selected adjtimex(2) system call stats. | Linux |
uname | Exposes system information as provided by the uname system call. | Darwin, FreeBSD, Linux, OpenBSD |
vmstat | Exposes statistics from /proc/vmstat. | Linux |
xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+) |
zfs | Exposes ZFS performance statistics. | Linux, Solaris |
$ mkdir -p /var/lib/node_exporter/textfile_collector
metadata{role="docker_server",datacenter="NJ"} 1
$ echo 'metadata{role="docker_server",datacenter="NJ"} 1' | sudo tee /var/lib/node_exporter/textfile_collector/metadata.prom
Password:
metadata{role="docker_server",datacenter="NJ"} 1
--collector.systemd.unit-whitelist
参数配置,它会匹配systemd正则表达式node_exporter --collector.textfile.directory="/var/lib/node_exporter/textfile_collector/" --collector.systemd
[vagrant@lab1 ~]$ node_exporter
INFO[0000] Starting node_exporter (version=0.18.1, branch=HEAD, revision=3db77732e925c08f675d7404a8c46466b2ece83e) source="node_exporter.go:156"
INFO[0000] Build context (go=go1.12.5, user=root@b50852a1acba, date=20190604-16:41:18) source="node_exporter.go:157"
INFO[0000] Enabled collectors: source="node_exporter.go:97"
INFO[0000] - arp source="node_exporter.go:104"
INFO[0000] - bcache source="node_exporter.go:104"
INFO[0000] - bonding source="node_exporter.go:104"
INFO[0000] - conntrack source="node_exporter.go:104"
INFO[0000] - cpu source="node_exporter.go:104"
INFO[0000] - cpufreq source="node_exporter.go:104"
INFO[0000] - diskstats source="node_exporter.go:104"
INFO[0000] - edac source="node_exporter.go:104"
INFO[0000] - entropy source="node_exporter.go:104"
INFO[0000] - filefd source="node_exporter.go:104"
INFO[0000] - filesystem source="node_exporter.go:104"
INFO[0000] - hwmon source="node_exporter.go:104"
INFO[0000] - infiniband source="node_exporter.go:104"
INFO[0000] - ipvs source="node_exporter.go:104"
INFO[0000] - loadavg source="node_exporter.go:104"
INFO[0000] - mdadm source="node_exporter.go:104"
INFO[0000] - meminfo source="node_exporter.go:104"
INFO[0000] - netclass source="node_exporter.go:104"
INFO[0000] - netdev source="node_exporter.go:104"
INFO[0000] - netstat source="node_exporter.go:104"
INFO[0000] - nfs source="node_exporter.go:104"
INFO[0000] - nfsd source="node_exporter.go:104"
INFO[0000] - pressure source="node_exporter.go:104"
INFO[0000] - sockstat source="node_exporter.go:104"
INFO[0000] - stat source="node_exporter.go:104"
INFO[0000] - textfile source="node_exporter.go:104"
INFO[0000] - time source="node_exporter.go:104"
INFO[0000] - timex source="node_exporter.go:104"
INFO[0000] - uname source="node_exporter.go:104"
INFO[0000] - vmstat source="node_exporter.go:104"
INFO[0000] - xfs source="node_exporter.go:104"
INFO[0000] - zfs source="node_exporter.go:104"
INFO[0000] Listening on :9100 source="node_exporter.go:170"
node_exporter --collector.systemd.unit-whitelist="(docker|ssh|rsyslog).service"
[vagrant@lab2 ~]$ node_exporter --collector.systemd.unit-whitelist="(docker|ssh|rsyslog).service"
INFO[0000] Starting node_exporter (version=0.18.1, branch=HEAD, revision=3db77732e925c08f675d7404a8c46466b2ece83e) source="node_exporter.go:156"
INFO[0000] Build context (go=go1.12.5, user=root@b50852a1acba, date=20190604-16:41:18) source="node_exporter.go:157"
INFO[0000] Enabled collectors: source="node_exporter.go:97"
INFO[0000] - arp source="node_exporter.go:104"
INFO[0000] - bcache source="node_exporter.go:104"
INFO[0000] - bonding source="node_exporter.go:104"
INFO[0000] - conntrack source="node_exporter.go:104"
INFO[0000] - cpu source="node_exporter.go:104"
INFO[0000] - cpufreq source="node_exporter.go:104"
INFO[0000] - diskstats source="node_exporter.go:104"
INFO[0000] - edac source="node_exporter.go:104"
INFO[0000] - entropy source="node_exporter.go:104"
INFO[0000] - filefd source="node_exporter.go:104"
INFO[0000] - filesystem source="node_exporter.go:104"
INFO[0000] - hwmon source="node_exporter.go:104"
INFO[0000] - infiniband source="node_exporter.go:104"
INFO[0000] - ipvs source="node_exporter.go:104"
INFO[0000] - loadavg source="node_exporter.go:104"
INFO[0000] - mdadm source="node_exporter.go:104"
INFO[0000] - meminfo source="node_exporter.go:104"
INFO[0000] - netclass source="node_exporter.go:104"
INFO[0000] - netdev source="node_exporter.go:104"
INFO[0000] - netstat source="node_exporter.go:104"
INFO[0000] - nfs source="node_exporter.go:104"
INFO[0000] - nfsd source="node_exporter.go:104"
INFO[0000] - pressure source="node_exporter.go:104"
INFO[0000] - sockstat source="node_exporter.go:104"
INFO[0000] - stat source="node_exporter.go:104"
INFO[0000] - textfile source="node_exporter.go:104"
INFO[0000] - time source="node_exporter.go:104"
INFO[0000] - timex source="node_exporter.go:104"
INFO[0000] - uname source="node_exporter.go:104"
INFO[0000] - vmstat source="node_exporter.go:104"
INFO[0000] - xfs source="node_exporter.go:104"
INFO[0000] - zfs source="node_exporter.go:104"
INFO[0000] Listening on :9100 source="node_exporter.go:170"
scrape_configs
部分,Node Exporter默认抓取路径是/metrics
,重启Prometheus服务器scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['11.11.11.111:9100', '11.11.11.112:9100', '11.11.11.113:9100']
11.11.11.111:9100/metrics
scrape_configs:
...
- job_name: 'node'
static_configs:
- targets: ['11.11.11.111:9100', '11.11.11.112:9100', '11.11.11.113:9100']
params:
collect[]:
- cpu
- meminfo
- diskstats
- netdev
- netstat
- filefd
- filesystem
- xfs
- systemd
curl -g -X GET http://11.11.11.111:9100/metrics?collect[]=cpu
docker run --volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker:/var/lib/docker:ro \
--volume=/dev/disk:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
--volume=/sys:/sys:ro
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['138.197.26.39:9100', '138.197.30.147:9100', '138.197.30.163:9100']
- job_name: 'docker'
static_configs:
- targets: ['138.197.26.39:8080']
scrape_configs:
- job_name: 'node'
scheme: https
metrics_path: /moremetrics
static_configs:
- targets: ['138.197.26.39:9100', '138.197.30.147:9100', '138.197.30.163:9100']
更改或添加标签会创建新的时间序列
- job_name: 'docker'
static_configs:
- targets: ['138.197.26.39:8080', '138.197.30.147:8080', '138.197.30.163:8080']
metric_relabel_configs:
- source_labels: [__name__]
regex: '(container_tasks_state|container_memory_failures_total)'
action: drop
- job_name: 'docker'
static_configs:
- targets: ['138.197.26.39:8080', '138.197.30.147:8080', '138.197.30.163:8080']
metric_relabel_configs:
- source_labels: [__name__]
separator: ','
regex: '(container_tasks_state|container_memory_failures_total)'
action: drop
regex1;regex2;regex3
id="/docker/6f823kdj39892jd8j3jid983ujj8edjie99djc883mnbnc8833nccllddklsoow838ckkc8"
metric_relabel_configs:
- source_labels: [id]
regex: '/docker/([a-z0-9]+)'
replacement: '$1'
target_label: container_id
metric_relabel_configs:
- regex: '/docker/([a-z0-9]+)'
action: labeldrop
node_cpu_seconds_total{cpu="cpu0",instance="138.197.26.39.9100",job="node",mode="user"}
irate(node_cpu_seconds_total{job="node"}[5m])
avg(irate(node_cpu_seconds_total{job="node"}[5m])) by (instance)
avg(irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) by (instance) * 100
100 - avg(irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) by (instance) * 100
count by (instance)(node_cpu_seconds_total{mode="idle"})
node_load1 > on (instance) 2 * count by (instance)(node_cpu_seconds_total{mode="idle"})
(总内存-(可用内存+缓冲缓存中的内存+页面缓存中的内存))÷总内存×100
(node_memory_MemTotal_bytes - (node_memory_MemFree_bytes + node_memory_Cached_bytes + node_memory_Buffers_bytes)) / node_memory_MemTotal_bytes * 100
1024 * sum by (instance) (
(rate(node_vmstat_pgpgin[1m])
+ rate(node_vmstat_pgpgout[1m]))
)
(node_filesystem_size_bytes{mountpoint="/"}) - node_filesystem_free_bytes{mountpoint="/") / node_filesystem_size_bytes{mountpoint="/"} * 100
predict_linear(node_filesystem_free_bytes{mountpoint="/"}[1h], 4*3600) < 0
node_systemd_unit_state{name="docker.service",state="active"}
up{job="<job-name>", instance="<instance-id>"}
metadata{role="docker_server",datacenter="NJ"} 1
更改标签或添加新标签都会创建新的时间序列
metadata{datacenter!="NJ"}
node_system_unit_state{name="docker.service"} == 1 and on (instance, job) metadata{datacenter="SF"}
node_system_unit_state{instance="138.197.30.147:9100", job="node", name="docker.service", state="active"}
global:
scrape_interval: 15s
evaluation_interval: 15s
mkdir -p rules
cd rules
touch node_rules.yml
rule_files:
- "rules/node_rules.yml"
group:
- name: node_rules
rules:
- record: instance:node_cpu:avg_rate5m
expr: 100 - avg(irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) by (instance) * 100
level:metric:operations
instance:node_cpu:avg_rate5m
group:
- name: node_rules
rules:
- record: instance:node_cpu:avg_rate5m
expr: 100 - avg(irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) by (instance) * 100
labels:
metric_type: aggregation
group:
- name: node_rules
rules:
- record: instance:node_cpu:avg_rate5m
expr: 100 - avg(irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) by (instance) * 100
- record: instance:node_memory_usage:percentage
expr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes + node_memory_Cached_bytes + node_memory_Buffers_bytes)) / node_memory_MemTotal_bytes * 100
- record: instance:root:node_filesystem_usage:percentage
expr: (node_filesystem_size_bytes{mountpoint="/"} - node_filesystem_free_bytes{mountpoint="/"}) / node_filesystem_size_bytes{mountpoint="/"} * 100
sudo rpm --import https://packagecloud.io/gpg.key
[grafana]
name=grafana
baseurl=https://packagecloud.io/grafana/stable/el/7/$basearch
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
sudo yum install grafana
brew install grafana
sudo service grafana-server start
brew services start grafana