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 網頁端數據查看
數據趨勢圖