-
Notifications
You must be signed in to change notification settings - Fork 1
/
stat_ssl.go
61 lines (54 loc) · 1.91 KB
/
stat_ssl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package pgstats
import (
"github.com/pkg/errors"
"github.com/vynaloze/pgstats/nullable"
)
// PgStatSslView represents content of pg_stat_ssl view
type PgStatSslView []PgStatSslRow
// PgStatSslRow represents schema of pg_stat_ssl view
type PgStatSslRow struct {
// Process ID of a backend or WAL sender process
Pid int64 `json:"pid"`
// True if SSL is used on this connection
Ssl bool `json:"ssl"`
// Version of SSL in use, or NULL if SSL is not in use on this connection
Version nullable.String `json:"version"`
// Name of SSL cipher in use, or NULL if SSL is not in use on this connection
Cipher nullable.String `json:"cipher"`
// Number of bits in the encryption algorithm used, or NULL if SSL is not used on this connection
Bits nullable.Int64 `json:"bits"`
// True if SSL compression is in use, false if not, or NULL if SSL is not in use on this connection
Compression nullable.Bool `json:"compression"`
// Distinguished Name (DN) field from the client certificate used,
// or NULL if no client certificate was supplied or if SSL is not in use on this connection.
// This field is truncated if the DN field is longer than NAMEDATALEN (64 characters in a standard build)
Clientdn nullable.String `json:"clientdn"`
}
func (s *PgStats) fetchSsl() (PgStatSslView, error) {
version, err := s.getPgVersion()
if err != nil {
return nil, err
}
if version < 9.5 {
return nil, errors.Errorf("Unsupported PostgreSQL version: %f", version)
}
db := s.conn.db
query := "select pid,ssl,version,cipher,bits," +
"compression,clientdn from pg_stat_ssl"
rows, err := db.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
data := make(PgStatSslView, 0)
for rows.Next() {
row := new(PgStatSslRow)
err := rows.Scan(&row.Pid, &row.Ssl, &row.Version, &row.Cipher, &row.Bits,
&row.Compression, &row.Clientdn)
if err != nil {
return nil, err
}
data = append(data, *row)
}
return data, rows.Err()
}