pangolin_exporter

Форк
0
84 строки · 1.9 Кб
1
// Copyright 2023 The Prometheus Authors
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13

14
package collector
15

16
import (
17
	"context"
18

19
	"github.com/prometheus/client_golang/prometheus"
20
)
21

22
const walSubsystem = "wal"
23

24
func init() {
25
	registerCollector(walSubsystem, defaultEnabled, NewPGWALCollector)
26
}
27

28
type PGWALCollector struct {
29
}
30

31
func NewPGWALCollector(config collectorConfig) (Collector, error) {
32
	return &PGWALCollector{}, nil
33
}
34

35
var (
36
	pgWALSegments = prometheus.NewDesc(
37
		prometheus.BuildFQName(
38
			namespace,
39
			walSubsystem,
40
			"segments",
41
		),
42
		"Number of WAL segments",
43
		[]string{}, nil,
44
	)
45
	pgWALSize = prometheus.NewDesc(
46
		prometheus.BuildFQName(
47
			namespace,
48
			walSubsystem,
49
			"size_bytes",
50
		),
51
		"Total size of WAL segments",
52
		[]string{}, nil,
53
	)
54

55
	pgWALQuery = `
56
		SELECT
57
			COUNT(*) AS segments,
58
			SUM(size) AS size
59
		FROM pg_ls_waldir()
60
		WHERE name ~ '^[0-9A-F]{24}$'`
61
)
62

63
func (c PGWALCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
64
	db := instance.getDB()
65
	row := db.QueryRowContext(ctx,
66
		pgWALQuery,
67
	)
68

69
	var segments uint64
70
	var size uint64
71
	err := row.Scan(&segments, &size)
72
	if err != nil {
73
		return err
74
	}
75
	ch <- prometheus.MustNewConstMetric(
76
		pgWALSegments,
77
		prometheus.GaugeValue, float64(segments),
78
	)
79
	ch <- prometheus.MustNewConstMetric(
80
		pgWALSize,
81
		prometheus.GaugeValue, float64(size),
82
	)
83
	return nil
84
}
85

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.