2015-05-18 17:46:44 +00:00
|
|
|
package postgresql
|
|
|
|
|
|
|
|
import (
|
2015-07-07 01:18:31 +00:00
|
|
|
"fmt"
|
2015-05-18 17:46:44 +00:00
|
|
|
"testing"
|
|
|
|
|
2015-05-22 23:45:14 +00:00
|
|
|
"github.com/influxdb/telegraf/testutil"
|
2015-05-18 17:46:44 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
2015-08-04 20:52:44 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
|
|
|
|
2015-05-18 17:46:44 +00:00
|
|
|
p := &Postgresql{
|
|
|
|
Servers: []*Server{
|
|
|
|
{
|
2015-08-04 20:52:44 +00:00
|
|
|
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
|
|
|
|
testutil.GetLocalHost()),
|
2015-05-18 17:46:44 +00:00
|
|
|
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) {
|
2015-08-04 20:52:44 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
|
|
|
|
2015-05-18 17:46:44 +00:00
|
|
|
p := &Postgresql{
|
|
|
|
Servers: []*Server{
|
|
|
|
{
|
2015-08-04 20:52:44 +00:00
|
|
|
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
|
|
|
|
testutil.GetLocalHost()),
|
2015-05-18 17:46:44 +00:00
|
|
|
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) {
|
2015-08-04 20:52:44 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
|
|
|
|
2015-05-18 17:46:44 +00:00
|
|
|
p := &Postgresql{
|
|
|
|
Servers: []*Server{
|
|
|
|
{
|
2015-08-04 20:52:44 +00:00
|
|
|
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
|
|
|
|
testutil.GetLocalHost()),
|
2015-05-18 17:46:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
err := p.Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var found bool
|
|
|
|
|
|
|
|
for _, pnt := range acc.Points {
|
2015-06-20 12:32:32 +00:00
|
|
|
if pnt.Measurement == "xact_commit" {
|
2015-05-18 17:46:44 +00:00
|
|
|
if pnt.Tags["db"] == "postgres" {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, found)
|
|
|
|
}
|