Inheritance: IInfluxDatabase
示例#1
0
        /// <summary>
        /// Gets the whole DB structure for the given databse in Influx.
        /// </summary>
        /// <param name="dbName">Name of the database</param>
        /// <returns>Hierarchical structure, Database<Measurement<Tags,Fields>></returns>
        ///<exception cref="UnauthorizedAccessException">When Influx needs authentication, and no user name password is supplied or auth fails</exception>
        ///<exception cref="HttpRequestException">all other HTTP exceptions</exception>
        public async Task <IInfluxDatabase> GetInfluxDBStructureAsync(string dbName)
        {
            var dbStructure = new InfluxDatabase(dbName);
            var fields      = await QueryMultiSeriesAsync(dbName, "SHOW FIELD KEYS");

            foreach (var s in fields)
            {
                var measurement = new InfluxMeasurement(s.SeriesName);
                foreach (var e in s.Entries)
                {
                    measurement.Fields.Add(e.FieldKey);
                }
                dbStructure.Measurements.Add(measurement);
            }

            var tags = await QueryMultiSeriesAsync(dbName, "SHOW TAG KEYS");

            foreach (var t in tags)
            {
                var measurement = dbStructure.Measurements.FirstOrDefault(x => x.Name == t.SeriesName);
                foreach (var e in t.Entries)
                {
                    measurement.Tags.Add(e.TagKey);
                }
            }

            return(dbStructure);
        }
        /// <summary>
        /// Gets the whole DB structure for the given databse in Influx.
        /// </summary>
        /// <param name="dbName">Name of the database</param>
        /// <returns>Hierarchical structure, Database<Measurement<Tags,Fields>></returns>
        ///<exception cref="UnauthorizedAccessException">When Influx needs authentication, and no user name password is supplied or auth fails</exception>
        ///<exception cref="HttpRequestException">all other HTTP exceptions</exception>
        public async Task <IInfluxDatabase> GetInfluxDBStructureAsync(string dbName)
        {
            var dbStructure       = new InfluxDatabase(dbName);
            var retentionPolicies = await GetRetentionPoliciesAsync(dbName);

            foreach (var policy in retentionPolicies)
            {
                dbStructure.MeasurementHierarchy.Add(policy, new HashSet <IInfluxMeasurement>());

                var fields = await QueryMultiSeriesAsync(dbName : dbName, retentionPolicy : policy.Name, measurementQuery : "SHOW FIELD KEYS");

                foreach (var s in fields)
                {
                    var measurement = new InfluxMeasurement(s.SeriesName);
                    dbStructure.Measurements.Add(measurement);
                    dbStructure.MeasurementHierarchy[policy].Add(measurement);

                    foreach (var e in s.Entries)
                    {
                        measurement.Fields.Add(e.FieldKey);
                    }

                    measurement.SeriesCount = (await QueryMultiSeriesAsync(dbName: dbName, retentionPolicy: policy.Name, measurementQuery: "SHOW SERIES")).FirstOrDefault().Entries?.Count() ?? -1;

                    var points = (IDictionary <string, object>)(await QueryMultiSeriesAsync(dbName: dbName, retentionPolicy: policy.Name, measurementQuery: $"select count(*) from \"{s.SeriesName}\"")).FirstOrDefault().Entries?.FirstOrDefault();
                    //influx returns point counts for each of the fields. Pick the larget of them as total points in the measurement
                    measurement.PointsCount = measurement.Fields.Select(f => int.Parse(points[$"Count_{f}"].ToString())).Max();
                }

                var tags = await QueryMultiSeriesAsync(dbName : dbName, retentionPolicy : policy.Name, measurementQuery : "SHOW TAG KEYS");

                foreach (var t in tags)
                {
                    var measurement = dbStructure.Measurements.FirstOrDefault(x => x.Name == t.SeriesName);
                    foreach (var e in t.Entries)
                    {
                        measurement.Tags.Add(e.TagKey);
                    }
                }
            }
            return(dbStructure);
        }
        /// <summary>
        /// Gets the whole DB structure for the given databse in Influx.
        /// </summary>
        /// <param name="dbName">Name of the database</param>
        /// <returns>Hierarchical structure, Database<Measurement<Tags,Fields>></returns>
        ///<exception cref="UnauthorizedAccessException">When Influx needs authentication, and no user name password is supplied or auth fails</exception>
        ///<exception cref="HttpRequestException">all other HTTP exceptions</exception>
        public async Task<IInfluxDatabase> GetInfluxDBStructureAsync (string dbName)
        {
            var dbStructure = new InfluxDatabase (dbName);
            var fields = await QueryMultiSeriesAsync (dbName, "SHOW FIELD KEYS");
            foreach (var s in fields)
            {
                var measurement = new InfluxMeasurement (s.SeriesName);
                foreach (var e in s.Entries)
                    measurement.Fields.Add (e.FieldKey);
                dbStructure.Measurements.Add (measurement);
            }

            var tags = await QueryMultiSeriesAsync (dbName, "SHOW TAG KEYS");
            foreach (var t in tags)
            {
                var measurement = dbStructure.Measurements.FirstOrDefault (x => x.Name == t.SeriesName);
                foreach (var e in t.Entries)
                    measurement.Tags.Add (e.TagKey);
            }

            return dbStructure;
        }
示例#4
0
 private List<GenericColumn> FilterGenericColumns (List<GenericColumn> columns, List<GenericColumn> filterColumns, InfluxDatabase dbStructure)
 {
     switch (settings.GenericFile.Filter)
     {
         case Filters.Measurement:
             return columns.Where (p => dbStructure.Measurements.Any (m => m.Name == settings.InfluxDB.Measurement)).ToList ();
         case Filters.Field:
             return columns.Where (p => dbStructure.Measurements.Any (m => m.Name == settings.InfluxDB.Measurement) &&
              (dbStructure.Measurements.FirstOrDefault (m => m.Name == settings.InfluxDB.Measurement).Tags.Contains (p.ColumnHeader)
              || dbStructure.Measurements.FirstOrDefault (m => m.Name == settings.InfluxDB.Measurement).Fields.Contains (p.ColumnHeader))).ToList ();
         case Filters.Columns:
             return columns.Where (p => filterColumns.Any (f => f.ColumnHeader == p.ColumnHeader)).ToList ();
     }
     return columns;
 }
示例#5
0
 private List<PerfmonCounter> FilterPerfmonLogColumns (List<PerfmonCounter> columns, List<PerfmonCounter> filterColumns, InfluxDatabase dbStructure)
 {
     switch (settings.PerfmonFile.Filter)
     {
         case Filters.Measurement:
             return columns.Where (p => dbStructure.Measurements.Any (m => m.Name == p.PerformanceObject)).ToList ();
         case Filters.Field:
             return columns.Where (p => dbStructure.Measurements.Any (m => m.Name == p.PerformanceObject) && dbStructure.Measurements.FirstOrDefault (m => m.Name == p.PerformanceObject).Fields.Any (f => f == p.CounterName)).ToList ();
         case Filters.Columns:
             return columns.Where (p => filterColumns.Any (f => p.PerformanceObject == f.PerformanceObject && p.CounterName == f.CounterName)).ToList ();
     }
     return columns;
 }