Vector 日志采集与处理

简介 Vector 是一个高性能日志与指标采集代理,它从各种 source 收集数据,经过 transform 处理后发送到 sink(如 Loki、ClickHouse、Kafka、Elasticsearch 等) 它的特点是高吞吐、低延迟、无需依赖 JVM、轻量好部署,非常适合边缘节点和容器环境 本文主要讲述 Events 和 Compnents 1. 配置结构概览 Vector 有两种数据模型 (Data Model), 又称事件(Events): Logs: 用于表示结构化或非结构化日志数据 metrics: 用于表示指标数据 Vector 的配置由三个核心部分 (Compnets) 组成: sources:数据采集源 transforms:数据处理与解析 sinks:输出目标 2. Data model(events) Log events Here’s an example representation of a log event (as JSON): { "log": { "custom": "field", "host": "my.host.com", "message": "Hello world", "timestamp": "2020-11-01T21:15:47+00:00" } } Metric event 此处留给以后撰写 3. Compnents 3.1 source 详细配置请见 👉 Sources reference ...

August 20, 2024 · 2 min · 232 words · Guangyang Zhong

ClickHouse 高性能数据库

ClickHouse 高性能数据库 ClickHouse 是一款 开源、高性能的列式数据库,主要用于 大规模数据分析 (OLAP) 和 实时查询。它的特点是: 列式存储,读取指定列非常快 支持高并发写入和查询 强大的聚合功能,适合报表和日志分析 支持 SQL 查询,易上手 1️. 安装与快速开始 可以参考官方文档或社区教程 👉ClickHouse 官方文档 1.1 安装 curl https://clickhouse.com/ | sh sudo ./clickhouse install 1.2 运行 $ clickhouse-client --host server ClickHouse client version 24.12.2.29 (official build). Connecting to server:9000 as user default. Connected to ClickHouse server version 24.12.2. :) Specify additional connection details as necessary: Option Description --port <port> The port ClickHouse server is accepting connections on. The default ports are 9440 (TLS) and 9000 (no TLS). Note that ClickHouse Client uses the native protocol and not HTTP(S). -s [--secure] Whether to use TLS (usually autodetected). -u [--user] <username> The database user to connect as. Connects as the default user by default. --password <password> The password of the database user. You can also specify the password for a connection in the configuration file. If you do not specify the password, the client will ask for it. -c [--config] <path-to-file> The location of the configuration file for ClickHouse Client, if it is not at one of the default locations. See Configuration Files. 1.3 退出 To exit the client, press Ctrl+D, or enter one of the following instead of a query: ...

August 18, 2024 · 2 min · 270 words · Guangyang Zhong

QR Scanner 使用指南

简介 qr-scanner 是一款纯前端、零依赖的 JavaScript 二维码扫描库,完全在浏览器端运行,无需后端配合。它同时支持: 摄像头实时扫码 静态图片/文件离线扫码(支持 <img>、<canvas>、<video>、File、Blob 等多种来源) 底层使用 WebAssembly 加速解码,识别速度快、准确率高,在手机端表现尤为优秀,是目前最推荐的前端二维码扫描方案 本文以 React + Next.js 框架为例 1. 安装 npm install qr-scanner 或使用 yarn: yarn add qr-scanner 注意:已不再推荐直接用 <script> 标签引入,现代项目请通过包管理器安装 2. 基本引入方式 import QrScanner from 'qr-scanner'; 3. 核心类:QrScanner 3.1 摄像头实时扫码 const videoElement = document.getElementById('video') as HTMLVideoElement; const scanner = new QrScanner( videoElement, (result) => { console.log('扫码成功:', result.data); // result.cornerPoints 可用来做边框动画 }, { returnDetailedScanResult: true, // 返回完整对象而非仅字符串 highlightScanRegion: true, // 显示扫描区域遮罩 highlightCodeOutline: true, // 高亮二维码轮廓 } ); // 启动摄像头 await scanner.start(); // 停止扫描 scanner.stop(); 常用配置项 参数 说明 returnDetailedScanResult true 时返回 { data, cornerPoints } 对象 highlightScanRegion 显示半透明扫描区域框 highlightCodeOutline 实时绘制二维码四角轮廓 3.2 离线扫描图片文件 const file: File = 文件输入框.files[0]; const result = await QrScanner.scanImage(file, { returnDetailedScanResult: true }); console.log('二维码内容:', result.data); 支持所有图片源:File、Blob、HTMLImageElement、HTMLCanvasElement、URL 等 ...

August 16, 2024 · 2 min · 263 words · Guangyang Zhong