VictoriaLogs.Client 1.0.7

dotnet add package VictoriaLogs.Client --version 1.0.7                
NuGet\Install-Package VictoriaLogs.Client -Version 1.0.7                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VictoriaLogs.Client" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VictoriaLogs.Client --version 1.0.7                
#r "nuget: VictoriaLogs.Client, 1.0.7"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install VictoriaLogs.Client as a Cake Addin
#addin nuget:?package=VictoriaLogs.Client&version=1.0.7

// Install VictoriaLogs.Client as a Cake Tool
#tool nuget:?package=VictoriaLogs.Client&version=1.0.7                

VictoriaLogs.Client

介绍

VictoriaLogs c# http SDK

软件架构

VictoriaLogs download
https://github.com/VictoriaMetrics/VictoriaMetrics/releases

VictoriaLogs doc
https://docs.victoriametrics.com/victorialogs

安装教程

https://www.nuget.org/packages/VictoriaLogs.Client

使用说明
using OkFlurl;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using VictoriaLogs.Client;

namespace Test
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            //https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
            //https://docs.victoriametrics.com/victorialogs/querying/

            //client must be singleton mode(必须是单例模式)
            var client = new VictoriaLogsClient("http://127.0.0.1:9428");

            //insert list
            var list = new List<object>();
            for (int i = 0; i < 10; i++)
            {
                var item = new
                {
                    _time = DateTime.Now,
                    _msg = "hello" + i,
                    app = "qms",
                    level = "info",
                    money = i
                };

                list.Add(item);

                Thread.Sleep(1);
            }
            await client.InsertListAsync(list, ["app"]);

            //insert by your self
            await client.InsertAsync(async stream =>
            {
                var model = new
                {
                    app = "qms",
                    _msg = "object model",
                    _time = DateTime.Now
                };
                await JsonSerializer.SerializeAsync(stream, model, VictoriaLogsClient.JsonOptionsMs);

                await stream.WriteAsync(VictoriaLogsClient.N); //write an \n

                var jsonText = """
                {"app":"qms","_msg":"json line"}
                """;
                await stream.WriteAsync(Encoding.UTF8.GetBytes(jsonText));

            }, ["app"]);


            //query
            //var query = "*"; //query all
            var query = """
                {app="qms"} | order by (_time desc) | limit 2
                """;
            var unbuffer = client.QueryAsync(query);
            await foreach (var item in unbuffer)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("===================");

            //query streams
            var streamsData = await client.QueryOtherAsync<JsonObject>(QueryType.Streams, "*");
            Console.WriteLine(JsonSerializer.Serialize(streamsData, FlurlExt.JsonOptions));

            //queue
            var queue = new VictoriaLogsQueue(client);

            queue.OnError += (errList) =>
            {
                Console.WriteLine($"error:{errList.Count}");
            };

            _ = Task.Run(async () =>
            {
                while (true)
                {
                    var obj = new People()
                    {
                        _time = DateTime.Now,
                        _msg = "哈哈哈" + DateTime.Now.Second,
                        app = "wms",
                        host = "127.0.0.1",
                        Name = "李四",
                        Remark = JsonSerializer.Serialize(new { id = 1, name = "厦门", money = 11.2 }, VictoriaLogsClient.JsonOptionsMs)
                    };

                    queue.Add(obj, ["app"]);
                    queue.Add(obj, ["app", "host"]);
                    queue.Add(obj, ["host", "app"]);

                    var obj2 = new
                    {
                        _time = DateTime.Now,
                        _msg = "哈哈哈" + DateTime.Now.Second,
                        pod = "nasa"
                    };

                    queue.Add(obj2, ["pod"]);

                    await Task.Delay(500);
                }

            });

            Console.WriteLine("Hello, World!");
            Console.ReadKey();
        }
    }
}

https://docs.victoriametrics.com/victorialogs/logsql

==========================================================

{app="wms"} | _time:(2024-11-03Z, 2024-11-05Z) | sort by (_time desc) | money:<2 or money:=100 | limit 50


范围
money:range(4.2, 4.8)

-------------------------------

精确匹配
name:="abc"

-------------------------------

短语过滤器,包含(性能好)
name:"abc"

----------------------------------

in多重精确过滤 
name:in(="a",="f")
name:(="a" OR ="f")
----------------------------------

不区分大小写
name:i("AbcD")

------------------------------------

前缀
name:err*
name:="err"*
name:="Processing request"*

---------------------------------------

包含(性能不好)
name:~"ampl"

字符串范围
name:string_range(A, C)

字符串长度

len_range(5, 10)
len_range(5, 10]

========================================

VictoriaLogs 默认返回所有日志字段。如果您只需要给定的一组字段,则在查询末尾 添加fields管道_time。例如,以下查询仅返回、_stream 和_msg字段:

error _time:5m | fields _time, _stream, _msg


==============================================

管道
_time:5m | stats count() logs
_time:5m | stats min(duration) min_duration
_time:5m | stats max(duration) max_duration
_time:5m | stats avg(duration) avg_duration
_time:5m | stats sum(duration) sum_duration

_time:1h error | stats by (host) count() logs_count | filter logs_count:> 1_000
_time:1h error | stats by (host) count() logs_count | where logs_count:> 1_000
_time:1h error | stats by (host) count() logs_count | logs_count:> 1_000


error                       # find logs with `error` word
  | stats by (_stream) logs # then count the number of logs per `_stream` label
  | sort by (logs) desc     # then sort by the found logs in descending order
  | limit 5                 # and show top 5 streams with the biggest number of logs
  
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.7 92 12/1/2024