OpenTSDB simple to use .NET

OpenTSDB Hbase timing based database [time-series database]. It does not have versatility, for the data having the main characteristics and time requirements, such as the monitoring data, temperature data and the like.

1, the installation OpenTSDB

Before installation be sure to install HBase, related to the installation of the Internet there are many. Download: https://github.com/OpenTSDB/opentsdb/releases 

2, set OpenTSDB

   Create a metric: two ways, you can choose one.
  • Create a metric in opentsdb in. The bridge generated as follows: tsdb mkmetric bridge
  • Opentsdb.conf modify settings: tsd.core.auto_create_metrics = true

3, C # data upload

Nuggets  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; }
    }
Foundation Classes
  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 View web client


 Data trends

Guess you like

Origin www.cnblogs.com/w2011/p/11906716.html