Skip to content

Commit

Permalink
Switch to kingpin
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett committed Sep 3, 2017
1 parent 8285b29 commit 6bb187c
Show file tree
Hide file tree
Showing 48 changed files with 9,892 additions and 183 deletions.
6 changes: 4 additions & 2 deletions collector/info_schema_innodb_metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package collector

import (
"flag"
"testing"

"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/log"
"github.com/smartystreets/goconvey/convey"
"gopkg.in/DATA-DOG/go-sqlmock.v1"
"gopkg.in/alecthomas/kingpin.v2"
)

func TestScrapeInnodbMetrics(t *testing.T) {
// Suppress a log messages
err := flag.Set("log.level", "fatal")
log.AddFlags(kingpin.CommandLine)
_, err := kingpin.CommandLine.Parse([]string{"--log.level", "fatal"})
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions collector/info_schema_processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package collector

import (
"database/sql"
"flag"
"fmt"
"strings"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

const infoSchemaProcesslistQuery = `
Expand All @@ -22,10 +22,10 @@ const infoSchemaProcesslistQuery = `

var (
// Tunable flags.
processlistMinTime = flag.Int(
"collect.info_schema.processlist.min_time", 0,
processlistMinTime = kingpin.Flag(
"collect.info_schema.processlist.min_time",
"Minimum time a thread must be in each state to be counted",
)
).Default("0").Int()
// Prometheus descriptors.
processlistCountDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, informationSchema, "threads"),
Expand Down
8 changes: 4 additions & 4 deletions collector/info_schema_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package collector

import (
"database/sql"
"flag"
"fmt"
"strings"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

const (
Expand Down Expand Up @@ -37,10 +37,10 @@ const (
)

var (
tableSchemaDatabases = flag.String(
"collect.info_schema.tables.databases", "*",
tableSchemaDatabases = kingpin.Flag(
"collect.info_schema.tables.databases",
"The list of databases to collect table stats for, or '*' for all",
)
).Default("*").String()
infoSchemaTablesVersionDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, informationSchema, "table_version"),
"The version number of the table's .frm file",
Expand Down
20 changes: 10 additions & 10 deletions collector/perf_schema_events_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package collector

import (
"database/sql"
"flag"
"fmt"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

const perfEventsStatementsQuery = `
Expand Down Expand Up @@ -56,18 +56,18 @@ const perfEventsStatementsQuery = `

// Tuning flags.
var (
perfEventsStatementsLimit = flag.Int(
"collect.perf_schema.eventsstatements.limit", 250,
perfEventsStatementsLimit = kingpin.Flag(
"collect.perf_schema.eventsstatements.limit",
"Limit the number of events statements digests by response time",
)
perfEventsStatementsTimeLimit = flag.Int(
"collect.perf_schema.eventsstatements.timelimit", 86400,
).Default("250").Int()
perfEventsStatementsTimeLimit = kingpin.Flag(
"collect.perf_schema.eventsstatements.timelimit",
"Limit how old the 'last_seen' events statements can be, in seconds",
)
perfEventsStatementsDigestTextLimit = flag.Int(
"collect.perf_schema.eventsstatements.digest_text_limit", 120,
).Default("86400").Int()
perfEventsStatementsDigestTextLimit = kingpin.Flag(
"collect.perf_schema.eventsstatements.digest_text_limit",
"Maximum length of the normalized statement text",
)
).Default("120").Int()
)

// Metric descriptors.
Expand Down
14 changes: 7 additions & 7 deletions collector/perf_schema_file_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"database/sql"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"

"flag"
"path"
"path/filepath"
)
Expand All @@ -23,15 +23,15 @@ const perfFileInstancesQuery = `

// Metric descriptors.
var (
performanceSchemaFileInstancesFilter = flag.String(
"collect.perf_schema.file_instances.filter", ".*",
performanceSchemaFileInstancesFilter = kingpin.Flag(
"collect.perf_schema.file_instances.filter",
"RegEx file_name filter for performance_schema.file_summary_by_instance",
)
).Default(".*").String()

performanceSchemaFileInstancesRemovePrefix = flag.Bool(
"collect.perf_schema.file_instances.remove_prefix", false,
performanceSchemaFileInstancesRemovePrefix = kingpin.Flag(
"collect.perf_schema.file_instances.remove_prefix",
"Remove path prefix in performance_schema.file_summary_by_instance",
)
).Default("false").Bool()

performanceSchemaFileInstancesBytesDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "file_instances_bytes"),
Expand Down
4 changes: 2 additions & 2 deletions collector/perf_schema_file_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package collector
import (
"testing"

"flag"
"fmt"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/smartystreets/goconvey/convey"
"gopkg.in/DATA-DOG/go-sqlmock.v1"
"gopkg.in/alecthomas/kingpin.v2"
)

func TestScrapePerfFileInstances(t *testing.T) {
err := flag.Set("collect.perf_schema.file_instances.filter", "")
_, err := kingpin.CommandLine.Parse([]string{"--collect.perf_schema.file_instances.filter", ""})
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 6bb187c

Please sign in to comment.