public List <PoolSizeHistory> GetPoolSizeHistory(string chainId) { var result = new List <PoolSizeHistory>(); var record = InfluxDBHelper.Get(chainId, "select * from transaction_pool_size"); foreach (var item in record.First().Values) { result.Add(new PoolSizeHistory { Time = Convert.ToDateTime(item[0]), Size = Convert.ToUInt64(item[1]) }); } return(result); }
public List <PoolStateHistory> GetPoolStateHistory(string chainId) { var result = new List <PoolStateHistory>(); var record = InfluxDBHelper.Get(chainId, "select * from network_pool_state"); foreach (var item in record.First().Values) { result.Add(new PoolStateHistory { Time = Convert.ToDateTime(item[0]), ReceivePoolSize = Convert.ToInt32(item[1]), RequestPoolSize = Convert.ToInt32(item[2]) }); } return(result); }
public async Task <List <NodeStateHistory> > GetHistoryState(string chainId) { var result = new List <NodeStateHistory>(); var record = InfluxDBHelper.Get(chainId, "select * from node_state"); foreach (var item in record.First().Values) { result.Add(new NodeStateHistory { Time = Convert.ToDateTime(item[0]), IsAlive = Convert.ToBoolean(item[1]), IsForked = Convert.ToBoolean(item[2]) }); } return(result); }
//[Fact] public void TestSetAndGet() { var database = "unittest"; InfluxDBHelper.CreateDatabase(database); var used = 50; var time = DateTime.Now; InfluxDBHelper.Set(database, "cpu", new Dictionary <string, object> { { "used", used } }, null, time); Thread.Sleep(1000); var result = InfluxDBHelper.Get(database, "select * from cpu"); Assert.True(Convert.ToInt32(result[0].Values[0][1]) == used); InfluxDBHelper.DropDatabase(database); }
public async Task RecordBlockInfo(string chainId) { ulong currentHeight; var currentRecord = InfluxDBHelper.Get(chainId, "select last(height) from block_info"); if (currentRecord.Count == 0) { currentHeight = await GetCurrentChainHeight(chainId); } else { var record = currentRecord.First().Values.First(); var time = Convert.ToDateTime(record[0]); if (time < DateTime.Now.AddHours(-1)) { currentHeight = await GetCurrentChainHeight(chainId); } else { currentHeight = Convert.ToUInt64(record[1]) + 1; } } var blockInfo = await GetBlockInfo(chainId, currentHeight); while (blockInfo.Result != null && blockInfo.Result.Body != null && blockInfo.Result.Header != null) { var fields = new Dictionary <string, object> { { "height", currentHeight }, { "tx_count", blockInfo.Result.Body.TransactionsCount } }; InfluxDBHelper.Set(chainId, "block_info", fields, null, blockInfo.Result.Header.Time); Thread.Sleep(1000); currentHeight++; blockInfo = await GetBlockInfo(chainId, currentHeight); } }