2015-05-18 17:46:44 +00:00
|
|
|
package postgresql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/influxdb/tivan/testutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
|
|
|
p := &Postgresql{
|
|
|
|
Servers: []*Server{
|
|
|
|
{
|
|
|
|
Address: "sslmode=disable",
|
|
|
|
Databases: []string{"postgres"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
err := p.Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
intMetrics := []string{
|
2015-05-18 19:15:15 +00:00
|
|
|
"xact_commit",
|
|
|
|
"xact_rollback",
|
|
|
|
"blks_read",
|
|
|
|
"blks_hit",
|
|
|
|
"tup_returned",
|
|
|
|
"tup_fetched",
|
|
|
|
"tup_inserted",
|
|
|
|
"tup_updated",
|
|
|
|
"tup_deleted",
|
|
|
|
"conflicts",
|
|
|
|
"temp_files",
|
|
|
|
"temp_bytes",
|
|
|
|
"deadlocks",
|
2015-05-18 17:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
floatMetrics := []string{
|
2015-05-18 19:15:15 +00:00
|
|
|
"blk_read_time",
|
|
|
|
"blk_write_time",
|
2015-05-18 17:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, metric := range intMetrics {
|
|
|
|
assert.True(t, acc.HasIntValue(metric))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, metric := range floatMetrics {
|
|
|
|
assert.True(t, acc.HasFloatValue(metric))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
|
|
|
|
p := &Postgresql{
|
|
|
|
Servers: []*Server{
|
|
|
|
{
|
|
|
|
Address: "sslmode=disable",
|
|
|
|
Databases: []string{"postgres"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
err := p.Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2015-05-18 19:15:15 +00:00
|
|
|
point, ok := acc.Get("xact_commit")
|
2015-05-18 17:46:44 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
assert.Equal(t, "postgres", point.Tags["db"])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostgresqlDefaultsToAllDatabases(t *testing.T) {
|
|
|
|
p := &Postgresql{
|
|
|
|
Servers: []*Server{
|
|
|
|
{
|
|
|
|
Address: "sslmode=disable",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
err := p.Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var found bool
|
|
|
|
|
|
|
|
for _, pnt := range acc.Points {
|
2015-05-18 19:15:15 +00:00
|
|
|
if pnt.Name == "xact_commit" {
|
2015-05-18 17:46:44 +00:00
|
|
|
if pnt.Tags["db"] == "postgres" {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, found)
|
|
|
|
}
|