Beispiel #1
0
 public InfluxClientFixture()
 {
     Client = new InfluxClient(new Uri(InfluxHost), "root", "root");
     //Client.DefaultQueryOptions.UsePost = true;
     //Client.DefaultQueryOptions.Precision = TimestampPrecision.Microsecond;
     Client.CreateDatabaseAsync(DatabaseName).Wait();
 }
Beispiel #2
0
        static async Task MainAsync(string[] args)
        {
            InfluxClassMap.Register <ComputerInfo>(cm =>
            {
                cm.SetMeasurementName(__measurementName);
                cm.MapTimestamp(x => x.Timestamp);
                cm.MapTag(x => x.Host, "host");
                cm.MapTag(x => x.Region, "region");
                cm.MapField(x => x.CPU, "cpu");
                cm.MapField(x => x.RAM, "ram");
            });
            const string influxHost   = "http://localhost:8086"; //"http://ipv4.fiddler:8086";
            const string databaseName = "mydb";

            var client = new InfluxClient(new Uri(influxHost));
            await client.CreateDatabaseAsync(databaseName);

            await Should_Write_Typed_Rows_To_Database(databaseName, client);
            await Should_Query_And_Display_Typed_Data(databaseName, client);
            await Should_Query_With_Parameters_And_Display_Typed_Data(databaseName, client);

            await client.DropDatabaseAsync(databaseName);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Beispiel #3
0
 private Task CreateDatabase()
 {
     lock ( _sync )
     {
         if (_createDatabase == null || _createDatabase.IsFaulted || _createDatabase.IsCanceled)
         {
             _createDatabase = _client.CreateDatabaseAsync(_database);
         }
     }
     return(_createDatabase);
 }
        public async Task Should_Throw_When_Creating_Duplicate_Database()
        {
            await _client.CreateDatabaseIfNotExistsAsync(Unused);

            await Assert.ThrowsAsync(typeof(InfluxException), async() =>
            {
                await _client.CreateDatabaseAsync(Unused);
            });

            await _client.DropDatabaseAsync(Unused);
        }
Beispiel #5
0
        public void CreateDB(string v)
        {
            var result = _client.CreateDatabaseAsync(v);

            result.Wait();

            if (result.Result.Succeeded != true)
            {
                //** TODO better Exception
                throw new Exception();
            }
        }
        static async Task <int> MainAsync(string[] args)
        {
            try
            {
                #region Test

                /*
                 * // WARNING: Remove or comment out this part for production.
                 * var testArgs = AppSettings.SensorListener.ExecutionParamsStringExample.Split(' ');
                 * args = testArgs;
                 */
                #endregion Test

                _parsedInputParams = CommandLineArgsParser.CommandLineArgsParser.ParseInputParams(args);
            }
            catch (Exception ex)
            {
                var errorMessage = "ERROR: execution params parsing failed.\r\n" + ex.Message;
                Console.WriteLine(errorMessage);

                return(1);
            }

            _measurementName = AppSettings.MeasurementNameBase + _parsedInputParams.TestId;

            _influxClient = new InfluxClient(new Uri(AppSettings.InfluxHost));

            // var databases = await _client.ShowDatabasesAsync();

            await _influxClient.CreateDatabaseAsync(AppSettings.InfluxDatabaseName); // Creates Influx database if not exist

            InitTimer(_parsedInputParams.ProgramExecutionTime);

            try
            {
                Console.WriteLine("Listening to port: {0}...", AppSettings.SensorListener.ListenPort);

                Thread receiveThread = new Thread(new ThreadStart(ReceiveMessage));
                receiveThread.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(2);
            }

            return(0);
        }
Beispiel #7
0
        public async Task Should_Create_Show_And_Delete_Database()
        {
            await _client.CreateDatabaseAsync(Unused);

            var result = await _client.ShowDatabasesAsync();

            Assert.True(result.Succeeded);
            Assert.Equal(result.Series.Count, 1);

            var rows = result.Series[0].Rows;

            Assert.Contains(rows, x => x.Name == Unused);

            await _client.DropDatabaseAsync(Unused);
        }
Beispiel #8
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services
            .AddMvc()
            .AddJsonOptions(opts =>
            {
                opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                opts.SerializerSettings.Converters.Add(new StringEnumConverter {
                    CamelCaseText = true
                });
            })
            .AddXmlSerializerFormatters();

            services.AddAuthentication(ApiKeyAuthenticationHandler.SchemeName)
            .AddScheme <AuthenticationSchemeOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthenticationHandler.SchemeName, null);


            services
            .AddSwaggerGen(c =>
            {
                c.SwaggerDoc("1.0.0", new Info
                {
                    Version     = "1.0.0",
                    Title       = "Smart AC POC - Device API",
                    Description = "Smart AC POC - Device API (ASP.NET Core 2.0)",
                    Contact     = new Contact()
                    {
                        Name  = "Rubén Martínez",
                        Url   = "http://github.com/rubms",
                        Email = "*****@*****.**"
                    },
                    TermsOfService = ""
                });
                c.CustomSchemaIds(type => type.FriendlyId(true));
                c.DescribeAllEnumsAsStrings();
                c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml");

                // Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..)
                // Use [ValidateModelState] on Actions to actually validate it in C# as well!
                c.OperationFilter <GeneratePathParamsValidationFilter>();
            });

            var influxClient = new InfluxClient(new Uri(Configuration.GetValue <string>("InfluxDbEndpoint")));

            influxClient.CreateDatabaseAsync(Configuration.GetValue <string>("InfluxDbName")).Wait();
            services.AddSingleton <InfluxClient>(influxClient);
        }
Beispiel #9
0
        static async Task MainAsync(string[] args)
        {
            const string influxHost   = "http://ipv4.fiddler:8086"; // "http://localhost:8086";
            const string databaseName = "mydb";

            var client = new InfluxClient(new Uri(influxHost));

            await client.CreateDatabaseAsync(databaseName);

            await Should_Write_Typed_Rows_To_Database(databaseName, client);
            await Should_Query_And_Display_Typed_Data(databaseName, client);

            await client.DropDatabaseAsync(databaseName);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Beispiel #10
0
 public InfluxClientFixture()
 {
     Client = new InfluxClient(new Uri(InfluxHost), "root", "root");
     Client.CreateDatabaseAsync(DatabaseName).Wait();
 }
        static async Task <int> MainAsync(string[] args)
        {
            var x = InfluxHost;

            _client = new InfluxClient(new Uri(InfluxHost));

            await _client.CreateDatabaseAsync(InfluxDatabaseName); // Creates Influx database if not exist

            try
            {
                #region Test

                var isDebug = true;

                if (isDebug)
                {
                    // WARNING: Remove or comment out this part for production.
                    var testArgs = ExecutionParamsStringExample.Split(' ');
                    args = testArgs;
                }

                #endregion Test

                _parsedInputParams = ParseInputParams(args);
            }
            catch (Exception ex)
            {
                var errorMessage = "ERROR: execution params parsing failed.\r\n" + ex.Message;
                Console.WriteLine(errorMessage);

                return(1);
            }

            foreach (var testSensorsInfo in _parsedInputParams.TestSensorsInfo)
            {
                var query = QueryMaker.GetSensorOutputsForTest(
                    testSensorsInfo.TestId,
                    _parsedInputParams.LeftTimeBorder,
                    _parsedInputParams.RightTimeBorder,
                    testSensorsInfo.Sensors);

                var resultSet = await _client.ReadAsync <SensorOutput>(InfluxDatabaseName, query);

                var results = resultSet.Results[0];
                var series  = results.Series;

                if (series.Count < 1)
                {
                    Console.WriteLine(
                        $"WARNING: There were no outputs found for the specified parameters: \r\n" +
                        GetSearchConditionsString(_parsedInputParams.LeftTimeBorder, _parsedInputParams.RightTimeBorder,
                                                  testSensorsInfo));

                    continue;
                }

                var retrievedOutputs = series[0].Rows;

                try
                {
                    await ParseSensorsDatatypeAsync(testSensorsInfo.Sensors);
                }
                catch (Npgsql.PostgresException postgresException)
                {
                    Console.WriteLine("ERROR:" + postgresException.Message);
                    return(1);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                var outputsForExport = ParseRetrievedData(retrievedOutputs);

                var jsonExport = new JsonExport(
                    testSensorsInfo.TestId,
                    _parsedInputParams.LeftTimeBorder,
                    _parsedInputParams.RightTimeBorder,
                    outputsForExport);

                var exportedFile = jsonExport.GetSensorOutputsFile();

                // var directoryPath = DefaultDirectoryPath;
                var directoryPath = _parsedInputParams.DirectoryPath;

                try
                {
                    FileWriter.WriteFileToDirectory(directoryPath, exportedFile.FileContents, exportedFile.FileName);

                    WriteSuccessMessage(
                        _parsedInputParams.LeftTimeBorder,
                        _parsedInputParams.RightTimeBorder,
                        testSensorsInfo,
                        exportedFile.FileName
                        );
                }
                catch (Exception e)
                {
                    Console.Write("ERROR: Writing to file failed with the following message: ");
                    Console.WriteLine(e);
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();

            return(0);
        }