Exemple #1
0
        public void Initialize(DatabaseConnectionSettings connectionSettings, DatabaseTablesSettings tables, MetricsWriterSettings writerSettings)
        {
            _connectionSettings = connectionSettings;
            _tables             = tables;
            _writerSettings     = writerSettings;

            counterDataTable = new DataTable();
            counterDataTable.Columns.Add("CounterName", typeof(string));
            counterDataTable.Columns.Add("StartTime", typeof(DateTime));
            counterDataTable.Columns.Add("EndTime", typeof(DateTime));
            counterDataTable.Columns.Add("Count", typeof(long));

            histogramDataTable = new DataTable();
            histogramDataTable.Columns.Add("HistogramName", typeof(string));
            histogramDataTable.Columns.Add("StartTime", typeof(DateTime));
            histogramDataTable.Columns.Add("EndTime", typeof(DateTime));
            histogramDataTable.Columns.Add("BucketFrom", typeof(int));
            histogramDataTable.Columns.Add("BucketTo", typeof(int));
            histogramDataTable.Columns.Add("Count", typeof(long));

            eventDataTable = new DataTable();
            eventDataTable.Columns.Add("EventName", typeof(string));
            eventDataTable.Columns.Add("Timestamp", typeof(DateTime));

            EnsureTablesExist();
        }
        public void Initialize(DatabaseConnectionSettings connectionSettings, DatabaseTablesSettings tables, MetricsWriterSettings writerSettings)
        {
            _connectionSettings = connectionSettings;

            _connectionString = new NpgsqlConnectionStringBuilder
            {
                Host            = connectionSettings.Host,
                Port            = connectionSettings.Port,
                Username        = connectionSettings.Username,
                Password        = connectionSettings.Password,
                Database        = connectionSettings.Database,
                SslMode         = connectionSettings.RequireSsl ? SslMode.Require : SslMode.Prefer,
                RootCertificate = connectionSettings.CaCertFile
            }.ConnectionString;

            var databaseName = _connectionSettings.Database;

            counterTable = new Table(_connectionString, databaseName, writerSettings)
            {
                Name    = tables.Counter,
                Columns = new List <Column> {
                    new Column {
                        Name = "Id", DataType = "UUID", DefaultFunction = "gen_random_uuid()"
                    },
                    new Column {
                        Name = "CounterName", DataType = "VARCHAR(8000)"
                    },
                    new Column {
                        Name = "StartTime", DataType = "TIMESTAMP"
                    },
                    new Column {
                        Name = "EndTime", DataType = "TIMESTAMP"
                    },
                    new Column {
                        Name = "Count", DataType = "INT"
                    },
                },
                PrimaryKey = "Id",
            };

            histogramTable = new Table(_connectionString, databaseName, writerSettings)
            {
                Name    = tables.Histogram,
                Columns = new List <Column> {
                    new Column {
                        Name = "Id", DataType = "UUID", DefaultFunction = "gen_random_uuid()"
                    },
                    new Column {
                        Name = "HistogramName", DataType = "VARCHAR(8000)"
                    },
                    new Column {
                        Name = "StartTime", DataType = "TIMESTAMP"
                    },
                    new Column {
                        Name = "EndTime", DataType = "TIMESTAMP"
                    },
                    new Column {
                        Name = "BucketFrom", DataType = "INT4"
                    },
                    new Column {
                        Name = "BucketTo", DataType = "INT4"
                    },
                    new Column {
                        Name = "Count", DataType = "INT"
                    },
                },
                PrimaryKey = "Id",
            };

            eventTable = new Table(_connectionString, databaseName, writerSettings)
            {
                Name    = tables.Event,
                Columns = new List <Column> {
                    new Column {
                        Name = "Id", DataType = "UUID", DefaultFunction = "gen_random_uuid()"
                    },
                    new Column {
                        Name = "EventName", DataType = "VARCHAR(8000)"
                    },
                    new Column {
                        Name = "Timestamp", DataType = "TIMESTAMP"
                    }
                },
                PrimaryKey = "Id",
            };

            profileTable = new Table(_connectionString, databaseName, writerSettings)
            {
                Name    = tables.Profile,
                Columns = new List <Column> {
                    new Column {
                        Name = "Id", DataType = "UUID", DefaultFunction = "gen_random_uuid()"
                    },
                    new Column {
                        Name = "SessionId", DataType = "VARCHAR(8000)"
                    },
                    new Column {
                        Name = "ProfileName", DataType = "VARCHAR(8000)"
                    },
                    new Column {
                        Name = "Process", DataType = "INT4"
                    },
                    new Column {
                        Name = "Thread", DataType = "VARCHAR(200)"
                    },
                    new Column {
                        Name = "Timestamp", DataType = "TIMESTAMP"
                    },
                    new Column {
                        Name = "Phase", DataType = "CHAR"
                    },
                },
                PrimaryKey = "Id",
            };

            EnsureDatabaseExists();
            counterTable.EnsureExists();
            histogramTable.EnsureExists();
            eventTable.EnsureExists();
            profileTable.EnsureExists();
        }