Documentation
¶
Index ¶
- Constants
- func NewTableSources(p *Postgresql, metrics []telegraf.Metric) map[string]*TableSource
- type Postgresql
- type TableManager
- type TableSource
- func (tsrc *TableSource) AddMetric(metric telegraf.Metric)
- func (tsrc *TableSource) ColumnNames() []string
- func (tsrc *TableSource) DropColumn(col utils.Column) error
- func (tsrc *TableSource) Err() error
- func (tsrc *TableSource) FieldColumns() []utils.Column
- func (tsrc *TableSource) MetricTableColumns() []utils.Column
- func (tsrc *TableSource) Name() string
- func (tsrc *TableSource) Next() bool
- func (tsrc *TableSource) Reset()
- func (tsrc *TableSource) TagColumns() []utils.Column
- func (tsrc *TableSource) TagTableColumns() []utils.Column
- func (tsrc *TableSource) Values() ([]interface{}, error)
- type TagTableSource
- func (ttsrc *TagTableSource) ColumnNames() []string
- func (ttsrc *TagTableSource) Err() error
- func (ttsrc *TagTableSource) Name() string
- func (ttsrc *TagTableSource) Next() bool
- func (ttsrc *TagTableSource) Reset()
- func (ttsrc *TagTableSource) UpdateCache()
- func (ttsrc *TagTableSource) Values() ([]interface{}, error)
- type Uint8
- func (u *Uint8) AssignTo(dst interface{}) error
- func (u *Uint8) DecodeBinary(_, src []byte) error
- func (u *Uint8) DecodeText(_, src []byte) error
- func (u *Uint8) EncodeBinary(_, buf []byte) ([]byte, error)
- func (u *Uint8) EncodeText(_, buf []byte) ([]byte, error)
- func (u *Uint8) Get() interface{}
- func (u *Uint8) MarshalJSON() ([]byte, error)
- func (u *Uint8) Scan(src interface{}) error
- func (u *Uint8) Set(src interface{}) error
- func (u *Uint8) UnmarshalJSON(b []byte) error
- func (u *Uint8) Value() (driver.Value, error)
Constants ¶
const ( PgBool = "boolean" PgSmallInt = "smallint" PgInteger = "integer" PgBigInt = "bigint" PgReal = "real" PgDoublePrecision = "double precision" PgNumeric = "numeric" PgText = "text" PgTimestampWithTimeZone = "timestamp with time zone" PgTimestampWithoutTimeZone = "timestamp without time zone" PgSerial = "serial" PgJSONb = "jsonb" )
Constants for naming PostgreSQL data types both in their short and long versions.
const (
PgUint8 = "uint8"
)
Types from pguint
Variables ¶
This section is empty.
Functions ¶
func NewTableSources ¶
func NewTableSources(p *Postgresql, metrics []telegraf.Metric) map[string]*TableSource
Types ¶
type Postgresql ¶
type Postgresql struct { Connection string `toml:"connection"` Schema string `toml:"schema"` TagsAsForeignKeys bool `toml:"tags_as_foreign_keys"` TagTableSuffix string `toml:"tag_table_suffix"` ForeignTagConstraint bool `toml:"foreign_tag_constraint"` TagsAsJsonb bool `toml:"tags_as_jsonb"` FieldsAsJsonb bool `toml:"fields_as_jsonb"` CreateTemplates []*sqltemplate.Template `toml:"create_templates"` AddColumnTemplates []*sqltemplate.Template `toml:"add_column_templates"` TagTableCreateTemplates []*sqltemplate.Template `toml:"tag_table_create_templates"` TagTableAddColumnTemplates []*sqltemplate.Template `toml:"tag_table_add_column_templates"` Uint64Type string `toml:"uint64_type"` RetryMaxBackoff config.Duration `toml:"retry_max_backoff"` TagCacheSize int `toml:"tag_cache_size"` LogLevel string `toml:"log_level"` Logger telegraf.Logger `toml:"-"` // contains filtered or unexported fields }
func (*Postgresql) Close ¶
func (p *Postgresql) Close() error
Close closes the connection(s) to the database.
func (*Postgresql) Connect ¶
func (p *Postgresql) Connect() error
Connect establishes a connection to the target database and prepares the cache
func (*Postgresql) Init ¶
func (p *Postgresql) Init() error
func (*Postgresql) SampleConfig ¶
func (p *Postgresql) SampleConfig() string
type TableManager ¶
type TableManager struct { *Postgresql // contains filtered or unexported fields }
func NewTableManager ¶
func NewTableManager(postgresql *Postgresql) *TableManager
NewTableManager returns an instance of the tables.Manager interface that can handle checking and updating the state of tables in the PG database.
func (*TableManager) ClearTableCache ¶
func (tm *TableManager) ClearTableCache()
ClearTableCache clear the table structure cache.
func (*TableManager) EnsureStructure ¶
func (tm *TableManager) EnsureStructure( ctx context.Context, db dbh, tbl *tableState, columns []utils.Column, createTemplates []*sqltemplate.Template, addColumnsTemplates []*sqltemplate.Template, metricsTable *tableState, tagsTable *tableState, ) ([]utils.Column, error)
EnsureStructure ensures that the table identified by tableName contains the provided columns.
createTemplates and addColumnTemplates are the templates which are executed in the event of table create or alter (respectively). metricsTableName and tagsTableName are passed to the templates.
If the table cannot be modified, the returned column list is the columns which are missing from the table. This includes when an error is returned.
func (*TableManager) MatchSource ¶
func (tm *TableManager) MatchSource(ctx context.Context, db dbh, rowSource *TableSource) error
MatchSource scans through the metrics, determining what columns are needed for inserting, and ensuring the DB schema matches.
If the schema does not match, and schema updates are disabled: If a field missing from the DB, the field is omitted. If a tag is missing from the DB, the metric is dropped.
type TableSource ¶
type TableSource struct {
// contains filtered or unexported fields
}
TableSource satisfies pgx.CopyFromSource
func NewTableSource ¶
func NewTableSource(postgresql *Postgresql, name string) *TableSource
func (*TableSource) AddMetric ¶
func (tsrc *TableSource) AddMetric(metric telegraf.Metric)
func (*TableSource) ColumnNames ¶
func (tsrc *TableSource) ColumnNames() []string
func (*TableSource) DropColumn ¶
func (tsrc *TableSource) DropColumn(col utils.Column) error
DropColumn drops the specified column. If column is a tag column, any metrics containing the tag will be skipped. If column is a field column, any metrics containing the field will have it omitted.
func (*TableSource) Err ¶
func (tsrc *TableSource) Err() error
func (*TableSource) FieldColumns ¶
func (tsrc *TableSource) FieldColumns() []utils.Column
FieldColumns returns the superset of all fields of all metrics.
func (*TableSource) MetricTableColumns ¶
func (tsrc *TableSource) MetricTableColumns() []utils.Column
MetricTableColumns returns the full column list, including time, tag id or tags, and fields.
func (*TableSource) Name ¶
func (tsrc *TableSource) Name() string
func (*TableSource) Next ¶
func (tsrc *TableSource) Next() bool
func (*TableSource) Reset ¶
func (tsrc *TableSource) Reset()
func (*TableSource) TagColumns ¶
func (tsrc *TableSource) TagColumns() []utils.Column
TagColumns returns the superset of all tags of all metrics.
func (*TableSource) TagTableColumns ¶
func (tsrc *TableSource) TagTableColumns() []utils.Column
func (*TableSource) Values ¶
func (tsrc *TableSource) Values() ([]interface{}, error)
type TagTableSource ¶
type TagTableSource struct { *TableSource // contains filtered or unexported fields }
func NewTagTableSource ¶
func NewTagTableSource(tsrc *TableSource) *TagTableSource
func (*TagTableSource) ColumnNames ¶
func (ttsrc *TagTableSource) ColumnNames() []string
func (*TagTableSource) Err ¶
func (ttsrc *TagTableSource) Err() error
func (*TagTableSource) Name ¶
func (ttsrc *TagTableSource) Name() string
func (*TagTableSource) Next ¶
func (ttsrc *TagTableSource) Next() bool
func (*TagTableSource) Reset ¶
func (ttsrc *TagTableSource) Reset()
func (*TagTableSource) UpdateCache ¶
func (ttsrc *TagTableSource) UpdateCache()
func (*TagTableSource) Values ¶
func (ttsrc *TagTableSource) Values() ([]interface{}, error)