zoukankan      html  css  js  c++  java
  • OpenTSDB 简单使用 .NET

    OpenTSDB是基于Hbase的时序数据库[时间序列数据库]。不具备通用性,主要针对具有时间特性和需求的数据,如监控数据、温度变化数据等。

    1、安装OpenTSDB

    安装前一定要安装HBase,相关的安装方式在网上有很多了。 下载地址:https://github.com/OpenTSDB/opentsdb/releases 

    2、设置OpenTSDB

       创建metric:   两种方式,选择其一即可。
    • 在opentsdb中创建metric。如生成 bridge 如下: tsdb mkmetric bridge
    • 修改opentsdb.conf设置: tsd.core.auto_create_metrics = true

    3、C# 数据上传

    Nuget Install-Package RestSharp -Version 106.6.10
       public class DataPoint
        {
            public string metric { get; set; }
            public int timestamp { get; set; }
            public int value { get; set; }
            public Tags tags { get; set; }
        }
    
        public class Tags
        {
            public string host { get; set; }
            public string dc { get; set; }
        }
    基础类
      class Program
        {
            static void Main(string[] args)
            {
                List<DataPoint> point = new List<DataPoint>();
                for(int i = 1; i <= 50; i++)
                {
                    point.Add(new DataPoint()
                    {
                        metric = "bridge",
                        timestamp = ConvertDateTimeInt(DateTime.Now.AddMinutes(i)),
                        value = new Random().Next(1,50),
                        tags = new Tags()
                        {
                            host = "YL-01-01",
                            dc = "BL"
                        }
                    });
                }
    
                var client = new RestClient("IP地址:4242/api/put?summary=");
                var request = new RestRequest(Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("Connection", "keep-alive");
                request.AddHeader("Content-Length", "235");
                request.AddHeader("Accept-Encoding", "gzip, deflate");
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("undefined", JsonConvert.SerializeObject(point), ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                Console.WriteLine(response.Content);
    
                Console.ReadKey();
            }
            public static int ConvertDateTimeInt(System.DateTime time)
            {
                System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                return (int)(time - startTime).TotalSeconds;
            }
        }

    4、OpenTSDB 网页端数据查看


     数据趋势图

  • 相关阅读:
    Java vs Python
    Compiled Language vs Scripting Language
    445. Add Two Numbers II
    213. House Robber II
    198. House Robber
    276. Paint Fence
    77. Combinations
    54. Spiral Matrix
    82. Remove Duplicates from Sorted List II
    80. Remove Duplicates from Sorted Array II
  • 原文地址:https://www.cnblogs.com/w2011/p/11906716.html
Copyright © 2011-2022 走看看