상속: IInfluxContinuousQuery
예제 #1
0
        /// <summary>
        /// Gets the list of Continuous Queries currently in efect
        /// </summary>
        /// <returns>List of InfluxContinuousQuery objects</returns>
        public async Task <List <IInfluxContinuousQuery> > GetContinuousQueriesAsync()
        {
            var cqPattern = new Regex(@"^CREATE CONTINUOUS QUERY (\S*) ON (\S*) (RESAMPLE (EVERY (\d\S)*)? ?(FOR (\d\S)*)?)? ?BEGIN ([\s\S]*GROUP BY time\((\d\S)\)[\s\S]*) END", RegexOptions.IgnoreCase | RegexOptions.Compiled, TimeSpan.FromSeconds(10));
            //Show Continous Queries runs at a global scope, not just for a given DB.
            var rawCQList = await QueryMultiSeriesAsync(null, "SHOW CONTINUOUS QUERIES");

            var queries = new List <IInfluxContinuousQuery>();

            foreach (var dbEntry in rawCQList.Where(cq => cq.HasEntries == true))
            {
                foreach (var rawCQ in dbEntry.Entries)
                {
                    var cq = new InfluxContinuousQuery()
                    {
                        DBName = dbEntry.SeriesName,
                        Name   = rawCQ.Name,
                        Saved  = true
                    };
                    Match queryParts;
                    try
                    {
                        queryParts           = cqPattern.Match(rawCQ.Query);
                        cq.ResampleFrequency = StringHelper.ParseDuration(queryParts.Groups[5].ToString());
                        cq.ResampleDuration  = StringHelper.ParseDuration(queryParts.Groups[7].ToString());
                        cq.Query             = queryParts.Groups[8].ToString();
                        cq.GroupByInterval   = StringHelper.ParseDuration(queryParts.Groups[9].ToString());
                    }
#pragma warning disable CS0168 // The variable 'e' is declared but never used
                    catch (Exception e)
#pragma warning restore CS0168 // The variable 'e' is declared but never used
                    {
                        string query = rawCQ.Query.ToString();
                        var    begin = query.IndexOf("BEGIN", StringComparison.CurrentCultureIgnoreCase) + 5;
                        cq.Query = query.Substring(begin, query.IndexOf(" END", StringComparison.CurrentCultureIgnoreCase));
                    }

                    queries.Add(cq);
                }
            }
            return(queries);
        }
        /// <summary>
        /// Gets the list of Continuous Queries currently in efect
        /// </summary>
        /// <returns>List of InfluxContinuousQuery objects</returns>
        public async Task<List<IInfluxContinuousQuery>> GetContinuousQueriesAsync ()
        {
            var cqPattern = new Regex (@"^CREATE CONTINUOUS QUERY (\S*) ON (\S*) (RESAMPLE (EVERY (\d\S)*)? ?(FOR (\d\S)*)?)? ?BEGIN ([\s\S]*GROUP BY time\((\d\S)\)[\s\S]*) END", RegexOptions.IgnoreCase | RegexOptions.Compiled, TimeSpan.FromSeconds (10));
            //Show Continous Queries runs at a global scope, not just for a given DB.
            var rawCQList = await QueryMultiSeriesAsync (null, "SHOW CONTINUOUS QUERIES");
            var queries = new List<IInfluxContinuousQuery> ();

            foreach (var dbEntry in rawCQList.Where (cq => cq.HasEntries == true))
            {
                foreach (var rawCQ in dbEntry.Entries)
                {
                    var cq = new InfluxContinuousQuery ()
                    {
                        DBName = dbEntry.SeriesName,
                        Name = rawCQ.Name,
                        Saved = true
                    };
                    Match queryParts;
                    try
                    {
                        queryParts = cqPattern.Match (rawCQ.Query);
                        cq.ResampleFrequency = StringHelper.ParseDuration (queryParts.Groups[5].ToString ());
                        cq.ResampleDuration = StringHelper.ParseDuration (queryParts.Groups[7].ToString ());
                        cq.Query = queryParts.Groups[8].ToString ();
                        cq.GroupByInterval = StringHelper.ParseDuration (queryParts.Groups[9].ToString ());
                    }
#pragma warning disable CS0168 // The variable 'e' is declared but never used
                    catch (Exception e)
#pragma warning restore CS0168 // The variable 'e' is declared but never used
                    {
                        string query = rawCQ.Query.ToString ();
                        var begin = query.IndexOf ("BEGIN", StringComparison.CurrentCultureIgnoreCase) + 5;
                        cq.Query = query.Substring (begin, query.IndexOf (" END", StringComparison.CurrentCultureIgnoreCase));
                    }

                    queries.Add (cq);
                }
            }
            return queries;

        }