|
|
|
@ -34,10 +34,10 @@ func TestSqlxMetric(t *testing.T) {
|
|
|
|
|
s, err := io.ReadAll(resp.Body)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
content := string(s)
|
|
|
|
|
assert.Contains(t, content, "mysql_client_requests_duration_ms_sum{command=\"test-cmd\"} 8\n")
|
|
|
|
|
assert.Contains(t, content, "mysql_client_requests_duration_ms_count{command=\"test-cmd\"} 1\n")
|
|
|
|
|
assert.Contains(t, content, "mysql_client_requests_error_total{command=\"test-cmd\",error=\"internal-error\"} 1\n")
|
|
|
|
|
assert.Contains(t, content, "mysql_client_requests_slow_total{command=\"test-cmd\"} 1\n")
|
|
|
|
|
assert.Contains(t, content, "sql_client_requests_duration_ms_sum{command=\"test-cmd\"} 8\n")
|
|
|
|
|
assert.Contains(t, content, "sql_client_requests_duration_ms_count{command=\"test-cmd\"} 1\n")
|
|
|
|
|
assert.Contains(t, content, "sql_client_requests_error_total{command=\"test-cmd\",error=\"internal-error\"} 1\n")
|
|
|
|
|
assert.Contains(t, content, "sql_client_requests_slow_total{command=\"test-cmd\"} 1\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMetricCollector(t *testing.T) {
|
|
|
|
@ -95,51 +95,51 @@ func TestMetricCollector(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
val := `
|
|
|
|
|
# HELP mysql_client_idle_connections The number of idle connections.
|
|
|
|
|
# TYPE mysql_client_idle_connections gauge
|
|
|
|
|
mysql_client_idle_connections{db_name="db-1",hash="hash-1"} 4
|
|
|
|
|
mysql_client_idle_connections{db_name="db-1",hash="hash-2"} 40
|
|
|
|
|
mysql_client_idle_connections{db_name="db-2",hash="hash-2"} 400
|
|
|
|
|
# HELP mysql_client_in_use_connections The number of connections currently in use.
|
|
|
|
|
# TYPE mysql_client_in_use_connections gauge
|
|
|
|
|
mysql_client_in_use_connections{db_name="db-1",hash="hash-1"} 3
|
|
|
|
|
mysql_client_in_use_connections{db_name="db-1",hash="hash-2"} 30
|
|
|
|
|
mysql_client_in_use_connections{db_name="db-2",hash="hash-2"} 300
|
|
|
|
|
# HELP mysql_client_max_idle_closed_total The total number of connections closed due to SetMaxIdleConns.
|
|
|
|
|
# TYPE mysql_client_max_idle_closed_total counter
|
|
|
|
|
mysql_client_max_idle_closed_total{db_name="db-1",hash="hash-1"} 7
|
|
|
|
|
mysql_client_max_idle_closed_total{db_name="db-1",hash="hash-2"} 70
|
|
|
|
|
mysql_client_max_idle_closed_total{db_name="db-2",hash="hash-2"} 700
|
|
|
|
|
# HELP mysql_client_max_idle_time_closed_total The total number of connections closed due to SetConnMaxIdleTime.
|
|
|
|
|
# TYPE mysql_client_max_idle_time_closed_total counter
|
|
|
|
|
mysql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-1"} 8
|
|
|
|
|
mysql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-2"} 80
|
|
|
|
|
mysql_client_max_idle_time_closed_total{db_name="db-2",hash="hash-2"} 800
|
|
|
|
|
# HELP mysql_client_max_lifetime_closed_total The total number of connections closed due to SetConnMaxLifetime.
|
|
|
|
|
# TYPE mysql_client_max_lifetime_closed_total counter
|
|
|
|
|
mysql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-1"} 9
|
|
|
|
|
mysql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-2"} 90
|
|
|
|
|
mysql_client_max_lifetime_closed_total{db_name="db-2",hash="hash-2"} 900
|
|
|
|
|
# HELP mysql_client_max_open_connections Maximum number of open connections to the database.
|
|
|
|
|
# TYPE mysql_client_max_open_connections gauge
|
|
|
|
|
mysql_client_max_open_connections{db_name="db-1",hash="hash-1"} 1
|
|
|
|
|
mysql_client_max_open_connections{db_name="db-1",hash="hash-2"} 10
|
|
|
|
|
mysql_client_max_open_connections{db_name="db-2",hash="hash-2"} 100
|
|
|
|
|
# HELP mysql_client_open_connections The number of established connections both in use and idle.
|
|
|
|
|
# TYPE mysql_client_open_connections gauge
|
|
|
|
|
mysql_client_open_connections{db_name="db-1",hash="hash-1"} 2
|
|
|
|
|
mysql_client_open_connections{db_name="db-1",hash="hash-2"} 20
|
|
|
|
|
mysql_client_open_connections{db_name="db-2",hash="hash-2"} 200
|
|
|
|
|
# HELP mysql_client_wait_count_total The total number of connections waited for.
|
|
|
|
|
# TYPE mysql_client_wait_count_total counter
|
|
|
|
|
mysql_client_wait_count_total{db_name="db-1",hash="hash-1"} 5
|
|
|
|
|
mysql_client_wait_count_total{db_name="db-1",hash="hash-2"} 50
|
|
|
|
|
mysql_client_wait_count_total{db_name="db-2",hash="hash-2"} 500
|
|
|
|
|
# HELP mysql_client_wait_duration_seconds_total The total time blocked waiting for a new connection.
|
|
|
|
|
# TYPE mysql_client_wait_duration_seconds_total counter
|
|
|
|
|
mysql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-1"} 6
|
|
|
|
|
mysql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-2"} 60
|
|
|
|
|
mysql_client_wait_duration_seconds_total{db_name="db-2",hash="hash-2"} 600
|
|
|
|
|
# HELP sql_client_idle_connections The number of idle connections.
|
|
|
|
|
# TYPE sql_client_idle_connections gauge
|
|
|
|
|
sql_client_idle_connections{db_name="db-1",hash="hash-1"} 4
|
|
|
|
|
sql_client_idle_connections{db_name="db-1",hash="hash-2"} 40
|
|
|
|
|
sql_client_idle_connections{db_name="db-2",hash="hash-2"} 400
|
|
|
|
|
# HELP sql_client_in_use_connections The number of connections currently in use.
|
|
|
|
|
# TYPE sql_client_in_use_connections gauge
|
|
|
|
|
sql_client_in_use_connections{db_name="db-1",hash="hash-1"} 3
|
|
|
|
|
sql_client_in_use_connections{db_name="db-1",hash="hash-2"} 30
|
|
|
|
|
sql_client_in_use_connections{db_name="db-2",hash="hash-2"} 300
|
|
|
|
|
# HELP sql_client_max_idle_closed_total The total number of connections closed due to SetMaxIdleConns.
|
|
|
|
|
# TYPE sql_client_max_idle_closed_total counter
|
|
|
|
|
sql_client_max_idle_closed_total{db_name="db-1",hash="hash-1"} 7
|
|
|
|
|
sql_client_max_idle_closed_total{db_name="db-1",hash="hash-2"} 70
|
|
|
|
|
sql_client_max_idle_closed_total{db_name="db-2",hash="hash-2"} 700
|
|
|
|
|
# HELP sql_client_max_idle_time_closed_total The total number of connections closed due to SetConnMaxIdleTime.
|
|
|
|
|
# TYPE sql_client_max_idle_time_closed_total counter
|
|
|
|
|
sql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-1"} 8
|
|
|
|
|
sql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-2"} 80
|
|
|
|
|
sql_client_max_idle_time_closed_total{db_name="db-2",hash="hash-2"} 800
|
|
|
|
|
# HELP sql_client_max_lifetime_closed_total The total number of connections closed due to SetConnMaxLifetime.
|
|
|
|
|
# TYPE sql_client_max_lifetime_closed_total counter
|
|
|
|
|
sql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-1"} 9
|
|
|
|
|
sql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-2"} 90
|
|
|
|
|
sql_client_max_lifetime_closed_total{db_name="db-2",hash="hash-2"} 900
|
|
|
|
|
# HELP sql_client_max_open_connections Maximum number of open connections to the database.
|
|
|
|
|
# TYPE sql_client_max_open_connections gauge
|
|
|
|
|
sql_client_max_open_connections{db_name="db-1",hash="hash-1"} 1
|
|
|
|
|
sql_client_max_open_connections{db_name="db-1",hash="hash-2"} 10
|
|
|
|
|
sql_client_max_open_connections{db_name="db-2",hash="hash-2"} 100
|
|
|
|
|
# HELP sql_client_open_connections The number of established connections both in use and idle.
|
|
|
|
|
# TYPE sql_client_open_connections gauge
|
|
|
|
|
sql_client_open_connections{db_name="db-1",hash="hash-1"} 2
|
|
|
|
|
sql_client_open_connections{db_name="db-1",hash="hash-2"} 20
|
|
|
|
|
sql_client_open_connections{db_name="db-2",hash="hash-2"} 200
|
|
|
|
|
# HELP sql_client_wait_count_total The total number of connections waited for.
|
|
|
|
|
# TYPE sql_client_wait_count_total counter
|
|
|
|
|
sql_client_wait_count_total{db_name="db-1",hash="hash-1"} 5
|
|
|
|
|
sql_client_wait_count_total{db_name="db-1",hash="hash-2"} 50
|
|
|
|
|
sql_client_wait_count_total{db_name="db-2",hash="hash-2"} 500
|
|
|
|
|
# HELP sql_client_wait_duration_seconds_total The total time blocked waiting for a new connection.
|
|
|
|
|
# TYPE sql_client_wait_duration_seconds_total counter
|
|
|
|
|
sql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-1"} 6
|
|
|
|
|
sql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-2"} 60
|
|
|
|
|
sql_client_wait_duration_seconds_total{db_name="db-2",hash="hash-2"} 600
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
err := testutil.CollectAndCompare(c, strings.NewReader(val))
|
|
|
|
|