Skip to content
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
6 changes: 3 additions & 3 deletions collector/binlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func TestScrapeBinlogSize(t *testing.T) {
}()

counterExpected := []MetricResult{
{labels: labelMap{}, value: 574942, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 3, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 444, metricType: dto.MetricType_GAUGE},
{name: "mysql_binlog_size_bytes", help: "Combined size of all registered binlog files.", labels: labelMap{}, value: 574942, metricType: dto.MetricType_GAUGE},
{name: "mysql_binlog_files", help: "Number of registered binlog files.", labels: labelMap{}, value: 3, metricType: dto.MetricType_GAUGE},
{name: "mysql_binlog_file_number", help: "The last binlog file number.", labels: labelMap{}, value: 444, metricType: dto.MetricType_GAUGE},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range counterExpected {
Expand Down
19 changes: 14 additions & 5 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,44 @@
package collector

import (
"reflect"
"strings"

"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)

type labelMap map[string]string

type MetricResult struct {
name string
help string
labels labelMap
value float64
metricType dto.MetricType
}

func readMetric(m prometheus.Metric) MetricResult {

a := m.Desc()
pb := &dto.Metric{}
m.Write(pb)
labels := make(labelMap, len(pb.Label))

name := reflect.ValueOf(a).Elem().FieldByName("fqName").String()
help := reflect.ValueOf(a).Elem().FieldByName("help").String()
labels := labelMap{}

for _, v := range pb.Label {
labels[v.GetName()] = v.GetValue()
}

if pb.Gauge != nil {
return MetricResult{labels: labels, value: pb.GetGauge().GetValue(), metricType: dto.MetricType_GAUGE}
return MetricResult{name: name, help: help, labels: labels, value: pb.GetGauge().GetValue(), metricType: dto.MetricType_GAUGE}
}
if pb.Counter != nil {
return MetricResult{labels: labels, value: pb.GetCounter().GetValue(), metricType: dto.MetricType_COUNTER}
return MetricResult{name: name, help: help, labels: labels, value: pb.GetCounter().GetValue(), metricType: dto.MetricType_COUNTER}
}
if pb.Untyped != nil {
return MetricResult{labels: labels, value: pb.GetUntyped().GetValue(), metricType: dto.MetricType_UNTYPED}
return MetricResult{name: name, help: help, labels: labels, value: pb.GetUntyped().GetValue(), metricType: dto.MetricType_UNTYPED}
}
panic("Unsupported metric type")
}
Expand Down
6 changes: 3 additions & 3 deletions collector/engine_innodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ END OF INNODB MONITOR OUTPUT
}()

metricsExpected := []MetricResult{
{labels: labelMap{}, value: 661, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 10, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 15, metricType: dto.MetricType_GAUGE},
{name: "mysql_engine_innodb_queries_inside_innodb", help: "Queries inside InnoDB.", labels: labelMap{}, value: 661, metricType: dto.MetricType_GAUGE},
{name: "mysql_engine_innodb_queries_in_queue", help: "Queries in queue.", labels: labelMap{}, value: 10, metricType: dto.MetricType_GAUGE},
{name: "mysql_engine_innodb_read_views_open_inside_innodb", help: "Read views open inside InnoDB.", labels: labelMap{}, value: 15, metricType: dto.MetricType_GAUGE},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range metricsExpected {
Expand Down
6 changes: 3 additions & 3 deletions collector/engine_tokudb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TestScrapeEngineTokudbStatus(t *testing.T) {
}()

metricsExpected := []MetricResult{
{labels: labelMap{}, value: 1, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 45316247, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 9115.904484, metricType: dto.MetricType_UNTYPED},
{name: "mysql_engine_tokudb_indexer_number_of_calls_to_indexer_build_succeeded", help: "Generic metric from SHOW ENGINE TOKUDB STATUS.", labels: labelMap{}, value: 1, metricType: dto.MetricType_UNTYPED},
{name: "mysql_engine_tokudb_ft_promotion_stopped_anyway_after_locking_the_child", help: "Generic metric from SHOW ENGINE TOKUDB STATUS.", labels: labelMap{}, value: 45316247, metricType: dto.MetricType_UNTYPED},
{name: "mysql_engine_tokudb_locktree_time_spent_ending_the_sto_early_seconds", help: "Generic metric from SHOW ENGINE TOKUDB STATUS.", labels: labelMap{}, value: 9115.904484, metricType: dto.MetricType_UNTYPED},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range metricsExpected {
Expand Down
10 changes: 5 additions & 5 deletions collector/global_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ func (ScrapeGlobalStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prom
}

evsMap := []evsValue{
evsValue{name: "min_seconds", value: 0, index: 0, help: "PXC/Galera group communication latency. Min value."},
evsValue{name: "avg_seconds", value: 0, index: 1, help: "PXC/Galera group communication latency. Avg value."},
evsValue{name: "max_seconds", value: 0, index: 2, help: "PXC/Galera group communication latency. Max value."},
evsValue{name: "stdev", value: 0, index: 3, help: "PXC/Galera group communication latency. Standard Deviation."},
evsValue{name: "sample_size", value: 0, index: 4, help: "PXC/Galera group communication latency. Sample Size."},
{name: "min_seconds", value: 0, index: 0, help: "PXC/Galera group communication latency. Min value."},
{name: "avg_seconds", value: 0, index: 1, help: "PXC/Galera group communication latency. Avg value."},
{name: "max_seconds", value: 0, index: 2, help: "PXC/Galera group communication latency. Max value."},
{name: "stdev", value: 0, index: 3, help: "PXC/Galera group communication latency. Standard Deviation."},
{name: "sample_size", value: 0, index: 4, help: "PXC/Galera group communication latency. Sample Size."},
}

evsParsingSuccess := true
Expand Down
52 changes: 26 additions & 26 deletions collector/global_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,33 @@ func TestScrapeGlobalStatus(t *testing.T) {
}()

counterExpected := []MetricResult{
{labels: labelMap{"command": "alter_db"}, value: 1, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"command": "show_status"}, value: 2, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"command": "select"}, value: 3, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"error": "internal"}, value: 4, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"handler": "commit"}, value: 5, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"state": "data"}, value: 6, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"operation": "flushed"}, value: 7, metricType: dto.MetricType_COUNTER},
{labels: labelMap{}, value: 7, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"state": "free"}, value: 8, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"state": "misc"}, value: 9, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"state": "old"}, value: 10, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_status_commands_total", help: "Total number of executed MySQL commands.", labels: labelMap{"command": "alter_db"}, value: 1, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_commands_total", help: "Total number of executed MySQL commands.", labels: labelMap{"command": "show_status"}, value: 2, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_commands_total", help: "Total number of executed MySQL commands.", labels: labelMap{"command": "select"}, value: 3, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_connection_errors_total", help: "Total number of MySQL connection errors.", labels: labelMap{"error": "internal"}, value: 4, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_handlers_total", help: "Total number of executed MySQL handlers.", labels: labelMap{"handler": "commit"}, value: 5, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_buffer_pool_pages", help: "Innodb buffer pool pages by state.", labels: labelMap{"state": "data"}, value: 6, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_status_buffer_pool_page_changes_total", help: "Innodb buffer pool page state changes.", labels: labelMap{"operation": "flushed"}, value: 7, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_buffer_pool_dirty_pages", help: "Innodb buffer pool dirty pages.", labels: labelMap{}, value: 7, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_status_buffer_pool_pages", help: "Innodb buffer pool pages by state.", labels: labelMap{"state": "free"}, value: 8, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_status_buffer_pool_pages", help: "Innodb buffer pool pages by state.", labels: labelMap{"state": "misc"}, value: 9, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_status_buffer_pool_pages", help: "Innodb buffer pool pages by state.", labels: labelMap{"state": "old"}, value: 10, metricType: dto.MetricType_GAUGE},
//{labels: labelMap{"state": "total_pages"}, value: 11, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"operation": "lru_flushed"}, value: 13, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"operation": "made_not_young"}, value: 14, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"operation": "made_young"}, value: 15, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"operation": "read"}, value: 8, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"instrumentation": "users_lost"}, value: 9, metricType: dto.MetricType_COUNTER},
{labels: labelMap{}, value: 0, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 10, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 11, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{}, value: 1, metricType: dto.MetricType_UNTYPED},
{labels: labelMap{"wsrep_local_state_uuid": "6c06e583-686f-11e6-b9e3-8336ad58138c", "wsrep_cluster_state_uuid": "6c06e583-686f-11e6-b9e3-8336ad58138c", "wsrep_provider_version": "3.16(r5c765eb)"}, value: 1, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 0.000227664, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 0.00034135, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 0.000544298, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 6.03708e-05, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 212, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_status_buffer_pool_page_changes_total", help: "Innodb buffer pool page state changes.", labels: labelMap{"operation": "lru_flushed"}, value: 13, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_buffer_pool_page_changes_total", help: "Innodb buffer pool page state changes.", labels: labelMap{"operation": "made_not_young"}, value: 14, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_buffer_pool_page_changes_total", help: "Innodb buffer pool page state changes.", labels: labelMap{"operation": "made_young"}, value: 15, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_innodb_row_ops_total", help: "Total number of MySQL InnoDB row operations.", labels: labelMap{"operation": "read"}, value: 8, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_performance_schema_lost_total", help: "Total number of MySQL instrumentations that could not be loaded or created due to memory constraints.", labels: labelMap{"instrumentation": "users_lost"}, value: 9, metricType: dto.MetricType_COUNTER},
{name: "mysql_global_status_slave_running", help: "Generic metric from SHOW GLOBAL STATUS.", labels: labelMap{}, value: 0, metricType: dto.MetricType_UNTYPED},
{name: "mysql_global_status_uptime", help: "Generic metric from SHOW GLOBAL STATUS.", labels: labelMap{}, value: 10, metricType: dto.MetricType_UNTYPED},
{name: "mysql_global_status_validate_password_dictionary_file_words_count", help: "Generic metric from SHOW GLOBAL STATUS.", labels: labelMap{}, value: 11, metricType: dto.MetricType_UNTYPED},
{name: "mysql_global_status_wsrep_cluster_status", help: "Generic metric from SHOW GLOBAL STATUS.", labels: labelMap{}, value: 1, metricType: dto.MetricType_UNTYPED},
{name: "mysql_galera_status_info", help: "PXC/Galera status information.", labels: labelMap{"wsrep_local_state_uuid": "6c06e583-686f-11e6-b9e3-8336ad58138c", "wsrep_cluster_state_uuid": "6c06e583-686f-11e6-b9e3-8336ad58138c", "wsrep_provider_version": "3.16(r5c765eb)"}, value: 1, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_evs_repl_latency_min_seconds", help: "PXC/Galera group communication latency. Min value.", labels: labelMap{}, value: 0.000227664, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_evs_repl_latency_avg_seconds", help: "PXC/Galera group communication latency. Avg value.", labels: labelMap{}, value: 0.00034135, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_evs_repl_latency_max_seconds", help: "PXC/Galera group communication latency. Max value.", labels: labelMap{}, value: 0.000544298, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_evs_repl_latency_stdev", help: "PXC/Galera group communication latency. Standard Deviation.", labels: labelMap{}, value: 6.03708e-05, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_evs_repl_latency_sample_size", help: "PXC/Galera group communication latency. Sample Size.", labels: labelMap{}, value: 212, metricType: dto.MetricType_GAUGE},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range counterExpected {
Expand Down
20 changes: 10 additions & 10 deletions collector/global_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ func TestScrapeGlobalVariables(t *testing.T) {
}()

counterExpected := []MetricResult{
{labels: labelMap{}, value: 28800, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 0, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 4096, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 16777216, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 0, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 1, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 2, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"innodb_version": "5.6.30-76.3", "version": "5.6.30-76.3-56", "version_comment": "Percona XtraDB Cluster..."}, value: 1, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"wsrep_cluster_name": "supercluster"}, value: 1, metricType: dto.MetricType_GAUGE},
{labels: labelMap{}, value: 134217728, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_wait_timeout", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 28800, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_userstat", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 0, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_transaction_prealloc_size", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 4096, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_tmp_table_size", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 16777216, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_sync_binlog", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 0, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_sync_frm", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 1, metricType: dto.MetricType_GAUGE},
{name: "mysql_global_variables_slow_launch_time", help: "Generic gauge metric from SHOW GLOBAL VARIABLES.", labels: labelMap{}, value: 2, metricType: dto.MetricType_GAUGE},
{name: "mysql_version_info", help: "MySQL version and distribution.", labels: labelMap{"innodb_version": "5.6.30-76.3", "version": "5.6.30-76.3-56", "version_comment": "Percona XtraDB Cluster..."}, value: 1, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_variables_info", help: "PXC/Galera variables information.", labels: labelMap{"wsrep_cluster_name": "supercluster"}, value: 1, metricType: dto.MetricType_GAUGE},
{name: "mysql_galera_gcache_size_bytes", help: "PXC/Galera gcache size.", labels: labelMap{}, value: 134217728, metricType: dto.MetricType_GAUGE},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range counterExpected {
Expand Down
4 changes: 2 additions & 2 deletions collector/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func TestScrapeHeartbeat(t *testing.T) {
}()

counterExpected := []MetricResult{
{labels: labelMap{"server_id": "1"}, value: 1487598113.448042, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"server_id": "1"}, value: 1487597613.00132, metricType: dto.MetricType_GAUGE},
{name: "mysql_heartbeat_now_timestamp_seconds", help: "Timestamp of the current server.", labels: labelMap{"server_id": "1"}, value: 1487598113.448042, metricType: dto.MetricType_GAUGE},
{name: "mysql_heartbeat_stored_timestamp_seconds", help: "Timestamp stored in the heartbeat table.", labels: labelMap{"server_id": "1"}, value: 1487597613.00132, metricType: dto.MetricType_GAUGE},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range counterExpected {
Expand Down
Loading