VictoriaMetrics.Client
1.0.4
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
dotnet add package VictoriaMetrics.Client --version 1.0.4
NuGet\Install-Package VictoriaMetrics.Client -Version 1.0.4
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="VictoriaMetrics.Client" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VictoriaMetrics.Client --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: VictoriaMetrics.Client, 1.0.4"
#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 VictoriaMetrics.Client as a Cake Addin #addin nuget:?package=VictoriaMetrics.Client&version=1.0.4 // Install VictoriaMetrics.Client as a Cake Tool #tool nuget:?package=VictoriaMetrics.Client&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
VictoriaMetrics.Client
介绍
VictoriaMetrics c# http SDK
软件架构
VictoriaMetrics download
https://github.com/VictoriaMetrics/VictoriaMetrics/releases
安装教程
https://www.nuget.org/packages/VictoriaMetrics.Client
使用说明
using System.Text.Json;
using System.Text.Json.Nodes;
using VictoriaMetrics.Client;
namespace Test
{
internal class Program
{
static async Task Main(string[] args)
{
//client must be singleton mode(必须是单例模式)
var client = new VictoriaMetricsClient("http://127.0.0.1:8428");
//import metrics
var metrics = new MetricsEntity("m1");
metrics.metric.Add("app", "qms");
for (int i = 0; i < 10; i++)
{
metrics.values.Add(i);
metrics.timestamps.Add(DateTimeOffset.Now.ToUnixTimeMilliseconds());
Thread.Sleep(1);
}
await client.ImportMetricsAsync([metrics]);
//import point data
var pointList = new List<MetricsPointData>();
for (int i = 0; i < 2; i++)
{
var point = new MetricsPointData("m1");
point.Metric.Add("app", "qms");
point.Time = DateTimeOffset.Now;
point.Value = Random.Shared.NextDouble();
pointList.Add(point);
Thread.Sleep(1);
}
await client.ImportPointAsync(pointList);
//import list
var list = new List<People>();
for (int i = 0; i < 10; i++)
{
var p = new People
{
Time = DateTimeOffset.Now,
app = "qms",
v1 = i,
v2 = Random.Shared.Next(1000, 9999)
};
await Task.Delay(1);
list.Add(p);
}
await client.ImportEntityAsync("m1", list);
//import by your self
await client.ImportAsync(async stream =>
{
var writer = new MetricsWriter(stream);
var metrics = new MetricsEntity("m1");
metrics.metric.Add("app", "qms");
metrics.values.Add(1);
metrics.timestamps.Add(DateTimeOffset.Now.ToUnixTimeMilliseconds());
await writer.WriteMetricsAsync(metrics);
await writer.WriteNAsync(); //write an \n
Thread.Sleep(1);
var point = new MetricsPointData("m1");
point.Metric.Add("app", "qms");
point.Time = DateTimeOffset.Now;
point.Value = Random.Shared.NextDouble();
pointList.Add(point);
await writer.WritePointAsync(point);
await writer.WriteNAsync(); //write an \n
Thread.Sleep(1);
var p = new People
{
Time = DateTimeOffset.Now,
app = "qms",
v1 = 12,
v2 = Random.Shared.Next(1000, 9999)
};
await writer.WriteEntityAsync("m1", p);
});
//export jsonline
var jsonlineData = client.ExportJsonline(null, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now, true);
await foreach (var item in jsonlineData)
{
Console.WriteLine(item);
}
Console.WriteLine("=========================");
//export metrics
var metricsData = client.ExportMetrics(null, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now, true);
await foreach (var item in metricsData)
{
Console.WriteLine($"{item.metric["__name__"]}==>{item.metric["app"]}==>{item.timestamps.Count}==>{item.values.Count}");
}
Console.WriteLine("=========================");
//export point
var pointData = client.ExportPoint(null, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now, true);
await foreach (var item in pointData)
{
Console.WriteLine($"{item.MetricName}==>{item.Metric["app"]}==>{item.Time}==>{item.Value}");
}
Console.WriteLine("=========================");
//export list
var listData = await client.ExportListAsync<People>(null, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now);
Console.WriteLine(JsonSerializer.Serialize(listData));
Console.WriteLine("=========================");
var query1 = """
m1{app="qms"}
""";
//query stream
using var stream = await client.QueryStreamAsync(query1, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now);
using var sr = new StreamReader(stream);
Console.WriteLine(sr.ReadToEnd());
Console.WriteLine("=========================");
//query range
var data1 = await client.QueryAsync<JsonObject>(query1, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now);
Console.WriteLine(JsonSerializer.Serialize(data1));
Console.WriteLine("=========================");
//query result
var data2 = await client.QueryResultAsync(query1, DateTimeOffset.Now.AddMinutes(-30), DateTimeOffset.Now);
Console.WriteLine(JsonSerializer.Serialize(data2));
//queue
var queue = new VictoriaMetricsQueue(client);
_ = Task.Run(async () =>
{
while (true)
{
//metrics
var metrics = new MetricsEntity("m1");
metrics.metric.Add("app", "qms");
metrics.values.Add(Random.Shared.Next(1, 1000));
metrics.timestamps.Add(DateTimeOffset.Now.ToUnixTimeMilliseconds());
queue.Add(metrics);
await Task.Delay(1);
//point
var point = new MetricsPointData("m1");
point.Metric.Add("app", "qms");
point.Value = Random.Shared.Next(1, 1000);
point.Time = DateTimeOffset.Now;
queue.Add(point);
await Task.Delay(1);
//entity
var p = new People
{
Time = DateTimeOffset.Now,
app = "qms",
v1 = Random.Shared.Next(1, 1000),
v2 = Random.Shared.Next(1000, 9999)
};
queue.Add(p, "m1");
await Task.Delay(10);
}
});
Console.WriteLine("Hello, World!");
Console.ReadKey();
}
}
}
public class People
{
public DateTimeOffset? Time { get; set; }
[MetricsTag]
public string app { get; set; }
public double v1 { get; set; }
public double v2 { get; set; }
}
Product | Versions 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.4 | 99 | 12/1/2024 |