一. VictoriaMetrics
官方文档
- 它可以作为 Prometheus 的长期储存,且支持 Prometheus 查询 API,可以在 Grafana 中用作 Prometheus 的代替品
- 对于低于每秒一百万个数据点的摄取率,建议使用单节点版本而不是集群版本。单节点版本可根据 CPU 内核、RAM 和可用存储空间的数量进行扩展。单节点版本比集群版本更容易配置和操作,所以在使用集群版本之前要三思而后行。上面我们介绍了 VM 的单节点版本的基本使用,接下来我们来介绍下如何使用集群版
- 集群版主要特点:
- 支持单节点版本的所有功能
- 性能和容量水平扩展
- 支持时间序列数据的多个独立命名空间(多租户)
- 支持多副本
1. 集群版介绍
文档说明
1). 组件说明
- vmstorage:存储原始数据并返回指定标签过滤器在给定时间范围内的查询数据,当
-storageDataPath
指向的目录包含的可用空间少于 -storage.minFreeDiskSpaceBytes
时,vmstorage
节点会自动切换到只读模式,vminsert
节点也会停止向此类节点发送数据并开始将数据重新路由到剩余的 vmstorage
节点 - vminsert:接受摄取的数据并根据指标名称及其所有标签的一致性哈希将其分散存储到
vmstorage
节点 - **vmselect:**通过从所有配置的
vmstorage
节点获取所需数据来执行查询 VictoriaMetrics
各个组件中的每个服务都可以进行独立扩展,vmstorage
节点之间互不了解、互不通信,并且不共享任何数据。这样可以增加集群的可用性,并且简化了集群的维护和扩展
2). 最小集群
- 必须包含节点:
- 带有
-retentionPeriod
和 -storageDataPath
参数的单 vmstorage
节点 - 带有
-storageNode=<vmstorage_host>
的单 vminsert
节点 - 带有
-storageNode=<vmstorage_host>
的单 vmselect
节点
3). 可用性
- 如果至少存在一个
vmstorage
节点,则集群仍然可用
vminsert
将传入数据从不可用的 vmstorage
节点重新路由到健康的 vmstorage
节点- 如果至少有一个
vmstorage
节点可用,则 vmselect
会继续提供部分响应。如果优先考虑可用性的一致性,则将 -search.denyPartialResponse
标志传递给 vmselect
或将请求中的 deny_partial_response=1
查询参数传递给 vmselect
4). 集群配置
http://<vmselect>:8481/select/<accountID>/prometheus/<suffix>
2. 配置清单
1). vmstorage.yaml
apiVersion: v1
kind: Service
metadata:
name: cluster-vmstorage
namespace: prometheus
labels:
app: vmstorage
spec:
clusterIP: None
ports:
- port: 8482
targetPort: http
name: http
- port: 8401
targetPort: vmselect
name: vmselect
- port: 8400
targetPort: vminsert
name: vminsert
selector:
app: vmstorage
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: vmstorage
namespace: prometheus
labels:
app: vmstorage
spec:
serviceName: cluster-vmstorage
selector:
matchLabels:
app: vmstorage
replicas: 2
template:
metadata:
labels:
app: vmstorage
spec:
containers:
- name: vmstorage
image: harbor.yeemiao.net.cn/library/vmstorage:v1.91.1-cluster
imagePullPolicy: IfNotPresent
args:
- --retentionPeriod=3
- --storageDataPath=/storage
- --envflag.enable=true
- --envflag.prefix=VM_
- --loggerFormat=json
ports:
- name: http
containerPort: 8482
- name: vminsert
containerPort: 8400
- name: vmselect
containerPort: 8401
livenessProbe:
failureThreshold: 10
initialDelaySeconds: 30
periodSeconds: 30
tcpSocket:
port: http
timeoutSeconds: 5
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 15
timeoutSeconds: 5
httpGet:
path: /health
port: http
volumeMounts:
- name: storage
mountPath: /storage
- name: time
mountPath: /etc/localtime
volumes:
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
volumeClaimTemplates:
- metadata:
name: storage
spec:
storageClassName: managed-nfs-storage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "50Gi"
2). vminsert.yaml
apiVersion: v1
kind: Service
metadata:
name: vminsert
namespace: prometheus
labels:
app: vminsert
spec:
ports:
- name: http
port: 8480
targetPort: http
selector:
app: vminsert
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: vminsert
namespace: prometheus
labels:
app: vminsert
spec:
replicas: 2
selector:
matchLabels:
app: vminsert
template:
metadata:
labels:
app: vminsert
spec:
containers:
- name: vminsert
image: harbor.yeemiao.net.cn/library/vminsert:v1.91.1-cluster
imagePullPolicy: IfNotPresent
args:
- --storageNode=vmstorage-0.cluster-vmstorage.$(NAMESPACE).svc.cluster.local:8400
- --storageNode=vmstorage-1.cluster-vmstorage.$(NAMESPACE).svc.cluster.local:8400
- --envflag.enable=true
- --envflag.prefix=VM_
- --loggerFormat=json
ports:
- name: http
containerPort: 8480
env:
- name: NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 5
periodSeconds: 15
timeoutSeconds: 5
failureThreshold: 3
livenessProbe:
tcpSocket:
port: http
initialDelaySeconds: 5
periodSeconds: 15
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- mountPath: /etc/localtime
name: time
volumes:
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
3). vmselect.yaml
apiVersion: v1
kind: Service
metadata:
name: vmselect
namespace: prometheus
labels:
app: vmselect
spec:
ports:
- name: http
port: 8481
targetPort: http
selector:
app: vmselect
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: vmselect
namespace: prometheus
labels:
app: vmselect
spec:
replicas: 2
selector:
matchLabels:
app: vmselect
template:
metadata:
labels:
app: vmselect
spec:
containers:
- name: vmselect
image: harbor.yeemiao.net.cn/library/vmselect:v1.91.1-cluster
imagePullPolicy: IfNotPresent
args:
- --cacheDataPath=/cache
- --storageNode=vmstorage-0.cluster-vmstorage.$(NAMESPACE).svc.cluster.local:8401
- --storageNode=vmstorage-1.cluster-vmstorage.$(NAMESPACE).svc.cluster.local:8401
- --envflag.enable=true
- --envflag.prefix=VM_
- --loggerFormat=json
ports:
- name: http
containerPort: 8481
env:
- name: NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 5
periodSeconds: 15
timeoutSeconds: 5
failureThreshold: 3
livenessProbe:
tcpSocket:
port: http
initialDelaySeconds: 5
periodSeconds: 15
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- mountPath: /cache
name: cache-volume
- mountPath: /etc/localtime
name: time
volumes:
- name: cache-volume
emptyDir: {}
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai