InfluxDB时序数据库安装与使用

1. 下载解压文件

 2.启动服务,双击运行influxd.exe

3.安装客户端工具(InfluxDBStudio)

 4.新建数据库

5. NuGet -> InfluxData.Net

using InfluxData.Net.InfluxDb.Models;
using System;
using System.Collections.Generic;

namespace InfluxDBTest
{
    class Program
    { 
        static void Main(string[] args)
        {
            string table = "logInfo";
            var point_model1 = new Point()
            {
                Name = table,//表名 
                Tags = new Dictionary<string, object>() { { "Id", "5810953" } }, // 索引
                Fields = new Dictionary<string, object>() { { "Val", 102 } },// 字段
                Timestamp = DateTime.UtcNow
            };

            var point_model2 = new Point()
            {
                Name = table,//表名
                Tags = new Dictionary<string, object>() { { "Id1", "5810951" }, { "Id2", "5810952" } },
                Fields = new Dictionary<string, object>() { { "Val1", 101 }, { "Val2", 102 } },
                Timestamp = DateTime.UtcNow
            };

            var queries = new[] 
            {
                " SELECT time,Id,Val FROM " + table+ " WHERE time> now() -  24h "
            };

            InfluxDbHelper.Init();

            InfluxDbHelper.Write(point_model1);
            InfluxDbHelper.Write(point_model2);

            //InfluxDbHelper.Read(queries).Wait();// 异步转同步
            IList<IList<object>> result = InfluxDbHelper.Read(queries).GetAwaiter().GetResult();
            for (int i = 0; i <result.Count; i++)
            {
                var lstTemp = result[i];
                Console.WriteLine("time:" + lstTemp[0] + ",id:" + lstTemp[1] + ",val:" + lstTemp[2]);

                //for (int j = 0; j < lstTemp.Count; j++)
                //{
                //    object content = lstTemp[j];
                //    Console.WriteLine(content);
                //}
            }

            Console.ReadKey();
        }
    } 
}

qq:505645074
原文地址:https://www.cnblogs.com/chen1880/p/14804969.html