(001)window 使用 OpenObserve

文章目录

  • 安装
  • 上传数据
  • 报错
  • 附录

安装

1.下载安装包:
在这里插入图片描述2. window 设置环境变量:

ZO_ETCD_COMMAND_TIMEOUT = 600 
ZO_ETCD_CONNECT_TIMEOUT = 600
ZO_ETCD_LOCK_WAIT_TIMEOUT = 600
ZO_INGEST_ALLOWED_UPTO = 10000
ZO_ROOT_USER_EMAIL = 422615924@qq.com
ZO_ROOT_USER_PASSWORD = 8R4VMmC1Su975e026Ln3
  1. 直接运行 openobserve.exe 启动程序:

在这里插入图片描述

上传数据

1.Gradle 需要的安装包:

 		// https://mvnrepository.com/artifact/cn.hutool/hutool-all
    implementation group: 'cn.hutool', name: 'hutool-all', version: '5.8.23'
    // https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2
    implementation group: 'com.alibaba.fastjson2', name: 'fastjson2', version: '2.0.45'

    implementation group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.25'
    implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
    implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
    implementation group: 'ch.qos.logback', name: 'logback-access', version: '1.2.3'

    // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
    implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '5.0.0-alpha.12'
    implementation group: 'com.alibaba', name: 'druid', version: '1.1.9'

2.数据目录和内容格式:
在这里插入图片描述

在这里插入图片描述
3.上传代码:

package org.example;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * 008
 */
public class UploadOpenObserve {
    private static final Logger logger = LoggerFactory.getLogger(UploadOpenObserve.class);
    private static String targetDirectory = "D:\\S3log\\unzip12\\";

    private static ConcurrentHashMap<String, String> failFile = new ConcurrentHashMap<>();
    private static String mail = "422615924@qq.com";
    private static String password = "4MHyN8BGMaCRyEen";
    private static String credential = Credentials.basic("422615924@qq.com", "4MHyN8BGMaCRyEen");

    private static volatile OkHttpClient okHttpClient;
    private static String buyStreamName = "buy105";
    private static String payStreamName = "pay105";

    public static void main(String[] args) {
        uploadBuyAndPay();
    }

    private static void upload_jpy20231216(){
        List<File> directories = listDirectory(targetDirectory);

        for (int i = 0; i < directories.size(); i++) {
            File file = directories.get(i);
            if (file.getName().startsWith("20231215_") || file.getName().startsWith("20231216_")){
                logger.debug(file.getName());
                uploadDirectory_jpy("jpy20231216_002", file);
            }
        }
    }

    private static void uploadBuyAndPay(){
        List<File> directories = listDirectory(targetDirectory);
        ExecutorService executorService = Executors.newFixedThreadPool(Math.max(2, Runtime.getRuntime().availableProcessors() / 2));
        CountDownLatch countDownLatch = new CountDownLatch(directories.size());
        for (int i = 0; i < directories.size(); i++) {
            final File file = directories.get(i);
            final int j = i;
            executorService.submit(() -> {
                try {
                    uploadDirectory(file);
                }finally {
                    countDownLatch.countDown();
                    logger.debug("目录传输完成: {}, {}/{}", file.getName(), j, directories.size());
                }
            });
        }
        try {
            countDownLatch.await();
        } catch (Exception e) {
            logger.error("", e);
        } finally {
            executorService.shutdown();
        }
        logger.debug("任务执行完成.");
    }

    private static List<File> listDirectory(String targetDirectory) {
        File[] files = FileUtil.ls(targetDirectory);

        List<File> arrFiles = new ArrayList<>();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                arrFiles.add(files[i]);
            }
        }
        return arrFiles;
    }

    private static void checkDirectoryFile(File directory) {
        if (!directory.isDirectory()) {
            logger.error("not a directory {}", directory.getName());
            return;
        }

        File[] files = FileUtil.ls(directory.getPath());
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getName();
            if (!name.startsWith("2023") && !name.startsWith("JPY")) {
                logger.error("error file {}", name);
            }
        }
    }

    private static void uploadDirectory_jpy(String streamName, File directory) {
        if (!directory.isDirectory()) {
            logger.error("not a directory {}", directory.getName());
            return;
        }
        File[] files = FileUtil.ls(directory.getPath());
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getName();
            if (!name.startsWith("JPY")) {
                continue;
            }
            uploadFile(directory, streamName, files[i]);
        }
    }

    private static void uploadDirectory(File directory) {
        if (!directory.isDirectory()) {
            logger.error("not a directory {}", directory.getName());
            return;
        }
//        if (FileUtil.exist(StrUtil.format("{}/upload", directory.getPath()))) {
//            logger.debug("has upload {}", directory.getPath());
//            return;
//        }
        File[] files = FileUtil.ls(directory.getPath());
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getName();
            if (name.startsWith("JPY")) {
                continue;
            }
            if (name.endsWith("Buy.log")) {
                uploadFile(directory, buyStreamName, files[i]);
            } else if (name.endsWith("Pay.log")) {
                uploadFile(directory, payStreamName, files[i]);
            }
        }
    }

    public static OkHttpClient getOkHttpInstance(){
        if (null == okHttpClient){
            synchronized (UploadOpenObserve.class){
                if (okHttpClient == null){
                    okHttpClient = new OkHttpClient.Builder()
                            .callTimeout(7200, TimeUnit.SECONDS)
                            .connectTimeout(3600, TimeUnit.SECONDS)
                            .readTimeout(3600, TimeUnit.SECONDS)
                            .writeTimeout(3600, TimeUnit.SECONDS)
                            .connectionPool(new ConnectionPool(32, 5, TimeUnit.MINUTES))
                            .build();
                    return okHttpClient;
                }
            }
        }
        return okHttpClient;
    }

    private static void uploadFile(File directory, String streamName, File file) {
        String url = StrUtil.format("http://localhost:5080/api/default/{}/_json", streamName);

        List<String> lines = FileUtil.readLines(file, StandardCharsets.UTF_8);
        lines.removeIf(item -> !item.startsWith("{"));
        if (lines.isEmpty()) {
            return;
        }
        List<JSONObject> jsonObjects = new ArrayList<>();
        lines.forEach(item -> {
            try {
                JSONObject jsonObject = JSONObject.parseObject(item);
                if (jsonObject.containsKey("JSTDate")){
                    String value = jsonObject.getString("JSTDate");
                    jsonObject.put("jst_time", value.substring(0, 8));
                    jsonObject.put("jst_dateday", value.substring(0, 6));
                    jsonObject.put("jst_day", value.substring(6, 8));
                }
                jsonObjects.add(jsonObject);
            } catch (Exception e){
                logger.error("", e);
            }
        });
        if (jsonObjects.isEmpty())
            return;

        RequestBody requestBody = RequestBody.create(JSON.toJSONString(jsonObjects),  MediaType.parse("application/x-www-form-urlencoded"));
        Request request = new Request.Builder()
                .addHeader("Authorization", credential)
                .url(url)
                .post(requestBody)
                .build();
        boolean success = false;
        try (Response response = getOkHttpInstance().newCall(request).execute()) {
            success = response.isSuccessful();
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug("upload fail {}, reason {}", file.getName(), e.getMessage());
        } finally {
            if (success){
                FileUtil.touch(StrUtil.format("{}/upload", directory.getPath()));
                //                String res = response.body().string();
                //            logger.debug("upload success {}, {}", file.getName(), JSON.toJSONString(res));
            } else {
                failFile.put(file.getName(), "true");
            }
        }
    }

    /**
     * curl -u 422615924@qq.com:8R4VMmC1Su975e026Ln3 -k https://api.openobserve.ai/api/peilin_organization_3737_H87YxMBFXYifSaV/default/_json
     * -d '[{"level":"info","job":"test","log":"test message for openobserve","_timestamp": 1704958559370}]'
     */
    private static void testUploadJson() {
        String url = "https://api.openobserve.ai/api/peilin_organization_3737_H87YxMBFXYifSaV/test1/_json";
        HttpRequest request = HttpUtil.createPost(url);
        request.basicAuth("422615924@qq.com", "8R4VMmC1Su975e026Ln3");
        request.body("[{\"level\":\"inf\",\"jo\":43212,\"log\":\"test message for openobserve\"}]", "application/json");
        HttpResponse response = request.execute();
        logger.info("{}", JSON.toJSON(response.body()));
    }
}

报错

一、 发送的数据格式错误:
在这里插入图片描述
二、 数据的太旧了:
在这里插入图片描述

附录

[1] Github openobserve/openobserve
[2] 官网手册 openobserve

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Linux网络--- SSH服务

一、ssh服务简介 1、什么是ssh SSH&#xff08;Secure Shell&#xff09;是一种安全通道协议&#xff0c;主要用来实现字符界面的远程登录、远程复制等功能。SSH 协议对通信双方的数据传输进行了加密处理&#xff0c;其中包括用户登录时输入的用户口令&#xff0c;SSH 为建立在…

Spring使用注解管理Bean

引入lib包 Spring对Bean管理的常用注解 Component组件(作用在类上) Spring中提供了Component的三个衍生注解:(功能在目前为止是一致的) Controller WEB层 Service 业务层 Repository 持久层 属性注入的注解:(使用注解注入的方式,可以不用提供set方法) Value 用于注入普…

powershell的help

打开win10 的powershell窗口&#xff0c;输入help命令&#xff0c;可以得到如下说明&#xff1a; 有了help系统&#xff0c;可以方便地了解关于powershell的详细说明。

Java异常处理--异常处理的方式2:throws

文章目录 一、方式2&#xff1a;声明抛出异常类型&#xff08;throws&#xff09;二、throws基本格式三、 throws 使用举例&#xff08;1&#xff09;针对于编译时异常1、案例12、案例2 &#xff08;2&#xff09;针对于运行时异常 四、 方法重写中throws的要求&#xff08;1&a…

当代大学生是怎么被废掉的?

中式教育以应试为核心&#xff0c;强调知识的灌输和学生被动接受。随着社会的发展&#xff0c;中式教育的短板逐渐显现&#xff0c;创新能力的缺乏、对记忆的过度依赖、忽视个体差异等问题日益突出。 建议所有大学生都能去看看《上海交通大学生存手册》&#xff0c;它道出了中…

AbstractHttpMessageConverter + easyexcell优雅下载附件

介绍 AbstractHttpMessageConverter 是 Spring 框架中用于处理 HTTP 消息转换的抽象基类。它用于处理来自 HTTP 请求的消息,并将其转换为特定的 Java 对象,或者将 Java 对象转换为 HTTP 响应消息。 这个抽象类允许开发人员创建自定义的 HTTP 消息转换器,以便在 Spring MVC…

如何提高发电机组带载能力

发电机组的带载能力是指其在一定时间内能够稳定运行的最大负载。提高发电机组的带载能力&#xff0c;不仅可以提高其工作效率&#xff0c;还可以延长其使用寿命。 优化发电机组的设计&#xff1a;通过改进发电机组的设计&#xff0c;可以提高其带载能力。例如&#xff0c;可以采…

MongoDB面试系列-01

1. MongoDB 是什么&#xff1f; MongoDB是由C语言编写的&#xff0c;是一个基于分布式文件存储的开源数据库系统。再高负载的情况下&#xff0c;添加更多的节点&#xff0c;可以保证服务器性能。MongoDB旨在给Web应用提供可扩展的高性能数据存储解决方案。 MongoDB将数据存储…

手把手教你学会接口自动化系列十五-如何用python操作excel的单元格自动化测试之前的准备工作

接上篇,我们都知道可以读取到sheet页了,下来就是读取sheet页下面的单元格数据 我们实践起来吧。 第一种方式是通过坐标的方式,比如我要取下面这个单元格的数据,如下: 这个数据位于Excel的B列第8行,所以对于excel来说就是坐标为B8。 代码如下: # !/usr/bin/env pytho…

LLM:Scaling Laws for Neural Language Models (中)

核心结论 1&#xff1a;LLM模型的性能主要与计算量C&#xff0c;模型参数量N和数据大小D三者相关&#xff0c;而与模型的具体结构 (层数/深度/宽度) 基本无关。三者满足: C ≈ 6ND 2. 为了提升模型性能&#xff0c;模型参数量N和数据大小D需要同步放大&#xff0c;但模型和数…

【生态适配】亚信安慧AntDB数据库与契约锁完成兼容互认

日前&#xff0c;亚信安慧AntDB数据库与上海亘岩网络科技有限公司&#xff08;简称:契约锁&#xff09;研发的契约锁电子签章产品完成兼容互认。经过双方团队的严格测试&#xff0c;亚信安慧AntDB数据库与契约锁&#xff08;V4&#xff09;完全兼容&#xff0c;整体运行稳定高效…

一天吃透Spring面试八股文

目录&#xff1a; Spring的优点Spring 用到了哪些设计模式&#xff1f;什么是AOP&#xff1f;AOP有哪些实现方式&#xff1f;Spring AOP的实现原理JDK动态代理和CGLIB动态代理的区别&#xff1f;Spring AOP相关术语Spring通知有哪些类型&#xff1f;什么是IOC&#xff1f;IOC的…

L1-027 出租(Java)

下面是新浪微博上曾经很火的一张图&#xff1a; 一时间网上一片求救声&#xff0c;急问这个怎么破。其实这段代码很简单&#xff0c;index数组就是arr数组的下标&#xff0c;index[0]2 对应 arr[2]1&#xff0c;index[1]0 对应 arr[0]8&#xff0c;index[2]3 对应 arr[3]0&…

鸿蒙开发之手势Pan

Entry Component struct OfficialPanGesturePage {State message: string 默认只左右移动State offsetX: number 0State offsetY: number 0State positionX: number 0State positionY: number 0//默认pan的参数&#xff0c;1根手指&#xff0c;左右方向private panOption:…

什么是泛域名证书?有免费的吗?

泛域名证书&#xff08;Wildcard SSL Certificate&#xff09;是一种用于加密多个子域名的SSL证书。与传统的SSL证书只能覆盖单个域名或特定子域不同&#xff0c;泛域名证书具有更广泛的适用性&#xff0c;可以涵盖一个域名下的所有子域。 泛域名证书的主要特点是通配符&#x…

华为数通方向HCIP-DataCom H12-831题库(判断题:1-20)

第01题 为了加快IS-IS网络中链路故障的感知速度,可以将IS-IS与BFD联动 正确 错误 答案:正确 解析: OSPF和IS-IS都可以设置与BFD联动加速链路故障检测 ,使用BFD时,可以实现毫秒级别的链路切换,所以使用IS–IS与BFD联动,可以加快IS–IS的感知速度 第02题 在OSPF中ABR会将…

关于整型提升与截断的一道题目

关于整型提升与截断&#xff0c;可以看我的博客 C语言&#xff1a;整型提升_c语言整形提升-CSDN博客 C语言&#xff1a;截断整型提升算数转换练习_c语言unsigned-CSDN博客 一、题目 二、题解 char a101截断 由于101是整型数据&#xff0c;需要32比特位存储空间&#xff0c;…

1.12号网络

1 网络发展历史 1.1 APRAnet阶段 阿帕网&#xff0c;是Interne的最早雏形 不能互联不同类型的计算机和不同类型的操作系统 没有纠错功能 1.2 TCP/IP两个协议阶段 什么是协议 在计算机网络中&#xff0c;要做到有条不紊的交换数据&#xff0c;需要遵循一些事先约定好的规则…

Java多线程并发篇----第十六篇

系列文章目录 文章目录 系列文章目录前言一、线程等待(wait)二、线程睡眠(sleep)三、线程让步(yield)四、线程中断(interrupt)五、Join 等待其他线程终止前言 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站,这…

【java八股文】之JVM基础篇

【java八股文】之JVM基础篇-CSDN博客 【java八股文】之MYSQL基础篇-CSDN博客 【java八股文】之Redis基础篇-CSDN博客 【java八股文】之Spring系列篇-CSDN博客 【java八股文】之分布式系列篇-CSDN博客 【java八股文】之多线程篇-CSDN博客 【java八股文】之JVM基础篇-CSDN博…
最新文章