prometheus:开源的系统监控和警报工具包,所采集的监控数据均以指标的形式保存再内置的时间序列数据库当中
监控包括:宿主机或自身系统的cpu,内存使用状况
组成:
- server-收集和存储时间序列
- Client library:用于client访问server
- Exporter-各种专用export,面向硬件,存储,数据库,http等
- Alertmanager-处理报警
- Pushgateway-对于短暂运行的任务,负责接收和缓存时间序列数据,同时也是一个数据源
- Node exporter:安装在监控的服务器上,用于暴露metrics给Prometheus;其中metrics包括cpu的负载,内存的使用情况,网络等
相关
- Counter:累加的metric,如请求的个数,结束的任务数等
- Gauge:常规的metric,如温度,运行的goroutines的个数
- Histogram:柱状图,如请求持续时间,响应大小
- Summary:类似于histogram,提供观测值的count和sum功能
- Instance:一个单独的scrape目标,一般对应于一个进程
- Jobs:一组同类型的instances
安装
- wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
- tar xvfz prometheus-2.10.0.linux-amd64.tar.gz
- 启动:./prometheus --config.file=prometheus.yml
- 在监控机器上下载node export: wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
- tar -xf node_exporter-0.14.0.linux-amd64.tar.g
- cp node_exporter-0.14.0.linux-amd64/node_exporter /usr/local/sbin/
- /usr/local/sbin/node_exporter
配置
- 通过修改/home/prometheus/prometheus-2.10.0.linux-amd64/prometheus.yml 添加target增加监控机器,在graph—graph/console可查看监控信息
- targets: ['ip:9100']
labels:
group: 'gitlab'
metrics和lables的命名规则
度量指标:metrics和lables(度量指标名称和标签,每一个时间序列数据都由度量指标名称和标签lables键值对集合唯一确定)
metric
符合有效数字的数据模型
与度量所属相关的应用前缀,通常是应用程序名称本身,eg:
prometheus_notifications_total
process_cpu_...
必须有一个单位(使用基本的单位,秒,字节,米等)
lables:区分被测物体的特征
api_http_requests_total - differentiate request types: type="create|update|delete"
api_request_duration_seconds - differentiate request stages: stage="extract|transform|load"