前面我们讲到了 OpenObserve 的基本使用,使用 Fluentd 将日志采集后输出到了 OpenObserve,此外 OpenObserve 还支持指标和链路追踪。

指标

OpenObserve 除了支持日志之外,也支持指标数据的摄取,它支持 Prometheus 的远程写入协议,这样我们就可以直接将 Prometheus 的数据远程写入到 OpenObserve 中了。

下面的资源清单就是一个简单的 Prometheus 示例,我们使用 node_exporter 来采集节点的指标数据,然后通过 Prometheus 将其远程写入到 OpenObserve 中:

# prometheus.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
  namespace: openobserve
data:
  prometheus.yaml: |
    global:
      scrape_interval: 15s
      scrape_timeout: 15s
    remote_write:  # 写入到远程 OO,url 是远程写入接口地址
    - url: http://openobserve.openobserve.svc.cluster.local:5080/api/default/prometheus/api/v1/write
      basic_auth:
        username: root@example.com
        password: root321
      # queue_config:    # 如果 Prometheus 抓取指标很大,可以加调整 queue,但是会提高内存占用
      #   max_samples_per_send: 10000  # 每次发送的最大样本数
      #   capacity: 20000
      #   max_shards: 30   # 最大分片数,即并发量。
    scrape_configs:
    - job_name: "nodes"
      static_configs:
      - targets: ['10.206.16.6:9100', '10.206.16.5:9100', '10.206.16.10:9100']
      relabel_configs: # 通过 relabeling 从 __address__ 中提取 IP 信息,为了后面验证 VM 是否兼容 relabeling
      - source_labels: [__address__]
        regex: "(.*):(.*)"
        replacement: "${1}"
        target_label: 'ip'
        action: replace
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus
  namespace: openobserve
spec:
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      containers:
        - args:
            - --config.file=/etc/prometheus/prometheus.yaml
            - --storage.tsdb.path=/prometheus
            - --storage.tsdb.retention.time=4h
            - --web.enable-lifecycle
          image: prom/prometheus:v2.44.0
          imagePullPolicy: IfNotPresent
          name: prometheus
          ports:
            - containerPort: 9090
              name: http
              protocol: TCP
          securityContext:
            runAsUser: 0
          volumeMounts:
            - mountPath: /etc/prometheus
              name: config-volume
            - mountPath: /prometheus
              name: data
      volumes:
        - name: data
          emptyDir: {}
        - configMap:
            defaultMode: 420
            name: prometheus-config
          name: config-volume
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus
  namespace: openobserve
spec:
  ports:
    - name: http
      port: 9090
      targetPort: 9090
  selector:
    app: prometheus
  type: NodePort