Exemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var fluxClient = FluxClientFactory.Create("http://localhost:8086/");

//             var fluxQuery = "from(bucket: \"telegraf\")\n"
//   + "|> range(start: -5m)"
//   + "|> filter(fn: (r) => r._measurement == \"influxdb_httpd\")";

            var fluxQuery = "from(bucket: \"telegraf/autogen\")\n"
                            + "|> range(start: -5m)"
                            + "|> filter(fn: (r) => r._measurement == \"cpu\")"
                            + "|> mean()"
                            + "|> group(columns: [\"_time\", \"_start\", \"_stop\", \"_value\"], mode: \"except\")";

            await fluxClient.QueryAsync(fluxQuery, (cancellable, record) =>
            {
                // process the flux query records
                Console.WriteLine(record.GetMeasurement() + ": " + record.GetValue());
            },
                                        (error) =>
            {
                // error handling while processing result
                Console.WriteLine(error.ToString());
            }, () =>
            {
                // on complete
                Console.WriteLine("Query completed");
            });
        }
Exemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            var options = new FluxConnectionOptions("http://127.0.0.1:8086");

            var fluxClient = FluxClientFactory.Create(options);

            var fluxQuery = "from(bucket: \"telegraf\")\n"
                            + " |> filter(fn: (r) => (r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_system\"))"
                            + " |> range(start: -1d)"
                            + " |> sample(n: 5, pos: 1)";

            await fluxClient.QueryAsync(fluxQuery, (cancellable, record) =>
            {
                // process the flux query records
                Console.WriteLine(record.GetTime() + ": " + record.GetValue());
            },
                                        (error) =>
            {
                // error handling while processing result
                Console.WriteLine(error.ToString());
            }, () =>
            {
                // on complete
                Console.WriteLine("Query completed");
            });
        }
Exemplo n.º 3
0
        public static async Task Run()
        {
            Console.WriteLine("Start");

            var options = new FluxConnectionOptions("http://127.0.0.1:8086", TimeSpan.FromSeconds(20));
            var client  = FluxClientFactory.Create(options);

            var fluxQuery = "from(bucket: \"telegraf\")\n"
                            + " |> filter(fn: (r) => (r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_system\"))"
                            + " |> range(start: -1d)"
                            + " |> sample(n: 5, pos: 1)";

            var tables = await client.QueryAsync(fluxQuery);

            if (tables != null)
            {
                foreach (var fluxTable in tables)
                {
                    foreach (var fluxRecord in fluxTable.Records)
                    {
                        Console.WriteLine(fluxRecord.GetTime() + ": " + fluxRecord.GetValueByKey("_value"));
                    }
                }
            }
        }
        public static async Task Run()
        {
            var options = new FluxConnectionOptions("http://127.0.0.1:8086");

            var fluxClient = FluxClientFactory.Create(options);

            var fluxQuery = "from(bucket: \"telegraf\")\n"
                            + " |> filter(fn: (r) => (r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_system\"))"
                            + " |> range(start: -1d)"
                            + " |> sample(n: 5, pos: 1)";

            ////Example of additional result stream processing on client side
            await fluxClient.Query <Cpu>(fluxQuery,
                                         (cancellable, cpu) =>
            {
                // process the flux query records
                Console.WriteLine(cpu.ToString());
            },
                                         (error) =>
            {
                // error handling while processing result
                Console.WriteLine(error.ToString());
            }, () =>
            {
                // on complete
                Console.WriteLine("Query completed");
            });
        }
Exemplo n.º 5
0
        async Task SetUpAsync()
        {
            var influxUrl = GetInfluxDbUrl();

            var options = new FluxConnectionOptions(influxUrl);

            FluxClient = FluxClientFactory.Create(options);

            await InfluxDbQuery("CREATE DATABASE " + DatabaseName, DatabaseName);
        }
Exemplo n.º 6
0
        public void ProxyDefaultConfigured()
        {
            var webProxy = new WebProxy("my-proxy", 8088);

            var options = new FluxConnectionOptions("http://127.0.0.1:8086",
                                                    TimeSpan.FromSeconds(60),
                                                    webProxy: webProxy);

            var fluxClient = FluxClientFactory.Create(options);

            Assert.AreEqual(webProxy, GetRestClient(fluxClient).Proxy);
        }
Exemplo n.º 7
0
        public async Task WithAuthentication()
        {
            FluxClient = FluxClientFactory.Create(new FluxConnectionOptions(MockServerUrl, "my-user", "my-password".ToCharArray()));

            MockServer.Given(Request.Create()
                             .WithPath("/ping")
                             .WithParam("u", new ExactMatcher("my-user"))
                             .WithParam("p", new ExactMatcher("my-password"))
                             .UsingGet())
            .RespondWith(Response.Create().WithStatusCode(204));

            Assert.IsTrue(await FluxClient.PingAsync());
        }
Exemplo n.º 8
0
        public async Task WithAuthentication()
        {
            FluxClient = FluxClientFactory.Create(new FluxConnectionOptions(MockServerUrl, "my-user", "my-password".ToCharArray()));

            MockServer.Given(Request.Create()
                             .WithPath("/api/v2/query")
                             .WithParam("u", new ExactMatcher("my-user"))
                             .WithParam("p", new ExactMatcher("my-password"))
                             .UsingPost())
            .RespondWith(CreateResponse());

            var result = await FluxClient.QueryAsync("from(bucket:\"telegraf\")");

            AssertSuccessResult(result);
        }
Exemplo n.º 9
0
        public async Task WithBasicAuthentication()
        {
            FluxClient = FluxClientFactory.Create(new FluxConnectionOptions(MockServerUrl, "my-user",
                                                                            "my-password".ToCharArray(), FluxConnectionOptions.AuthenticationType.BasicAuthentication));

            var auth = System.Text.Encoding.UTF8.GetBytes("my-user:my-password");

            MockServer.Given(Request.Create()
                             .WithPath("/ping")
                             .WithHeader("Authorization",
                                         new ExactMatcher("Basic " + Convert.ToBase64String(auth)))
                             .UsingGet())
            .RespondWith(Response.Create().WithStatusCode(204));

            Assert.IsTrue(await FluxClient.PingAsync());
        }
        public async Task WithBasicAuthentication()
        {
            FluxClient = FluxClientFactory.Create(new FluxConnectionOptions(MockServerUrl, "my-user",
                                                                            "my-password".ToCharArray(), FluxConnectionOptions.AuthenticationType.BasicAuthentication));

            var auth = System.Text.Encoding.UTF8.GetBytes("my-user:my-password");

            MockServer.Given(Request.Create()
                             .WithPath("/api/v2/query")
                             .WithHeader("Authorization",
                                         new ExactMatcher("Basic " + Convert.ToBase64String(auth)))
                             .UsingPost())
            .RespondWith(CreateResponse());

            var result = await FluxClient.QueryAsync("from(bucket:\"telegraf\")");

            AssertSuccessResult(result);
        }
Exemplo n.º 11
0
        public static async Task Main(string[] args)
        {
            var fluxClient = FluxClientFactory.Create("http://localhost:8086/");

            var fluxQuery = "from(bucket: \"telegraf\")\n"
                            + " |> filter(fn: (r) => (r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_system\"))"
                            + " |> range(start: -1d)"
                            + " |> sample(n: 5, pos: 1)";

            await fluxClient.QueryRawAsync(fluxQuery, (cancellable, line) =>
            {
                // process the flux query result record
                Console.WriteLine(line);
            },
                                           (error) =>
            {
                // error handling while processing result
                Console.WriteLine(error.ToString());
            }, () =>
            {
                // on complete
                Console.WriteLine("Query completed");
            });
        }
        public void Connect()
        {
            var fluxClient = FluxClientFactory.Create("http://localhost:8093");

            Assert.IsNotNull((fluxClient));
        }
Exemplo n.º 13
0
 public void SetUp()
 {
     _fluxClient = FluxClientFactory.Create("http://localhost:8093");
 }
 public new void SetUp()
 {
     FluxClient = FluxClientFactory.Create(MockServerUrl);
 }