上篇回顾
分布式可观测性 Logging 浅谈
分布式可观测性 Structured Log
继续浅谈Observability的另1个基石
在单体式架构上,主要的监控对象是OS与机器这物理节点, 所以经常直接使用OS自带的工具.
以Linux来说top
来看每个Process的CPU使用率、记忆体用量, mpstat
, vmstat
, iostat
等等的.
Windows则是Task manager.
透过这些OS提供的命令与工具来监控.
但在现在分布式架构下, 数十数百台机器或是在VM上的OS, 监控的可观测性成了挑战.
於是陆续诞生了Cacti、Zabbix、Prometheus等很多监控系统,
它们的特色是metrics数据的收集、数据的存放、数据的查询展示都分离开来. 彼此透过网路协议与介面来传递资料.
现在常见的架构有两种,
一种是数据的收集以Library形式, 与业务系统整合在程序专案中,
在程序码埋点的方式, 以Client调用的角度, 把调用资源或服务的耗时、请求量、慢查询量,
甚至能收集GC的资讯等等的送给另一个独立出来的数据处理服务去做处理与分析.
以Go来说, Prometheus就有提供这样的Library
Go自带的pprof其实也是一种
另一种则是以Agent(Sidecar)或Exporter形式, 由它来负责数据收集与数据做处理 .
通常它会负责采集特定指标资讯例如, 主机资讯, 或是各Process的CPU用量, 记忆体用量.
Prometheus提供非常多exporter来采集特定指标
之後要介绍的Fluent-bit或Promtail则是以Agent形式
5种常见的Metrics类型
这里主要依据Prometheus提供的Metric Types
type Gauge interface {
Metric
Collector
// Set sets the Gauge to an arbitrary value.
Set(float64)
// Inc increments the Gauge by 1. Use Add to increment it by arbitrary
// values.
Inc()
// Dec decrements the Gauge by 1. Use Sub to decrement it by arbitrary
// values.
Dec()
// Add adds the given value to the Gauge. (The value can be negative,
// resulting in a decrease of the Gauge.)
Add(float64)
// Sub subtracts the given value from the Gauge. (The value can be
// negative, resulting in an increase of the Gauge.)
Sub(float64)
// SetToCurrentTime sets the Gauge to the current Unix time in seconds.
SetToCurrentTime()
}
type Counter interface {
Metric
Collector
// Inc increments the counter by 1. Use Add to increment it by arbitrary
// non-negative values.
Inc()
// Add adds the given value to the counter. It panics if the value is <
// 0.
Add(float64)
}
type Histogram interface {
Metric
Collector
// Observe adds a single observation to the histogram. Observations are
// usually positive or zero. Negative observations are accepted but
// prevent current versions of Prometheus from properly detecting
// counter resets in the sum of observations. See
// https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
// for details.
Observe(float64)
}
type Summary interface {
Metric
Collector
// Observe adds a single observation to the summary. Observations are
// usually positive or zero. Negative observations are accepted but
// prevent current versions of Prometheus from properly detecting
// counter resets in the sum of observations. See
// https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
// for details.
Observe(float64)
}
Metrics的强大在於几乎可以针对任意指标进行数值计算後, 决定展示或是通知报警.
至於到底要对什麽指标做监控. 这才是重要的思考点
也许有人想到Response time做监控, 只要系统回应时间逐渐变慢, 就报警通知
也许是针对错误日志发生的速率, 做计算後超过一个阀值做通知
也许是资源超过一个阀值, 做通知
Mettrics的设计也不是一蹴而就的, 要慢慢根据具体的需求变化反覆跌带来更新设计.
>>: [ 卡卡 DAY 22 ] - React Native 元件害羞之骨架屏先让你瞧 react-native-skeleton-placeholder
元件介绍 Pagination 是一个分页元件,当页面中一次要载入过多的资料时,载入及渲染将会花费更...
预处理器可以透过加快撰写程序的速度,但是自己的打字速度提升有限(换了Mac之後还变慢不少),Emme...
今日任务 1. Q&A Section (原生JS写法) Codepen Link: htt...
Ktor Plugin & DSL Ktor 的架构设计是让开发者透过实作 plugin,把...
Day 14 - 安装与执行 YOLO 在 介绍影像辨识的处理流程 - Day 10 有提到 YOL...