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

added TLS module of prometheus community #110

Open
wants to merge 1 commit 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,10 @@ Prometheus scrapes. This is partly a philosophical issue, but practical issues a
jitter; duplicate data points; or collected but not scraped data points. The control they provide over which labels get
applied is limited, and the base label set spammy. And finally, configurations are not easily reused without
copy-pasting and editing across jobs and instances.

## TLS and basic authentication

SQL Exporter supports TLS and basic authentication. This enables better control of the various HTTP endpoints.

To use TLS and/or basic authentication, you need to pass a configuration file using the `--web.config.file` parameter. The format of the file is described
[in the exporter-toolkit repository](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md).
20 changes: 17 additions & 3 deletions cmd/sql_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import (
"os"
"runtime"

_ "net/http/pprof"

"github.com/free/sql_exporter"
log "github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
_ "net/http/pprof"

//"github.com/prometheus/common/log"
"github.com/prometheus/common/promlog"
"github.com/prometheus/exporter-toolkit/web"
)

var (
showVersion = flag.Bool("version", false, "Print version information.")
listenAddress = flag.String("web.listen-address", ":9399", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("web.metrics-path", "/metrics", "Path under which to expose metrics.")
configFile = flag.String("config.file", "sql_exporter.yml", "SQL Exporter configuration file name.")
webcfgFile = flag.String("web.config", "", "Path to config yaml file that can enable TLS or authentication.")
)

func init() {
Expand Down Expand Up @@ -64,8 +70,16 @@ func main() {
// Expose exporter metrics separately, for debugging purposes.
http.Handle("/sql_exporter_metrics", promhttp.Handler())

log.Infof("Listening on %s", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
promlogConfig := &promlog.Config{}
logger := promlog.New(promlogConfig)
log.Infoln("Listening on", *listenAddress)
server := &http.Server{Addr: *listenAddress}
if err := web.Listen(server, *webcfgFile, logger); err != nil {
log.Fatal(err)
}

//log.Infof("Listening on %s", *listenAddress)
//log.Fatal(http.ListenAndServe(*listenAddress, nil))
}

// LogFunc is an adapter to allow the use of any function as a promhttp.Logger. If f is a function, LogFunc(f) is a
Expand Down
2 changes: 1 addition & 1 deletion exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"sync"

"github.com/free/sql_exporter/config"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
)

var dsnOverride = flag.String("config.data-source-name", "", "Data source name to override the value in the configuration file with.")
Expand Down
38 changes: 38 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module github.com/free/sql_exporter

go 1.17

require (
github.com/ClickHouse/clickhouse-go v1.5.1
github.com/denisenkom/go-mssqldb v0.11.0
github.com/go-sql-driver/mysql v1.6.0
github.com/golang/glog v1.0.0
github.com/lib/pq v1.10.4
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.32.1
github.com/prometheus/exporter-toolkit v0.7.1
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
github.com/go-kit/log v0.1.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/appengine v1.6.6 // indirect
)
Loading