You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-11-23 23:02:58 +03:00
Use the pg_settings view to retrieve runtime variable
Adds all bool/integer/real runtime variables that can be retrieved ths way. Use the `pg_settings` view to retrieve runtime variables: https://www.postgresql.org/docs/current/static/view-pg-settings.html Replaces the use of `SHOW` to retrieve runtime variables. Only runtime variables with a `vartype` of `bool`, `real`, or `integer` are currently supported. Uses the `short_desc` field as a description. This commit deprecates the following metric names: ``` pg_runtime_variable_max_connections pg_runtime_variable_max_files_per_process pg_runtime_variable_max_function_args pg_runtime_variable_max_identifier_length pg_runtime_variable_max_index_keys pg_runtime_variable_max_locks_per_transaction pg_runtime_variable_max_pred_locks_per_transaction pg_runtime_variable_max_prepared_transactions pg_runtime_variable_max_standby_archive_delay_milliseconds pg_runtime_variable_max_standby_streaming_delay_milliseconds pg_runtime_variable_max_wal_senders ``` They are replaced by equivalent names under `pg_settings` with the exception of ``` pg_runtime_variable_max_standby_archive_delay_milliseconds pg_runtime_variable_max_standby_streaming_delay_milliseconds ``` which are replaced with ``` pg_settings_max_standby_archive_delay_seconds pg_settings_max_standby_streaming_delay_seconds ``` Adds approximately 195 new metrics, when considered across all supported PostgreSQL versions.
This commit is contained in:
committed by
Will Rouesnel
parent
994be318d4
commit
98ba566322
191
pg_setting_test.go
Normal file
191
pg_setting_test.go
Normal file
@@ -0,0 +1,191 @@
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
type PgSettingSuite struct{}
|
||||
|
||||
var _ = Suite(&PgSettingSuite{})
|
||||
|
||||
var fixtures = []fixture{
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "seconds_fixture_metric",
|
||||
setting: "5",
|
||||
unit: "s",
|
||||
shortDesc: "Foo foo foo",
|
||||
vartype: "integer",
|
||||
},
|
||||
n: normalised{
|
||||
val: 5,
|
||||
unit: "seconds",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_seconds_fixture_metric_seconds\", help: \"Foo foo foo [Units converted to seconds.]\", constLabels: {}, variableLabels: []}",
|
||||
v: 5,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "milliseconds_fixture_metric",
|
||||
setting: "5000",
|
||||
unit: "ms",
|
||||
shortDesc: "Foo foo foo",
|
||||
vartype: "integer",
|
||||
},
|
||||
n: normalised{
|
||||
val: 5,
|
||||
unit: "seconds",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_milliseconds_fixture_metric_seconds\", help: \"Foo foo foo [Units converted to seconds.]\", constLabels: {}, variableLabels: []}",
|
||||
v: 5,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "eight_kb_fixture_metric",
|
||||
setting: "17",
|
||||
unit: "8kB",
|
||||
shortDesc: "Foo foo foo",
|
||||
vartype: "integer",
|
||||
},
|
||||
n: normalised{
|
||||
val: 139264,
|
||||
unit: "bytes",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_eight_kb_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}",
|
||||
v: 139264,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "16_mb_real_fixture_metric",
|
||||
setting: "3.0",
|
||||
unit: "16MB",
|
||||
shortDesc: "Foo foo foo",
|
||||
vartype: "real",
|
||||
},
|
||||
n: normalised{
|
||||
val: 5.0331648e+07,
|
||||
unit: "bytes",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_16_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}",
|
||||
v: 5.0331648e+07,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "bool_on_fixture_metric",
|
||||
setting: "on",
|
||||
unit: "",
|
||||
shortDesc: "Foo foo foo",
|
||||
vartype: "bool",
|
||||
},
|
||||
n: normalised{
|
||||
val: 1,
|
||||
unit: "",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_bool_on_fixture_metric\", help: \"Foo foo foo\", constLabels: {}, variableLabels: []}",
|
||||
v: 1,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "bool_off_fixture_metric",
|
||||
setting: "off",
|
||||
unit: "",
|
||||
shortDesc: "Foo foo foo",
|
||||
vartype: "bool",
|
||||
},
|
||||
n: normalised{
|
||||
val: 0,
|
||||
unit: "",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_bool_off_fixture_metric\", help: \"Foo foo foo\", constLabels: {}, variableLabels: []}",
|
||||
v: 0,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "special_minus_one_value",
|
||||
setting: "-1",
|
||||
unit: "d",
|
||||
shortDesc: "foo foo foo",
|
||||
vartype: "integer",
|
||||
},
|
||||
n: normalised{
|
||||
val: -1,
|
||||
unit: "seconds",
|
||||
err: "",
|
||||
},
|
||||
d: "Desc{fqName: \"pg_settings_special_minus_one_value_seconds\", help: \"foo foo foo [Units converted to seconds.]\", constLabels: {}, variableLabels: []}",
|
||||
v: -1,
|
||||
},
|
||||
fixture{
|
||||
p: pgSetting{
|
||||
name: "unknown_unit",
|
||||
setting: "10",
|
||||
unit: "nonexistent",
|
||||
shortDesc: "foo foo foo",
|
||||
vartype: "integer",
|
||||
},
|
||||
n: normalised{
|
||||
val: 10,
|
||||
unit: "",
|
||||
err: `Unknown unit for runtime variable: "nonexistent"`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func (s *PgSettingSuite) TestNormaliseUnit(c *C) {
|
||||
for _, f := range fixtures {
|
||||
switch f.p.vartype {
|
||||
case "integer", "real":
|
||||
val, unit, err := f.p.normaliseUnit()
|
||||
|
||||
c.Check(val, Equals, f.n.val)
|
||||
c.Check(unit, Equals, f.n.unit)
|
||||
|
||||
if err == nil {
|
||||
c.Check("", Equals, f.n.err)
|
||||
} else {
|
||||
c.Check(err.Error(), Equals, f.n.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PgSettingSuite) TestMetric(c *C) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if r.(error).Error() != `Unknown unit for runtime variable: "nonexistent"` {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for _, f := range fixtures {
|
||||
d := &dto.Metric{}
|
||||
m := f.p.metric()
|
||||
m.Write(d)
|
||||
|
||||
c.Check(m.Desc().String(), Equals, f.d)
|
||||
c.Check(d.GetGauge().GetValue(), Equals, f.v)
|
||||
}
|
||||
}
|
||||
|
||||
type normalised struct {
|
||||
val float64
|
||||
unit string
|
||||
err string
|
||||
}
|
||||
|
||||
type fixture struct {
|
||||
p pgSetting
|
||||
n normalised
|
||||
d string
|
||||
v float64
|
||||
}
|
||||
Reference in New Issue
Block a user