Пример #1
0
        /// <summary>
        /// Performs a backfill query on the database based on a given time range and backfill parameters.
        /// </summary>
        /// <param name="database">The name of the database to perform the backfill on.</param>
        /// <param name="backfillParams">The backfill parameters query.</param>
        /// <returns>The API response.</returns>
        public async override Task<InfluxDbApiResponse> BackfillAsync(string database, InfluxDbBackfillParams backfillParams)
        {
            if (backfillParams == null) throw new ArgumentNullException("backfillParams");

            // Validate
            if (string.IsNullOrWhiteSpace(backfillParams.Destination)) throw new ArgumentNullException("backfillParams.Destination");
            if (string.IsNullOrWhiteSpace(backfillParams.Source)) throw new ArgumentNullException("backfillParams.Source");
            if (string.IsNullOrWhiteSpace(backfillParams.Interval)) throw new ArgumentNullException("backfillParams.Interval");

            if (backfillParams.SubQueries == null || backfillParams.SubQueries.Count() == 0 || string.IsNullOrWhiteSpace(backfillParams.SubQueries.First()))
                throw new ArgumentException("backfillParams.SubQueries needs at least one query.");

            if (!InfluxDbHelper.IsTimeIntervalValid(backfillParams.Interval))
                throw new ArgumentException("backfillParams.Interval is invalid: " + backfillParams.Interval);

            // Copy values to InfluxData.Net equivalent
            var _bfParams = new BackfillParams()
            {
                DsSerieName = backfillParams.Destination,
                SourceSerieName = backfillParams.Source,
                Downsamplers = backfillParams.SubQueries.ToList(),
                Interval = backfillParams.Interval,
                TimeFrom = backfillParams.FromTime,
                TimeTo = backfillParams.ToTime,
                Filters = backfillParams.Filters != null ? backfillParams.Filters.ToList() : null,
                FillType = (FillType)Enum.Parse(typeof(FillType), backfillParams.FillType.ToString(), true),
                Tags = backfillParams.Tags != null ? backfillParams.Tags.ToList() : null,
            };

            // Execute the request and return response
            var response = await influx.ContinuousQuery.BackfillAsync(database, _bfParams).ConfigureAwait(false);
            return new InfluxDbApiResponse(response.Body, response.StatusCode, response.Success);
        }
Пример #2
0
        /// <summary>
        /// Creates a new Influx DB Continuous Query.
        /// </summary>
        /// <param name="cqParams">The parameters used to create the CQ.</param>
        /// <returns>The API response.</returns>
        public async override Task<InfluxDbApiResponse> CreateContinuousQueryAsync(InfluxDbCqParams cqParams)
        {
            if (cqParams == null) throw new ArgumentNullException("cqParams");

            // Validate
            if (string.IsNullOrWhiteSpace(cqParams.Name)) throw new ArgumentNullException("cqParams.Name");
            if (string.IsNullOrWhiteSpace(cqParams.Database)) throw new ArgumentNullException("cqParams.Database");
            if (string.IsNullOrWhiteSpace(cqParams.Destination)) throw new ArgumentNullException("cqParams.Destination");
            if (string.IsNullOrWhiteSpace(cqParams.Source)) throw new ArgumentNullException("cqParams.Source");
            if (string.IsNullOrWhiteSpace(cqParams.Interval)) throw new ArgumentNullException("cqParams.Interval");

            if (cqParams.SubQueries == null || cqParams.SubQueries.Count() == 0 || string.IsNullOrWhiteSpace(cqParams.SubQueries.First()))
                throw new ArgumentException("cqParams.SubQueries needs at least one query.");

            if (!InfluxDbHelper.IsTimeIntervalValid(cqParams.Interval))
                throw new ArgumentException("cqParams.Interval is invalid: " + cqParams.Interval);

            if (!string.IsNullOrWhiteSpace(cqParams.ResampleEveryInterval) 
                && !InfluxDbHelper.IsTimeIntervalValid(cqParams.ResampleEveryInterval))
            {
                throw new ArgumentException("cqParams.ResampleEveryInterval is invalid: " + cqParams.ResampleEveryInterval);
            }

            if (!string.IsNullOrWhiteSpace(cqParams.ResampleForInterval)
                && !InfluxDbHelper.IsTimeIntervalValid(cqParams.ResampleForInterval))
            {
                throw new ArgumentException("cqParams.ResampleForInterval is invalid: " + cqParams.ResampleForInterval);
            }

            // Copy values to InfluxData.Net equivalent
            var _cqParams = new CqParams()
            {
                CqName = cqParams.Name,
                DbName = cqParams.Database,
                DsSerieName = cqParams.Destination,
                SourceSerieName = cqParams.Source,
                Downsamplers = cqParams.SubQueries.ToList(),
                Interval = cqParams.Interval,
                FillType = (FillType)Enum.Parse(typeof(FillType), cqParams.FillType.ToString(), true),
                Tags = cqParams.Tags != null ? cqParams.Tags.ToList() : null,
            };

            // Add resample values if they exist
            if (!string.IsNullOrWhiteSpace(cqParams.ResampleEveryInterval)
                || !string.IsNullOrWhiteSpace(cqParams.ResampleForInterval))
            {
                _cqParams.Resample = new CqResampleParam()
                {
                    Every = cqParams.ResampleEveryInterval,
                    For = cqParams.ResampleForInterval
                };
            }

            // Execute the request and return response
            var response = await influx.ContinuousQuery.CreateContinuousQueryAsync(_cqParams).ConfigureAwait(false);
            return new InfluxDbApiResponse(response.Body, response.StatusCode, response.Success);
        }