本节为您介绍如何使用Connection
对象的方法检查数据库服务器统计信息和驱动连接。
每个示例主要展示如何使用所列方法。点击完整示例查看完整代码示例。
Stats()
获取数据库服务器的统计信息。
参数:
RequestConfig
(可选):配置请求。
Returns:
DatabaseStats
:获取到的服务器统计信息。
var res = await ultipa.Stats();
Console.WriteLine("CPU usage: " + res.CpuUsage);
Console.WriteLine("Memory usage: " + res.MemUsage);
Console.WriteLine("Expiration date: " + res.ExpiredDate);
Console.WriteLine("CPU cores: " + res.CpuCores);
Console.WriteLine("Company: " + res.Company);
Console.WriteLine("Server type: " + res.ServerType);
Console.WriteLine("Version: " + res.Version);
CPU usage: 11.535199
Memory usage: 10702.644531
Expiration date: Thu Dec 26 23:59:59 2024
CPU cores: 80
Company: ultipa
Server type: CT
Version: htap_beta.4.5.7-b4.5.0-tv-ui
Test()
测试驱动和数据库服务器连接。
参数:
RequestConfig
(可选):配置请求。
Returns:
bool
:请求的结果。
var res = ultipa.Test();
Console.WriteLine("Test succeeds: " + res);
Test succeeds: True
完整示例
using System.Security.Cryptography.X509Certificates;
using System.Xml.Linq;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using UltipaService;
using UltipaSharp;
using UltipaSharp.api;
using UltipaSharp.configuration;
using UltipaSharp.connection;
using UltipaSharp.exceptions;
using UltipaSharp.structs;
using UltipaSharp.utils;
using Logger = UltipaSharp.utils.Logger;
using Property = UltipaSharp.structs.Property;
using Schema = UltipaSharp.structs.Schema;
class Program
{
static async Task Main(string[] args)
{
// 设置连接
// URI 示例: Hosts=new[]{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"}
var myconfig = new UltipaConfig()
{
Hosts = new[] { "192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061" },
Username = "***",
Password = "***",
};
// 建立与数据库的连接
var ultipa = new Ultipa(myconfig);
// 配置请求
RequestConfig requestConfig = new RequestConfig() { UseMaster = true };
// 测试连接
var isSuccess = ultipa.Test();
Console.WriteLine("Test succeeds: " + isSuccess);
}
}