PostgreSQL loadable plugin
Source
paramTLSConnect = metric.NewSessionOnlyParam(tlsConnectParam, "DB connection encryption type.").WithDefault("")
/*
** Zabbix
** Copyright 2001-2024 Zabbix SIA
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**/
package plugin
import (
"context"
"errors"
"fmt"
"regexp"
"strings"
"git.zabbix.com/ap/plugin-support/metric"
"git.zabbix.com/ap/plugin-support/plugin"
"git.zabbix.com/ap/plugin-support/uri"
)
const (
keyArchiveSize = "pgsql.archive"
keyAutovacuum = "pgsql.autovacuum.count"
keyBgwriter = "pgsql.bgwriter"
keyCache = "pgsql.cache.hit"
keyConnections = "pgsql.connections"
keyCustomQuery = "pgsql.custom.query"
keyDBStat = "pgsql.dbstat"
keyDBStatSum = "pgsql.dbstat.sum"
keyDatabaseAge = "pgsql.db.age"
keyDatabasesBloating = "pgsql.db.bloating_tables"
keyDatabasesDiscovery = "pgsql.db.discovery"
keyDatabaseSize = "pgsql.db.size"
keyLocks = "pgsql.locks"
keyOldestXid = "pgsql.oldest.xid"
keyPing = "pgsql.ping"
keyQueries = "pgsql.queries"
keyReplicationCount = "pgsql.replication.count"
keyReplicationLagB = "pgsql.replication.lag.b"
keyReplicationLagSec = "pgsql.replication.lag.sec"
keyReplicationProcessInfo = "pgsql.replication.process"
keyReplicationProcessNameDiscovery = "pgsql.replication.process.discovery"
keyReplicationRecoveryRole = "pgsql.replication.recovery_role"
keyReplicationStatus = "pgsql.replication.status"
keyUptime = "pgsql.uptime"
keyVersion = "pgsql.version"
keyWal = "pgsql.wal.stat"
uriParam = "URI"
tcpParam = "tcp"
userParam = "User"
databaseParam = "Database"
passwordParam = "Password"
tlsConnectParam = "TLSConnect"
tlsCAParam = "TLSCAFile"
tlsCertParam = "TLSCertFile"
tlsKeyParam = "TLSKeyFile"
cacheModeParam = "CacheMode"
)
var uriDefaults = &uri.Defaults{Scheme: "tcp", Port: "5432"}
var (
minDBNameLen = 1
maxDBNameLen = 63
maxPassLen = 512
)
var reSocketPath = regexp.MustCompile(`^.*\.s\.PGSQL\.\d{1,5}$`)
var (
paramURI = metric.NewConnParam(uriParam, "URI to connect or session name.").
WithDefault(uriDefaults.Scheme + "://localhost:" + uriDefaults.Port).WithSession().
WithValidator(PostgresURIValidator{
Defaults: uriDefaults,
AllowedSchemes: []string{tcpParam, "postgresql", "unix"},
})
paramUsername = metric.NewConnParam(userParam, "PostgreSQL user.").WithDefault("postgres")
paramPassword = metric.NewConnParam(passwordParam, "User's password.").
WithDefault("").