Exemple #1
0
        public async Task WriteRecords()
        {
            Console.WriteLine("Writing records");

            DateTimeOffset now = DateTimeOffset.UtcNow;
            string         currentTimeString = (now.ToUnixTimeMilliseconds()).ToString();

            List <Dimension> dimensions = new List <Dimension> {
                new Dimension {
                    Name = "region", Value = "us-east-1"
                },
                new Dimension {
                    Name = "az", Value = "az1"
                },
                new Dimension {
                    Name = "hostname", Value = "host1"
                }
            };

            var cpuUtilization = new Record
            {
                Dimensions       = dimensions,
                MeasureName      = "cpu_utilization",
                MeasureValue     = "13.6",
                MeasureValueType = MeasureValueType.DOUBLE,
                Time             = currentTimeString
            };

            var memoryUtilization = new Record
            {
                Dimensions       = dimensions,
                MeasureName      = "memory_utilization",
                MeasureValue     = "40",
                MeasureValueType = MeasureValueType.DOUBLE,
                Time             = currentTimeString
            };


            List <Record> records = new List <Record> {
                cpuUtilization,
                memoryUtilization
            };

            try
            {
                var writeRecordsRequest = new WriteRecordsRequest
                {
                    DatabaseName = Constants.DATABASE_NAME,
                    TableName    = Constants.TABLE_NAME,
                    Records      = records
                };
                WriteRecordsResponse response = await writeClient.WriteRecordsAsync(writeRecordsRequest);

                Console.WriteLine($"Write records status code: {response.HttpStatusCode.ToString()}");
            }
            catch (Exception e)
            {
                Console.WriteLine("Write records failure:" + e.ToString());
            }
        }
        private async Task write100(List <Record> records)
        {
            var writeRecordsRequest = new WriteRecordsRequest
            {
                DatabaseName = Constants.DATABASE_NAME,
                TableName    = Constants.TABLE_NAME,
                Records      = records
            };
            WriteRecordsResponse response = await writeClient.WriteRecordsAsync(writeRecordsRequest);

            Console.WriteLine($"Write records status code: {response.HttpStatusCode.ToString()}");
        }
Exemple #3
0
        private async Task SubmitBatchAsync(List <Record> records, int counter)
        {
            try
            {
                var writeRecordsRequest = new WriteRecordsRequest
                {
                    DatabaseName = Constants.DATABASE_NAME,
                    TableName    = Constants.TABLE_NAME,
                    Records      = records
                };
                WriteRecordsResponse response = await writeClient.WriteRecordsAsync(writeRecordsRequest);

                Console.WriteLine($"Processed {counter} records. Write records status code:{response.HttpStatusCode.ToString()}");
            }
            catch (Exception e)
            {
                Console.WriteLine("Write records failure:" + e.ToString());
            }
        }
Exemple #4
0
 public async Task WriteRecordsAsync(string table, RecordData[] records, CancellationToken ct = default)
 {
     await _writer.WriteRecordsAsync(new WriteRecordsRequest
     {
         DatabaseName = _database,
         TableName    = table,
         Records      = records.Select(x => new Record
         {
             Time       = x.Time.ToUnixTimeMilliseconds().ToString(),
             TimeUnit   = TimeUnit.MILLISECONDS,
             Dimensions = x.Metadata.Select(m => new Dimension
             {
                 DimensionValueType = DimensionValueType.VARCHAR,
                 Name  = m.Key,
                 Value = m.Value,
             }).ToList(),
             MeasureName      = x.Name,
             MeasureValue     = x.Value.ToString(),
             MeasureValueType = MeasureValueType.DOUBLE,
         })
                        .ToList(),
     }, ct);
 }
Exemple #5
0
        public async Task WriteRecordsMultiMeasureValueSingleRecord()
        {
            Console.WriteLine("Writing records with multi value attributes");

            DateTimeOffset now = DateTimeOffset.UtcNow;
            string         currentTimeString = (now.ToUnixTimeMilliseconds()).ToString();

            List <Dimension> dimensions = new List <Dimension> {
                new Dimension {
                    Name = "region", Value = "us-east-1"
                },
                new Dimension {
                    Name = "az", Value = "az1"
                },
                new Dimension {
                    Name = "hostname", Value = "host1"
                }
            };

            var commonAttributes = new Record
            {
                Dimensions = dimensions,
                Time       = currentTimeString
            };

            var cpuUtilization = new MeasureValue
            {
                Name  = "cpu_utilization",
                Value = "13.6",
                Type  = "DOUBLE"
            };

            var memoryUtilization = new MeasureValue
            {
                Name  = "memory_utilization",
                Value = "40",
                Type  = "DOUBLE"
            };

            var computationalRecord = new Record
            {
                MeasureName   = "cpu_memory",
                MeasureValues = new List <MeasureValue> {
                    cpuUtilization, memoryUtilization
                },
                MeasureValueType = "MULTI"
            };


            List <Record> records = new List <Record>();

            records.Add(computationalRecord);

            try
            {
                var writeRecordsRequest = new WriteRecordsRequest
                {
                    DatabaseName     = MultiMeasureValueConstants.MultiMeasureValueSampleDb,
                    TableName        = MultiMeasureValueConstants.MultiMeasureValueSampleTable,
                    Records          = records,
                    CommonAttributes = commonAttributes
                };
                WriteRecordsResponse response = await writeClient.WriteRecordsAsync(writeRecordsRequest);

                Console.WriteLine($"Write records status code: {response.HttpStatusCode.ToString()}");
            }
            catch (Exception e)
            {
                Console.WriteLine("Write records failure:" + e.ToString());
            }
        }