(001)window 使用 OpenObserve

安装

1.下载 openobserve

在这里插入图片描述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.http://localhost:5080/
在这里插入图片描述

报错

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

注意

1.每次重新启动的时候,密码可能改变,注意一下,不然数据可能上传一直超时!!!

附录

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

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在PL/SQL中,Command Window是一个命令行窗口,可以用来执行一些简单的命令和操作。使用Command Window可以方便地进行一些调试和测试工作。 要打开Command Window,可以在PL/SQL Developer的工具栏上选择“视图”菜单,然后选择“Command Window”选项。或者可以使用快捷键“Ctrl+Shift+C”。 在Command Window中,可以输入一些简单的命令,比如“show errors”可以显示当前会话中的错误信息,“set serveroutput on”可以打开服务器输出,等等。还可以使用SQL*Plus命令来执行SQL语句和PL/SQL代码。 需要注意的是,Command Window并不是一个完整的命令行工具,它只能执行一些简单的命令和操作。如果需要进行更复杂的操作,建议使用SQL*Plus或其他命令行工具。 ### 回答2: PL/SQL是Oracle数据库的一种面向对象的程序设计语言,用来编写存储过程、触发器等数据库对象。其中,Command Window是PL/SQL Developer中一个非常重要的功能,它允许用户在该窗口中运行PL/SQL语句。在这个窗口中,用户可以执行一个或多个PL/SQL语句,从而了解他们的行为方式。以下是关于PL/SQL中Command Window使用的详细介绍: 一、Command Window的打开 打开窗口的方法是单击PL/SQL Developer的主菜单中的工具->命令窗口或使用快捷键Ctrl+W。打开窗口后,用户可以在其中运行各种PL/SQL命令和语句。 二、运行命令和语句 1. 使用SQL*Plus命令:SQL*Plus是一种Oracle数据库的命令行界面工具,它可以与Oracle数据库进行交互。在Command Window中,用户可以使用各种SQL*Plus命令,包含在“/”符号后。 例如,用户可以执行如下命令,查看当前连接的用户: SELECT USER FROM DUAL; / 2. 运行PL/SQL块:用户可以在Command Window中创建和运行PL/SQL块。以下是一个PL/SQL块示例: DECLARE v_name VARCHAR2(100); BEGIN SELECT first_name INTO v_name FROM employees WHERE employee_id = 100; DBMS_OUTPUT.PUT_LINE('Name: ' || v_name); END; / 三、在命令行窗口中使用列表 默认情况下,Command Window的输出会在消息窗口中显示。但是,用户还可以使用“LIST”命令打开列表窗口,该窗口类似于数据表格。 例如,用户可以执行以下命令,将所有员工的相关信息显示在列表窗口中: SET SERVEROUTPUT ON SET LINESIZE 200 SET PAGESIZE 100 LIST SELECT * FROM employees; 四、设置命令行窗口参数 用户可以在Command Window中设置各种参数,以自定义其行为。例如,可以设置文本颜色、背景颜色、字体大小、行距等。 用户可以通过单击主菜单中的“Tools->Preferences”打开首选项窗口,然后单击“Command Window”选项卡,以修改各种命令行窗口参数。 总之,在PL/SQL中,Command Window是一个强大的工具,它允许用户在该窗口中交互式地编写和运行SQL和PL/SQL命令,并查看其输出结果。通过此窗口,用户可以更轻松、更有效地管理其数据库。 ### 回答3: PL/SQL 中的 Command Window 是一个命令行窗口,它可以让开发人员在编写 PL/SQL 代码时执行测试操作,如执行函数、存储过程、游标等,以及查询数据等功能。Command Window 主要是为了方便开发人员进行调试与测试,提高 PL/SQL 应用程序的稳定性和性能。 在 PL/SQL 中打开 Command Window 的方法是通过 SQL Developer 工具,打开 PL/SQL 代码编辑器,在编辑器界面的菜单栏中选择“视图”(View)->“Command Window”,或者从快捷键 F11 打开。 在 Command Window 中,可以执行 SQL 语句、PL/SQL 代码和系统命令等操作,也可以直接查询数据库中的表和视图。例如,输入“select * from tablename”即可在 Command Window 中查看表中的数据。此外,用户还可以使用一些特定的命令进行操作,如“help”命令可以查看 Command Window 的帮助信息,“clear”命令可以清空 Command Window 窗口等。 在使用 Command Window 进行测试时,还需要使用 DBMS_OUTPUT 包来输出调试信息和结果信息。在 PL/SQL 中,可以通过在 Command Window使用“set serveroutput on”命令开启 DBMS_OUTPUT 的输出功能,然后在代码中使用“dbms_output.put_line()”命令输出信息,并在 Command Window 中查看输出结果。 总的来说,Command Window 是 PL/SQL 开发的重要工具之一,可以方便开发人员进行测试和调试,提高应用程序的质量和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值