docker compose 部署 grafana + loki + vector 监控kafka消息

news2024/11/28 11:35:31

Centos7 随笔记录记录 docker compose 统一管理 granfana + loki + vector  监控kafka 信息。

当然如果仅仅是想通过 Grafana 监控kafka,推荐使用 Grafana Prometheus 通过JMX监控kafka

目录

1. 目录结构

2. 前提已安装Docker-Compose

3. docker-compose 自定义服务相关配置文件

3.1  配置 docker-compose-grafana-loki-vector.yml 文件

3.2 创建 loki-config.yaml 

3.3 配置loki 服务

4. docker-compose  单独启动指定服务

4.1 单独启动 loki 

4.1.1 启动loki

4.1.2 查询 log 

4.2 单独启动vector 

4.2.1 启动 vector

4.2.2 查询vector log 

4.2.2.1 错误log 问题定位 

4.2.2.2 解决方法

4.2.2.3 重启vector 容器,查看无error log

4.3 单独启动grafana 

4.3.1 启动 grafana 

4.3.2 查看 grafana log 

4.3.2.1 错误log 问题定位 

4.3.2.2 解决方法

4.3.2.3 重启grafana 容器,查看无error log

4.3.3 访问grafana 

4.4  查看loki metrics数据  和loki 运行状态

5. docker-compose  启停所有服务

5.1 docker-compose 启动所有自定义容器服务

5.2 docker-compose 停止所有容器服务

6. 配置grafana

6.1 添加loki 数据源

6.2 修改时区

6.3 添加query 

6.4 过滤展示kafka 消息

6.5 优化后 dashboard, 展示kafka 指定字段 

6.5.1 添加添加dashboard

6.5.2 优化dashboard, 显示指定字段

6.5.2.1  筛选kafka 原始消息

 6.5.2.2 优化表格显示指定字段

7. 其他异常问题

7.1  grafana 页面有时跳转 网址 http://localhost:3000/XXXX 错误

7.2 跳转错误网址原因定位 

7.3 解决方法

7.3.1 Grafana 服务的环境变量 GF_SERVER_ROOT_URL 设置为正确的访问地址

7.3.2 为了grafana 有数据,必须修改vector.tml 配置参数

7.3.3 使配置生效

 7.4 验证 跳转网址正确


1. 目录结构

# 1 创建 4个文件夹:grafana loki vector wal 
# 2 为 wal 赋777 权限

[root@localhost grafana_loki_vector]# pwd
/home/magx/Docker-Compose-Master/grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1859 Dec 26 10:58 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# tree
.
├── docker-compose-grafana-loki-vector.yml
└── grafana_loki_vector                     # 创建 grafana folder 
    ├── grafana
    ├── loki                                # 创建 loki folder
    │   └── loki-config.yaml
    ├── vector                              # 创建 vector folder
    │   └── vector.toml
    └── wal                                 # 创建 wal folder,并赋 777 权限
     

8 directories, 5 files
[root@localhost grafana_loki_vector]#


# 为避免docker 中权限问题,为wal folder 赋权限

[root@localhost grafana_loki_vector]# pwd
/home/magx/Docker-Compose-Master/grafana_loki_vector/grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# chmod 777 wal
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# ll
total 0
drwxr-xr-x. 4 root root 41 Dec 26 10:04 grafana
drwxr-xr-x. 2 root root 44 Dec 26 10:47 loki
drwxr-xr-x. 2 root root 33 Dec 21 15:03 vector
drwxrwxrwx. 3 root root 59 Dec 26 11:19 wal
[root@localhost grafana_loki_vector]#

2. 前提已安装Docker-Compose

如何安装 Docker-Compose,请参考 安装部署Docker-Compose

3. docker-compose 自定义服务相关配置文件

3.1  配置 docker-compose-grafana-loki-vector.yml 文件
# docker-compose 配置参考:https://github.com/grafana/loki/blob/master/production/docker-compose.yaml

[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1859 Dec 26 10:58 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# cat docker-compose-grafana-loki-vector.yml

version: "3"   # 这是Docker Compose的版本指定,该配置文件使用版本3的语法

# 网桥loki -> 方便相互通讯
networks:      # 定义了一个名为loki的网络,该网络是为了Loki和其他服务之间相互通信而创建的网桥。
  loki:

services:      # 在这个部分定义了要运行的各个服务
  loki:                                                  # Loki服务的配置
    image: grafana/loki:latest                           # 使用了grafana/loki:latest镜像
    container_name: grafana_loki_vector_demo_loki        # 定义 容器名
    restart: unless-stopped                              # 设置了重启策略
    ports:
      - "3100:3100"   # 将主机的3100端口映射到Loki容器的3100端口,以便能够从主机访问Loki的API
    volumes:          # 将两个主机目录与容器内的目录进行了卷映射
      - ./grafana_loki_vector/loki:/etc/loki  
      - ./grafana_loki_vector/wal:/wal       
    command: -config.file=/etc/loki/loki-config.yaml
    networks:
      - loki

 # vector  用于对接kafka 消息
  vector:                                                # vector 服务的配置
    # 指定使用 timberio/vector的Docker 镜像,并使用0.10.0-alpine 版本
    image: timberio/vector:0.10.0-alpine       
    container_name: grafana_loki_vector_demo_vector      # 定义 容器名
    restart: unless-stopped                   # 指定容器在退出时重新启动,除非显式停止
    ports:
      - "80:80"                               # 容器的 80 端口映射到主机的 80 端口上
    volumes:
      # - ./grafana_loki_vector/vector/logs:/var/logs

      # 本地主机目录./grafana_loki_vector/vector挂载到容器的/etc/vector目录上
      - "./grafana_loki_vector/vector:/etc/vector"

    # 这是要在容器中运行的命令,通过-c /etc/vector/vector.toml指定了配置文件的路径,并通过 -v 启用了详细日志输出
    command: -c /etc/vector/vector.toml -v
    networks:
      - loki

 # 用于UI展示
  grafana:
    image: grafana/grafana:latest
    container_name: grafana_loki_vector_demo_grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - "./grafana_loki_vector/grafana/data:/var/lib/grafana"
      #      - "./grafana_promtail_loki/grafana/config:/etc/grafana"
      - "./grafana_loki_vector/grafana/log:/var/log/grafana"

    environment:
      # GF_EXPLORE_ENABLED: "true"

      # 避免有时Grafana 会将跳转 URL 设置为 "localhost"
      - GF_SERVER_ROOT_URL=http://192.168.2.247:3000  
    networks:
      - loki

 


=====================================================================
配置参数说明:

 volumes:          # 将两个主机目录与容器内的目录进行了卷映射
      - ./grafana_loki_vector/loki:/etc/loki  
      # ./grafana_loki_vector/loki映射到了/etc/loki

      - ./grafana_loki_vector/wal_tmp1:/wal   
      # ./grafana_loki_vector/wal_tmp1映射到了/wal

command: -config.file=/etc/loki/loki-local-config.yaml
# -config.file=/etc/loki/loki-local-config.yaml 指定了Loki容器启动时使用的配置文件路径

environment:
      # 避免有时Grafana 会将跳转 URL 设置为 "localhost"
      - GF_SERVER_ROOT_URL=http://192.168.2.247:3000  
3.2 创建 loki-config.yaml 
创建loki-local-config.yaml 文件,配置loki 服务


[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1857 Dec 26 11:31 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# tree
.
├── docker-compose-grafana-loki-vector.yml
└── grafana_loki_vector
    ├── grafana
    │   ├── data
    │   └── log
    ├── loki
    │   └── loki-config.yaml       # 创建loki-config.yaml文件,配置loki 服务
    ├── vector
    │   └── vector.toml
    └── wal
3.3 配置loki 服务
# 这个是Loki的配置文件示例,其中包含了各个方面的配置,用于自定义和配置Loki日志系统的行为和存储。

auth_enabled: false # 设置认证功能是否启用。设为false表示禁用认证,即任何用户都可以访问Loki服务

server:
  http_listen_port: 3100  # 配置Loki服务监听的HTTP端口。在这个示例中,Loki将监听3100端口

ingester:                 # 配置Loki的ingester(摄取器)相关参数
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:                  # 使用内存作为kvstore存储方式
        store: inmemory
      replication_factor: 1     # 复制因子设置为 1
    final_sleep: 0s
  chunk_idle_period: 5m         # chunk的闲置期 5m
  chunk_retain_period: 30s      # chunk的保留期 30s
 
schema_config:                  # 配置存储模式参数
  configs:
    - from: 2018-04-15          # 从特定日期开始使用的配置
      store: boltdb             # 数据存储方式(boltdb,文件系统)
      object_store: filesystem  # 数据存储方式 (文件系统)
      schema: v9                # schema版本
      index:                    # 索引相关参数
        prefix: index_
        period: 168h

storage_config:                 # 配置存储配置,指定Loki数据的持久化存储位置
  boltdb:
    directory: /tmp/loki/index  # 索引数据将存储在/tmp/loki/index目录

  filesystem:
    directory: /tmp/loki/chunks # chunk数据将存储在/tmp/loki/chunks目录

# 配置限制参数,用于强制限制指标名称、拒绝旧样本数据,以及设置拒绝旧样本数据的最大时间范围
limits_config:     
  enforce_metric_name: false        # 强制限制指标名称
  reject_old_samples: true          # 拒绝旧样本数据
  reject_old_samples_max_age: 168h  # 设置拒绝旧样本数据的最大时间范围

chunk_store_config:                 # 配置chunk存储参数,设置最大回溯时间范围
  max_look_back_period: 0s          # 设置最大回溯时间范围

table_manager:                         # 配置表管理器相关参数
  chunk_tables_provisioning:           # 设置chunk表的吞吐量
    inactive_read_throughput: 0   
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  index_tables_provisioning:           # 设置索引表的吞吐量
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  retention_deletes_enabled: false     # 保留删除是否启用
  retention_period: 0s                 # 保留期设置
    # retention_deletes_enabled: true
    # retention_period: 168h

4. docker-compose  单独启动指定服务

建议docker-compose 自定义多个服务时,先单独启动每个服务调试,没问题后,再统一启动

4.1 单独启动 loki 
4.1.1 启动loki

# 启动指定自定义服务 

#  docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up <服务名> -d


# 启动loki

[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1857 Dec 26 11:31 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#  docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up loki -d
[+] Running 7/7
 ✔ loki 6 layers [⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                        24.0s
   ✔ c926b61bad3b Pull complete                                                                                                                                         12.0s
   ✔ 21a0947e3c21 Pull complete                                                                                                                                          6.0s
   ✔ 19779106cfff Pull complete                                                                                                                                         17.5s
   ✔ 9c6ee7a30a41 Pull complete                                                                                                                                          7.4s
   ✔ 2f9c53357ffd Pull complete                                                                                                                                          8.7s
   ✔ d8cb9832c63f Pull complete                                                                                                                                         11.4s
[+] Running 1/1
 ✔ Container grafana_loki_vector_demo_loki  Started                                                                                                                      0.2s
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker ps        # 查询启动容器
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                                                                   NAMES
58528f1b4782   grafana/loki:latest      "/usr/bin/loki -conf…"   9 seconds ago   Up 8 seconds   0.0.0.0:3100->3100/tcp, :::3100->3100/tcp                               grafana_loki_vector_demo_loki
c4f7b69648a8   wurstmeister/kafka       "start-kafka.sh"         18 hours ago    Up 18 hours    0.0.0.0:9092->9092/tcp, :::9092->9092/tcp                               kafka
a893cce0d465   wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   18 hours ago    Up 18 hours    22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp   zookeeper
[root@localhost grafana_loki_vector]#

4.1.2 查询 log 
# 查看 loki 容器 log
# docker logs <loki服务容器名>

[root@localhost grafana_loki_vector]# pwd
/home/magx/Docker-Compose-Master/grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1857 Dec 26 11:31 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker logs grafana_loki_vector_demo_loki
level=warn ts=2023-12-26T03:39:33.891828641Z caller=loki.go:286 msg="per-tenant timeout not configured, using default engine timeout (\"5m0s\"). This behavior will change in the next major to always use the default per-tenant timeout (\"5m\")."

''''''
''''''
''''''
level=info ts=2023-12-26T03:44:33.988929326Z caller=checkpoint.go:502 msg="atomic checkpoint finished" old=wal/checkpoint.000006.tmp new=wal/checkpoint.000006
[root@localhost grafana_loki_vector]#
4.2 单独启动vector 
4.2.1 启动 vector

# 启动指定自定义服务 

#  docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up <服务名> -d


# 启动 vector

[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1857 Dec 26 11:31 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up vector -d
[+] Running 6/6
 ✔ vector 5 layers [⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                       30.6s
   ✔ 21c83c524219 Pull complete                                                                                                                                         18.0s
   ✔ 88943f7483ee Pull complete                                                                                                                                          2.9s
   ✔ 24da72aaf03b Pull complete                                                                                                                                         23.4s
   ✔ 4145aaf02e3f Pull complete                                                                                                                                         10.7s
   ✔ b16d307dc057 Pull complete                                                                                                                                         12.0s
[+] Running 1/1
 ✔ Container grafana_loki_vector_demo_vector  Started                                                                                                                    0.3s
[root@localhost grafana_loki_vector]#

[root@localhost grafana_loki_vector]# docker ps        # 查询启动容器
CONTAINER ID   IMAGE                           COMMAND                  CREATED              STATUS              PORTS                                                                   NAMES
776ab907da32   timberio/vector:0.10.0-alpine   "/usr/local/bin/vect…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, :::80->80/tcp                                       grafana_loki_vector_demo_vector
2a5581eea2eb   grafana/loki:latest             "/usr/bin/loki -conf…"   2 minutes ago        Up 2 minutes        0.0.0.0:3100->3100/tcp, :::3100->3100/tcp                               grafana_loki_vector_demo_loki
c4f7b69648a8   wurstmeister/kafka              "start-kafka.sh"         21 hours ago         Up 21 hours         0.0.0.0:9092->9092/tcp, :::9092->9092/tcp                               kafka
a893cce0d465   wurstmeister/zookeeper          "/bin/sh -c '/usr/sb…"   21 hours ago         Up 21 hours         22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp   zookeeper
[root@localhost grafana_loki_vector]#
4.2.2 查询vector log 
# 查看 vector 容器log
# docker logs <vector 容器名>

[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker logs grafana_loki_vector_demo_vector
Dec 26 06:02:01.842  INFO vector: Log level "debug" is enabled.
Dec 26 06:02:01.857  INFO vector: Loading configs. path=["/etc/vector/vector.toml"]
Dec 26 06:02:01.862  INFO vector: Vector is starting. version="0.10.0" git_version="v0.9.0-377-g0f0311a" released="Wed, 22 Jul 2020 20:01:29 +0000" arch="x86_64"
Dec 26 06:02:01.876 DEBUG vector::tls::settings: Fetching system root certs.
Dec 26 06:02:01.876  INFO vector::topology: Running healthchecks.
Dec 26 06:02:01.876  INFO vector::topology: Starting source "in"
Dec 26 06:02:01.876  INFO vector::topology: Starting sink "out"
Dec 26 06:02:01.876 DEBUG http: vector::sinks::util::http: sending request. uri=http://loki:3100/ready method=GET
Dec 26 06:02:01.884 DEBUG http: vector::sinks::util::http: response. status=503 version=HTTP/1.1
Dec 26 06:02:01.885 ERROR vector::topology::builder: Healthcheck: Failed Reason: A non-successful status returned: 503 Service Unavailable         # Error Log
Dec 26 06:02:05.978 DEBUG http: vector::sinks::util::http: sending request. uri=http://loki:3100/loki/api/v1/push method=POST
Dec 26 06:02:06.060 DEBUG http: vector::sinks::util::http: response. status=204 version=HTTP/1.1
[root@localhost grafana_loki_vector]#
4.2.2.1 错误log 问题定位 
# 确认 Vector 可以连接到 Loki 服务
在 Vector 配置文件中配置的 Loki 服务的地址应该是可访问的。
可以尝试使用 curl 或类似的工具连接到 Loki 服务

# curl http://loki:3100/ready

[root@localhost grafana_loki_vector]# curl http://loki:3100/ready
curl: (6) Could not resolve host: loki; Unknown error
[root@localhost grafana_loki_vector]#


总结: curl 请求无法解析 loki 主机名,并出现了 Unknown error 错误,vector 无法连接loki
4.2.2.2 解决方法
1) 检查 DNS 配置:确认您的 DNS 配置正确,可以解析主机名
# nslookup loki

[root@localhost grafana_loki_vector]# nslookup loki
Server:         114.114.114.114
Address:        114.114.114.114#53

** server can't find loki: NXDOMAIN   # loki无法解析为有效的 IP 地址,返回了 NXDOMAIN 错误。

[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#


2)添加主机名映射:如果 DNS 解析不起作用,您可以尝试手动添加主机名到 IP 地址的映射

[root@localhost grafana_loki_vector]# cat /etc/hosts          # 添加前
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost grafana_loki_vector]# 
[root@localhost grafana_loki_vector]# cat /etc/hosts          # 添加后
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.247 loki
[root@localhost grafana_loki_vector]#


3)检查vector 是否可以连接loki
# curl http://loki:3100/ready

[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# curl http://loki:3100/ready
ready                                                # 可以连接loki
[root@localhost grafana_loki_vector]#

4.2.2.3 重启vector 容器,查看无error log
# 重启vector 容器 or 重新创建 vector 容器
# 无error log, vector 服务运行正常

[root@localhost grafana_loki_vector]# docker logs grafana_loki_vector_demo_vector
Dec 26 06:20:58.569  INFO vector: Log level "debug" is enabled.
Dec 26 06:20:58.583  INFO vector: Loading configs. path=["/etc/vector/vector.toml"]
Dec 26 06:20:58.588  INFO vector: Vector is starting. version="0.10.0" git_version="v0.9.0-377-g0f0311a" released="Wed, 22 Jul 2020 20:01:29 +0000" arch="x86_64"
Dec 26 06:20:58.602 DEBUG vector::tls::settings: Fetching system root certs.
Dec 26 06:20:58.602  INFO vector::topology: Running healthchecks.
Dec 26 06:20:58.602  INFO vector::topology: Starting source "in"
Dec 26 06:20:58.602  INFO vector::topology: Starting sink "out"
Dec 26 06:20:58.602 DEBUG http: vector::sinks::util::http: sending request. uri=http://loki:3100/ready method=GET
Dec 26 06:20:58.606 DEBUG http: vector::sinks::util::http: response. status=200 version=HTTP/1.1
Dec 26 06:20:58.607  INFO vector::topology::builder: Healthcheck: Passed.
[root@localhost grafana_loki_vector]#
4.3 单独启动grafana 
4.3.1 启动 grafana 

# 启动指定自定义服务 

#  docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up <服务名> -d

[root@localhost grafana_loki_vector]# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up grafana -d
[+] Running 11/11
 ✔ grafana 10 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                               106.8s
   ✔ 96526aa774ef Pull complete                                                                                                                                          2.3s
   ✔ 8107a14e7703 Pull complete                                                                                                                                          1.4s
   ✔ 41aaa20cd87e Pull complete                                                                                                                                          2.7s
   ✔ e00aef65f013 Pull complete                                                                                                                                          5.1s
   ✔ 257ea9b0297f Pull complete                                                                                                                                          5.5s
   ✔ 599ebbeda3b8 Pull complete                                                                                                                                          6.1s
   ✔ ca6b21901a74 Pull complete                                                                                                                                         59.8s
   ✔ b5fb47d1c454 Pull complete                                                                                                                                         92.5s
   ✔ 4fc0f14a8243 Pull complete                                                                                                                                          8.0s
   ✔ f638e65e9fc0 Pull complete                                                                                                                                         13.7s
[+] Running 1/1
 ✔ Container grafana_loki_vector_demo_grafana  Started                                                                                                                   0.3s
[root@localhost grafana_loki_vector]#
4.3.2 查看 grafana log 
# 查看 vector 容器log
# docker logs <vector 容器名>

[root@localhost grafana_loki_vector]# docker logs grafana_loki_vector_demo_grafana
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
.....
....

[root@localhost grafana_loki_vector]#
4.3.2.1 错误log 问题定位 

这些错误通常表示在容器中的某个目录或文件上没有写入权限。

4.3.2.2 解决方法
# 解决此问题的一种可能方法是确保您在运行容器时具有足够的权限

# 确保您以具有适当权限的用户身份运行 Docker 命令
# sudo usermod -aG docker $USER

# 更改目标目录的所有者和权限
sudo chown -R 472:472 ./grafana_loki_vector/grafana/data
sudo chmod -R 755 ./grafana_loki_vector/grafana/data


# 检查您的目标目录权限,并确保它具有足够的写入权限

[root@localhost grafana_loki_vector]# sudo chmod -R 777 ./grafana_loki_vector/grafana/data
[root@localhost grafana_loki_vector]#
4.3.2.3 重启grafana 容器,查看无error log
 
# 重启grafana 容器 or 重新创建 grafana 容器
# 无error log, grafana服务运行正常

# 此处每次都是:
1) 停止容器 # docker stop <container_ID or container_name>
2) 删除容器 # docker rm <container_ID or container_name>
3) 删除镜像 # docker rmi <image_ID>
4)  创建 grafana 容器
5) 查看 log


[root@localhost grafana_loki_vector]# docker stop 839b53f097ee   # 停止容器
839b53f097ee
[root@localhost grafana_loki_vector]# docker rm 839b53f097ee     # 删除容器
839b53f097ee
[root@localhost grafana_loki_vector]# docker images              # 查询镜像ID
REPOSITORY               TAG             IMAGE ID       CREATED         SIZE
grafana/grafana          latest          8387f19108f9   7 days ago      399MB
grafana/loki             latest          c2c89eb81f6e   13 days ago     67.7MB
hello-world              latest          9c7a54a9a43c   7 months ago    13.3kB
wurstmeister/kafka       latest          a692873757c0   19 months ago   468MB
timberio/vector          0.10.0-alpine   2ebd263245dd   3 years ago     80.7MB
wurstmeister/zookeeper   latest          3f43f72cb283   4 years ago     510MB
[root@localhost grafana_loki_vector]# docker rmi 8387f19108f9     # 删除镜像
Untagged: grafana/grafana:latest
Untagged: grafana/grafana@sha256:6b5b37eb35bbf30e7f64bd7f0fd41c0a5b7637f65d3bf93223b04a192b8bf3e2
Deleted: sha256:8387f19108f986254ecb7eeb1124445a9aeda16602114d98348ed5cd49151a7a
Deleted: sha256:06619c984d0071cd4b3a8fbfb377c1ca5b991497f4e1f6c2f280b9f33d402cb4
Deleted: sha256:5fe5dac0845a9eb44e2c5cfed4fb2754a4adf3224209f58c1a46cb7bd250f2e7
Deleted: sha256:91a3b38581f407bb488e03f002566138875732ba1da4a5e91c55b3dec08a2756
Deleted: sha256:18c0364cc25d61f2e9c8ba8582944e1fc6528ba44abc25ffc3e3bc5ed6a8dec9
Deleted: sha256:e335659dfae7632b652b2c796e742f11b2a9f0c0c7def8511b4df29158a50ee5
Deleted: sha256:5f7c41d4921ce413887919068764757d42744f4898c3f790953fee2e1b33b79b
Deleted: sha256:e8df864ddb32cefc11b6a549add118948327816e858570f6fcbb4b393643d196
Deleted: sha256:14b7f68d3d9094af53f80ebf90273ec864b731545874ee30cfb09cae5d097935
Deleted: sha256:baf151d12231a621fead4ca244823c83fb4ae6e01c36501e37c48a964138e724
Deleted: sha256:cc2447e1835a40530975ab80bb1f872fbab0f2a0faecf2ab16fbbb89b3589438
[root@localhost grafana_loki_vector]#


# 创建 grafana 容器 

[root@localhost grafana_loki_vector]# sudo docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up grafana -d
[+] Running 11/11
 ✔ grafana 10 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                               113.6s
   ✔ 96526aa774ef Pull complete                                                                                                                                         12.7s
   ✔ 8107a14e7703 Pull complete                                                                                                                                          2.3s
   ✔ 41aaa20cd87e Pull complete                                                                                                                                          2.2s
   ✔ e00aef65f013 Pull complete                                                                                                                                         10.4s
   ✔ 257ea9b0297f Pull complete                                                                                                                                          5.5s
   ✔ 599ebbeda3b8 Pull complete                                                                                                                                         10.5s
   ✔ ca6b21901a74 Pull complete                                                                                                                                         83.9s
   ✔ b5fb47d1c454 Pull complete                                                                                                                                         97.5s
   ✔ 4fc0f14a8243 Pull complete                                                                                                                                         17.4s
   ✔ f638e65e9fc0 Pull complete                                                                                                                                         28.6s
[+] Running 1/1
 ✔ Container grafana_loki_vector_demo_grafana  Started                                                                                                                   0.5s
[root@localhost grafana_loki_vector]# 


# 查看 log
[root@localhost grafana_loki_vector]# docker logs grafana_loki_vector_demo_grafana
logger=settings t=2023-12-26T07:25:30.701353225Z level=info msg="Starting Grafana" version=10.2.3 commit=1e84fede543acc892d2a2515187e545eb047f237 branch=HEAD compiled=2023-12-18T15:46:07Z
logger=settings t=2023-12-26T07:25:30.701604782Z level=info msg="Config loaded from" file=/usr/share/grafana/conf/defaults.ini
......
......
...... 

logger=ngalert.scheduler t=2023-12-26T07:26:18.891340858Z level=info msg="Starting scheduler" tickInterval=10s
logger=ticker t=2023-12-26T07:26:18.891454409Z level=info msg=starting first_tick=2023-12-26T07:26:20Z
logger=http.server t=2023-12-26T07:26:18.897364437Z level=info msg="HTTP Server Listen" address=[::]:3000 protocol=http subUrl= socket=
logger=plugins.update.checker t=2023-12-26T07:26:19.502508394Z level=info msg="Update check succeeded" duration=611.312832ms
logger=grafana.update.checker t=2023-12-26T07:26:20.504658267Z level=info msg="Update check succeeded" duration=1.613658029s
logger=infra.usagestats t=2023-12-26T07:26:51.904796949Z level=info msg="Usage stats are ready to report"
[root@localhost grafana_loki_vector]# 
4.3.3 访问grafana 

打开 http://<grafana 容器所在主机IP>:3000

默认 user/pwd: admin/admin

 

4.4  查看loki metrics数据  和loki 运行状态
  #   查看loki metrics数据 
  #  访问:http://<loki 容器所在主机IP>:3100/metrics

#  查看loki运行状态
#  访问:http://<loki 容器所在主机IP>:3100/ready

到此已经调试完成,可以通过docker-compose 统一启动所有服务 

5. docker-compose  启停所有服务

5.1 docker-compose 启动所有自定义容器服务
# 启动 定义服务
# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up -d

[root@localhost grafana_loki_vector]# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up -d
[+] Running 3/3
 ✔ Container grafana_loki_vector_demo_loki     Started                                                                                                                   0.0s
 ✔ Container grafana_loki_vector_demo_vector   Started                                                                                                                   0.0s
 ✔ Container grafana_loki_vector_demo_grafana  Started                                                                                                                   0.0s
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker ps          # 查询启动容器
CONTAINER ID   IMAGE                           COMMAND                  CREATED        STATUS         PORTS                                                                   NAMES
252ca4e81d6f   grafana/grafana:latest          "/run.sh"                2 hours ago    Up 2 seconds   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp                               grafana_loki_vector_demo_grafana
7068d0da2577   timberio/vector:0.10.0-alpine   "/usr/local/bin/vect…"   3 hours ago    Up 2 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp                                       grafana_loki_vector_demo_vector
2a5581eea2eb   grafana/loki:latest             "/usr/bin/loki -conf…"   3 hours ago    Up 2 seconds   0.0.0.0:3100->3100/tcp, :::3100->3100/tcp                               grafana_loki_vector_demo_loki
c4f7b69648a8   wurstmeister/kafka              "start-kafka.sh"         24 hours ago   Up 24 hours    0.0.0.0:9092->9092/tcp, :::9092->9092/tcp                               kafka
a893cce0d465   wurstmeister/zookeeper          "/bin/sh -c '/usr/sb…"   24 hours ago   Up 24 hours    22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp   zookeeper
[root@localhost grafana_loki_vector]#

 

5.2 docker-compose 停止所有容器服务
# docker-compose 停止所有容器服务

# docker-compose -f <docker-compose 自定义容器服务配置 yml 文件> -p <项目名> down


[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1909 Dec 28 17:27 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector down
[+] Running 4/4
 ✔ Container grafana_loki_vector_demo_vector   Removed                                                                                                                   0.4s
 ✔ Container grafana_loki_vector_demo_loki     Removed                                                                                                                   2.0s
 ✔ Container grafana_loki_vector_demo_grafana  Removed                                                                                                                   0.0s
 ✔ Network grafana_loki_vector_loki            Removed                                                                                                                   0.2s
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker ps -a
CONTAINER ID   IMAGE                    COMMAND                  CREATED       STATUS                   PORTS                                                                   NAMES
c4f7b69648a8   wurstmeister/kafka       "start-kafka.sh"         3 days ago    Up 3 days                0.0.0.0:9092->9092/tcp, :::9092->9092/tcp                               kafka
a893cce0d465   wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   3 days ago    Up 3 days                22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp   zookeeper
b38e9b5b6a2e   hello-world              "/hello"                 3 weeks ago   Exited (0) 3 weeks ago                                                                           infallible_rosalind
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker images
REPOSITORY               TAG             IMAGE ID       CREATED         SIZE
grafana/grafana          latest          8387f19108f9   9 days ago      399MB
grafana/loki             latest          c2c89eb81f6e   2 weeks ago     67.7MB
hello-world              latest          9c7a54a9a43c   7 months ago    13.3kB
wurstmeister/kafka       latest          a692873757c0   19 months ago   468MB
timberio/vector          0.10.0-alpine   2ebd263245dd   3 years ago     80.7MB
wurstmeister/zookeeper   latest          3f43f72cb283   4 years ago     510MB
[root@localhost grafana_loki_vector]#

6. 配置grafana

6.1 添加loki 数据源

如果找不到data Source, 可以直接search 查找。

6.2 修改时区

6.3 添加query 
click 'Home' -> Explore -> change 'loki' option

6.4 过滤展示kafka 消息
原始kafka 消息数据:

{
    "currentIndex":0,
    "header":{
        "headerMap":{
            "35":"381166"
        }
    },
    "mapList":[
        {
            "10007":"1"
        },
        {
            "37":"48",
            "38":"300000",
            "44":"15007900",
            "48":"688021",
            "1301":"1",
            "11001":"国盾量子",
            "11436":"20231227",
            "28000":"20231227",
            "28001":"1703642600915",
            "28005":"2",
            "28101":"893786271",
            "43220":"金额:[3000000,450416980],数量:[300000,300100],价格涨跌幅:[0.02,0.19934],市场成交量占比:[0.3,0.967752],区间内最高卖出成交价: 1799.8,昨收盘价: 1500,下单数量: 300000,当前交易价格: 1500.79,挂单数量: 0,挂单金额: 0,成交数量: 100,成交金额: 179980,市场成交数量: 10100",
            "64101":"2403",
            "64102":"1101",
            "64103":"2403-4096个账户-4096个证券",
            "65098":"1",
            "66002":"5",
            "66003":"1",
            "66004":"0",
            "66005":"2",
            "91001":"200000",
            "93020":"2"
        }
    ]
}

将以上kafka 原始消息数据,筛选过滤出指定字段,语句如下: 

# 将以上kafka 原始消息数据,筛选过滤出指定字段,语句如下: 

{key="mag1225"}|= ""|json| line_format "{{.message}}" | json mapList1="mapList[1]",ruleID="mapList[1][\"64101\"]",rcSysId="mapList[1][\"66002\"]",logDate="mapList[1][\"28000\"]",logTime="mapList[1][\"28001\"]",securityExchange="mapList[1][\"1301\"]",threshold="mapList[1][\"43220\"]",stockName="mapList[1][\"11001\"]",securityId="mapList[1][\"48\"]",orderId="mapList[1][\"37\"]",orderBs="mapList[1][\"93020\"]",tradeSysId="mapList[1][\"66003\"]",riskConCaption="mapList[1][\"64103\"]",riskConType="mapList[1][\"64102\"]"|line_format "{{.mapList1}}"| __error__=``

6.5 优化后 dashboard, 展示kafka 指定字段 
{key="mag1225"}|= ""|json| line_format "{{.message}}" | json mapList1="mapList[1]"|line_format "{{.mapList1}}"| __error__=`` 
6.5.1 添加添加dashboard

Clieck 'Add visualizaion' Button  or click 'Add'-> Visualization

6.5.2 优化dashboard, 显示指定字段
6.5.2.1  筛选kafka 原始消息
clieck Query 输入 将 kafka 原始消息数据,筛选过滤出指定字段语句 

过滤语句:
{key="mag1225"}|= ""|json| line_format "{{.message}}" | json mapList1="mapList[1]",ruleID="mapList[1][\"64101\"]",rcSysId="mapList[1][\"66002\"]",logDate="mapList[1][\"28000\"]",logTime="mapList[1][\"28001\"]",securityExchange="mapList[1][\"1301\"]",threshold="mapList[1][\"43220\"]",stockName="mapList[1][\"11001\"]",securityId="mapList[1][\"48\"]",orderId="mapList[1][\"37\"]",orderBs="mapList[1][\"93020\"]",tradeSysId="mapList[1][\"66003\"]",riskConCaption="mapList[1][\"64103\"]",riskConType="mapList[1][\"64102\"]"|line_format "{{.mapList1}}"| __error__=``


注意:
key=<vector.toml 中sinks.out中的自定义的labels.key>


[root@localhost vector]# cat vector.toml


#                                    __   __  __
#                                    \ \ / / / /
#                                     \ V / / /
#                                      \_/  \/
#
#                                    V E C T O R
#                                   Configuration
#
# ------------------------------------------------------------------------------
# Website: https://vector.dev
# Docs: https://vector.dev/docs/
# ------------------------------------------------------------------------------

# Note: A full config spec is located at ./vector.spec.toml and examples
#       in the ./examples folder.


# Vector config kafka + Loki

[ sources.in ]
    type = "kafka"
    bootstrap_servers = "192.168.2.247:9092"      # kafka 地址
    group_id = "kafka_mag_groupId1225"               # "<消费组id>"
    topics = ["alarm_warning","kafka_consumer"]                    # kafka_consumer
    auto_offset_reset = "smallest"                # 从最早未处理的消息开始消费
    # topics = ["^(prefix1|prefix2)-.+", "topic-1", "topic-2"]  # topic名字,支持正则
    #[sources.in.encoding]
    #codec = "json"
        #timestamp_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        #json.fields = ["level", "message"]

[sinks.out]
    endpoint = "http://loki:3100"
    inputs = ["in"]                              # source.in
    type = "loki"
    labels.key = "mag1225"                       # 自定义key
#  labels.key = "{{ event_field }}"              # event的动态值
    #[sinks.out.encoding]
    #codec = "json"
        # timestamp_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        # json.fields = ["level", "message"]
[root@localhost vector]#

 6.5.2.2 优化表格显示指定字段
# 优化已表格显示指定字段


1. Click 'Transform data' --> Add Transformation --> Reformat -> Extract fields
2. 添加Extract files -->Source:Line -->Format:JSON --> 打开 'Replacee all fields' --> 打开'Keep time'


重名列名->调整顺序->显示隐藏指定列,配置如下:
3. click 'Add another transformation' --> 'Reorder and rename' --> 'Organize fields by name' 

 

7. 其他异常问题

7.1  grafana 页面有时跳转 网址 http://localhost:3000/XXXX 错误
grafana 容器所在主机IP:192.168.2.247
grafana web address: http://192.168.2.247:3000
grafana web 页面有时操作跳转 网址:http://localhost:3000/XXXX,导致页面跳转错误
7.2 跳转错误网址原因定位 
原因定位:
 Grafana Explore 页面上的 "Add to Dashboard" 后,跳转网址为 "http://localhost:3000/..." 的问题可能是因为 Grafana 配置中使用了相对 URL 路径导致的
7.3 解决方法
7.3.1 Grafana 服务的环境变量 GF_SERVER_ROOT_URL 设置为正确的访问地址
1. 修改 docker-compose-grafana-loki-vector.yml 文件,
   将 Grafana 服务的环境变量 GF_SERVER_ROOT_URL 设置为正确的访问地址 

environment:
  - GF_SERVER_ROOT_URL=http://192.168.2.247:3000


[root@localhost grafana_loki_vector]# cat docker-compose-grafana-loki-vector.yml
# docker-compose配置参考:https://github.com/grafana/loki/blob/master/production/docker-compose.yaml
version: "3"

# 网桥loki -> 方便相互通讯
networks:
  loki:

services:
  # Loki日志系统
  loki:
    image: grafana/loki:latest
    container_name: grafana_loki_vector_demo_loki
    restart: unless-stopped
    ports:
      - "3100:3100"
    volumes:
      - ./grafana_loki_vector/loki:/etc/loki
      - ./grafana_loki_vector/wal:/wal
    command: -config.file=/etc/loki/loki-config.yaml
    networks:
      - loki

  # 用于UI展示
  grafana:
    image: grafana/grafana:latest
    container_name: grafana_loki_vector_demo_grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - "./grafana_loki_vector/grafana/data:/var/lib/grafana"
      #      - "./grafana_promtail_loki/grafana/config:/etc/grafana"
      - "./grafana_loki_vector/grafana/log:/var/log/grafana"
    environment:
      # GF_EXPLORE_ENABLED: "true"
      - GF_SERVER_ROOT_URL=http://192.168.2.247:3000  # 修改正确网址 grafana 容器所在主机

    networks:
      - loki

  # vector  用于对接kafka 消息
  vector:
    image: timberio/vector:0.10.0-alpine
    container_name: grafana_loki_vector_demo_vector
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      # - ./grafana_loki_vector/vector/logs:/var/logs
      - "./grafana_loki_vector/vector:/etc/vector"
    command: -c /etc/vector/vector.toml -v
    networks:
      - loki

[root@localhost grafana_loki_vector]#
7.3.2 为了grafana 有数据,必须修改vector.tml 配置参数
# 为了grafana 展示kafka 数据,必须修改vector.tml 文件中2个参数
  1. group_id = "kafka_mag_groupId1228"           # 任意值 从 *1225 改为 *1228
  2. labels.key = "mag1228"                       # 自定义key    从 *1225 改为 *1228


[root@localhost grafana_loki_vector]# ll
total 4
-rw-r--r--. 1 root root 1909 Dec 28 17:27 docker-compose-grafana-loki-vector.yml
drwxr-xr-x. 6 root root   78 Dec 26 10:52 grafana_loki_vector
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# cat grafana_loki_vector/vector/vector.toml


#                                    __   __  __
#                                    \ \ / / / /
#                                     \ V / / /
#                                      \_/  \/
#
#                                    V E C T O R
#                                   Configuration
#
# ------------------------------------------------------------------------------
# Website: https://vector.dev
# Docs: https://vector.dev/docs/
# ------------------------------------------------------------------------------

# Note: A full config spec is located at ./vector.spec.toml and examples
#       in the ./examples folder.


# Vector config kafka + Loki

[ sources.in ]
    type = "kafka"
    bootstrap_servers = "192.168.2.247:9092"      # kafka 地址
    group_id = "kafka_mag_groupId1228"               # "<消费组id>" 修改group_ID
    topics = ["alarm_warning","kafka_consumer"]                    # kafka_consumer
    auto_offset_reset = "smallest"                # 从最早未处理的消息开始消费
    # topics = ["^(prefix1|prefix2)-.+", "topic-1", "topic-2"]  # topic名字,支持正则
    #[sources.in.encoding]
    #codec = "json"
        #timestamp_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        #json.fields = ["level", "message"]

[sinks.out]
    endpoint = "http://loki:3100"
    inputs = ["in"]                              # source.in
    type = "loki"
    labels.key = "mag1228"                       # 自定义key
#  labels.key = "{{ event_field }}"              # event的动态值
    #[sinks.out.encoding]
    #codec = "json"
        # timestamp_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        # json.fields = ["level", "message"]
[root@localhost grafana_loki_vector]#
7.3.3 使配置生效
# 使配置生效
2. docker-compose 关闭项目
# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector down

3. docker-copose 启动项目即可。
#  docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up -d



# docker-compose 关闭项目

[root@localhost grafana_loki_vector]# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector down
[+] Running 4/4
 ✔ Container grafana_loki_vector_demo_vector   Removed                                                                                                                   0.5s
 ✔ Container grafana_loki_vector_demo_loki     Removed                                                                                                                   1.7s
 ✔ Container grafana_loki_vector_demo_grafana  Removed                                                                                                                   0.4s
 ✔ Network grafana_loki_vector_loki            Removed                                                                                                                   0.1s
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]#


# docker-copose 启动项目

[root@localhost grafana_loki_vector]#
[root@localhost grafana_loki_vector]# docker-compose -f docker-compose-grafana-loki-vector.yml -p grafana_loki_vector up -d
[+] Running 4/4
 ✔ Network grafana_loki_vector_loki            Created                                                                                                                   0.1s
 ✔ Container grafana_loki_vector_demo_vector   Started                                                                                                                   0.1s
 ✔ Container grafana_loki_vector_demo_grafana  Started                                                                                                                   0.1s
 ✔ Container grafana_loki_vector_demo_loki     Started                                                                                                                   0.1s
[root@localhost grafana_loki_vector]#

 7.4 验证 跳转网址正确
在新页面打开,跳转网址正确  http://192.168.2.247:3000/XXXXX

 

到此基本完成。

当然如果仅仅是想通过 Grafana 监控kafka,推荐使用 Grafana Prometheus 通过JMX监控kafka

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1341470.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

009:vue结合el-table实现表格行拖拽排序(基于sortablejs)

文章目录 1. 实现效果2. 安装 sortablejs 插件3. 完整组件代码4. 注意点 1. 实现效果 2. 安装 sortablejs 插件 sortablejs 更多用法 cnpm i --save sortablejs3. 完整组件代码 <template><div class"home"><div class"body"><el-ta…

车路协同中 CUDA 鱼眼相机矫正、检测、追踪

在车路协同中,鱼眼一般用来补充杆件下方的盲区,需要实现目标检测、追踪、定位。在目标追踪任务中,通常的球机或者枪机方案,无法避免人群遮挡的问题,从而导致较高的ID Swich,造成追踪不稳定。但是鱼眼相机的顶视角安装方式,天然缓解了遮挡的问题,从而实现杆件下方的盲区…

用通俗易懂的方式讲解大模型:Prompt 提示词在开发中的使用

OpenAI 的 ChatGPT 是一种领先的人工智能模型&#xff0c;它以其出色的语言理解和生成能力&#xff0c;为我们提供了一种全新的与机器交流的方式。但不是每个问题都可以得到令人满意的答案&#xff0c;如果想得到你所要的回答就要构建好你的提示词 Prompt。本文将探讨 Prompt 提…

VSCODE : SSH远程配置+免密登录

SSH基础配置 填入地址&#xff0c;回车 ssh userhost-or-ip 然后选择默认的配置&#xff0c;回车&#xff0c;得到以下结果&#xff1a; 点击链接 选择远程的系统 输入密码 免密登录 生成SSH密钥&#xff1a; 首先&#xff0c;确保你已经在本地生成了SSH密钥。你可以使…

Hive中支持毫秒级别的时间精度

实际上&#xff0c;Hive 在较新的版本中已经支持毫秒级别的时间精度。你可以通过设置 hive.exec.default.serialization.format 和 mapred.output.value.format 属性为 1&#xff0c;启用 Hive 的时间精度为毫秒级。可以使用以下命令进行设置&#xff1a; set hive.exec.defau…

unity学习笔记----游戏练习02

一、阳光值的展示和消耗 1.创建一个文本组件用于显示阳光的数值&#xff0c;然后在脚本中得到这个UI。 在SunManger中得到这个组件的引用 public TextMeshProUGUI sunPointText; 写一个用于更新显示的方法 public void UpdataSunPointText() { sunPointText.tex…

IntelliJ IDE 插件开发 | (四)开发一个时间管理大师插件

系列文章 IntelliJ IDE 插件开发 |&#xff08;一&#xff09;快速入门IntelliJ IDE 插件开发 |&#xff08;二&#xff09;UI 界面与数据持久化IntelliJ IDE 插件开发 |&#xff08;三&#xff09;消息通知与事件监听IntelliJ IDE 插件开发 |&#xff08;四&#xff09;开发一…

MIT线性代数笔记-第31讲-线性变换及对应矩阵

目录 31.线性变换及对应矩阵打赏 31.线性变换及对应矩阵 线性变换相当于是矩阵的抽象表示&#xff0c;每个线性变换都对应着一个矩阵 例&#xff1a; 考虑一个变换 T T T&#xff0c;使得平面上的一个向量投影为平面上的另一个向量&#xff0c;即 T : R 2 → R 2 T:R^2 \to R…

【Spark精讲】一文讲透Spark RDD

MapReduce的缺陷 MR虽然在编程接口的种类和丰富程度上已经比较完善了&#xff0c;但这些系统普遍都缺乏操作分布式内存的接口抽象&#xff0c;导致很多应用在性能上非常低效 。 这些应用的共同特点是需要在多个并行操 作之间重用工作数据集 &#xff0c;典型的场景就是机器学习…

Mybatis行为配置之Ⅰ—缓存

专栏精选 引入Mybatis Mybatis的快速入门 Mybatis的增删改查扩展功能说明 mapper映射的参数和结果 Mybatis复杂类型的结果映射 Mybatis基于注解的结果映射 Mybatis枚举类型处理和类型处理器 再谈动态SQL 文章目录 专栏精选摘要引言正文缓存配置项说明cacheEnabledlocal…

SASS循环

<template><div><button class"btn type-1">默认按钮</button><button class"type-2">主要按钮</button><button class"type-3">成功按钮</button><button class"type-4">信息…

VSCode 如何安装插件的历史版本

背景 在日常开发过程中&#xff0c;我们可能会遇到新版VSCode插件存在问题&#xff0c;无法正常工作的情况。这种情况下&#xff0c;一种可行的解决方案就是安装插件的历史版本。VSCode 插件默认安装的都是插件最新的版本&#xff0c;例如下面 vscode-styled-compoents 插件 本…

C语言之进制转换

C语言之进制转换 一、引言二、十进制与二进制、八进制、十六进制三、二进制与八进制、十六进制四、八进制与十六进制 一、引言 在C语言中&#xff0c;经常使用的整数的进制有十进制、二进制、十六进制&#xff08;在C语言中以0x或0X为前缀&#xff09;、八进制&#xff08;在C…

3D游戏角色建模纹理贴图处理

在线工具推荐&#xff1a; 3D数字孪生场景编辑器 - GLTF/GLB材质纹理编辑器 - 3D模型在线转换 - Three.js AI自动纹理开发包 - YOLO 虚幻合成数据生成器 - 三维模型预览图生成器 - 3D模型语义搜索引擎 在本文中&#xff0c;我们将介绍 3D 纹理的基础知识&#xff0c;并讨…

使用Microsoft托管密钥的Azure信息保护云退出

由于各种原因&#xff0c;一些组织需要一个明确定义的流程来停止使用 Azure 信息保护以及对云服务的任何依赖&#xff0c;而不会在采用之前失去对其数据的访问权限 - 以便在出现需要时做好准备。 Azure 信息保护 (AIP) 为使用自带密钥 (BYOK) 的客户和使用 Microsoft 托管密钥…

uniapp:全局消息是推送,实现app在线更新,WebSocket,apk上传

全局消息是推送&#xff0c;实现app在线更新&#xff0c;WebSocket 1.在main.js中定义全局的WebSocket2.java后端建立和发送WebSocket3.通知所有用户更新 背景&#xff1a; 开发人员开发后app后打包成.apk文件&#xff0c;上传后通知厂区在线用户更新app。 那么没在线的怎么办&…

爬虫工作量由小到大的思维转变---<第三十三章 Scrapy Redis 23年8月5日后会遇到的bug)>

前言: 收到回复评论说,按照我之前文章写的: 爬虫工作量由小到大的思维转变---&#xff1c;第三十一章 Scrapy Redis 初启动/conn说明书)&#xff1e;-CSDN博客 在启动scrapy-redis后,往redis丢入url网址的时候遇到: TypeError: ExecutionEngine.crawl() got an unexpected …

ASM GaN: 行业硅基氮化镓射频和功率设备标准模型—第一部分:直流、CV和射频模型

来源&#xff1a;ASM GaN: Industry Standard Model for GaN RF and Power Devices—Part 1: DC, CV, and RF Model (IEEE TRANSACTIONS ON ELECTRON DEVICES) 19年 摘要 本文介绍了GaN&#xff08;氮化镓&#xff09;HEMT&#xff08;高电子迁移率晶体管&#xff09;的先进S…

边缘检测——PidiNet网络训练自己数据集并优化推理测试(详细图文教程)

PiDiNet 是一种用于边缘检测的算法&#xff0c;它提出了一种简单、轻量级但有效的架构。PiDiNet 采用了新 颖的像素差卷积&#xff0c;将传统的边缘检测算子集成到现代 CNN 中流行的卷积运算中&#xff0c;以增强任务性能。 在 BSDS500、NYUD 和 Multicue 上进行了大量的实验…

第四课:早期的编程方式、编程语言发展史、编程基础-语句和函数、算法入门、数据结构、阿兰图灵及软件工程

第四课&#xff1a;早期的编程方式、编程语言发展史、编程基础-语句和函数、算法入门、数据结构、阿兰图灵及软件工程 第十章&#xff1a;早期的编程方式1、早期&#xff0c;程序如何进入计算机2、早期计算机的编程3、现代计算机基础结构——冯诺依曼计算机 第十一章&#xff1…