Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snowflake support #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Database agnostic SQL exporter for [Prometheus](https://prometheus.io).
## Overview

SQL Exporter is a configuration driven exporter that exposes metrics gathered from DBMSs, for use by the Prometheus
monitoring system. Out of the box, it provides support for MySQL, PostgreSQL, Microsoft SQL Server and Clickhouse, but
monitoring system. Out of the box, it provides support for MySQL, PostgreSQL, Microsoft SQL Server, Clickhouse, and Snowflake, but
any DBMS for which a Go driver is available may be monitored after rebuilding the binary with the DBMS driver included.

The collected metrics and the queries that produce them are entirely configuration defined. SQL queries are grouped into
Expand Down
12 changes: 11 additions & 1 deletion sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
_ "github.com/ClickHouse/clickhouse-go" // register the ClickHouse driver
_ "github.com/denisenkom/go-mssqldb" // register the MS-SQL driver
_ "github.com/go-sql-driver/mysql" // register the MySQL driver
_ "github.com/lib/pq" // register the PostgreSQL driver
_ "github.com/snowflakedb/gosnowflake" // register the Snowflake driver

log "github.com/golang/glog"
_ "github.com/lib/pq" // register the PostgreSQL driver
)

// OpenConnection extracts the driver name from the DSN (expected as the URI scheme), adjusts it where necessary (e.g.
Expand Down Expand Up @@ -43,6 +45,12 @@ import (
// Using the https://github.com/kshvakov/clickhouse driver, DSN format (passed to the driver with the`clickhouse://`
// prefix replaced with `tcp://`):
// clickhouse://host:port?username=username&password=password&database=dbname&param=value
//
// Snowflake
//
// Using the https://godoc.org/github.com/snowflakedb/gosnowflake driver, DSN format (passed to the driver stripped
// of the `snowflake://`` prefix):
// snowflake://username:password@account/dbname?role=rolename&warehouse=warehousename&param=value
func OpenConnection(ctx context.Context, logContext, dsn string, maxConns, maxIdleConns int) (*sql.DB, error) {
// Extract driver name from DSN.
idx := strings.Index(dsn, "://")
Expand All @@ -57,6 +65,8 @@ func OpenConnection(ctx context.Context, logContext, dsn string, maxConns, maxId
dsn = strings.TrimPrefix(dsn, "mysql://")
case "clickhouse":
dsn = "tcp://" + strings.TrimPrefix(dsn, "clickhouse://")
case "snowflake":
dsn = strings.TrimPrefix(dsn, "snowflake://")
}

// Open the DB handle in a separate goroutine so we can terminate early if the context closes.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading