pangolin_exporter

Форк
0
/
pg_test_metric.go 
69 строк · 1.8 Кб
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
	"database/sql"
19

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

23
const testMetricSubsystem = "TestMetric"
24

25
func init() {
26
	registerCollector(testMetricSubsystem, defaultEnabled, NewTestMetricCollector)
27
}
28

29
type TestMetricCollector struct {
30
}
31

32
func NewTestMetricCollector(collectorConfig) (Collector, error) {
33
	return &TestMetricCollector{}, nil
34
}
35

36
var (
37
	TestMetricStartTimeSeconds = prometheus.NewDesc(
38
		prometheus.BuildFQName(
39
			namespace,
40
			testMetricSubsystem,
41
			"my_first_metric_in_package_collector",
42
		),
43
		"Time at which testMetric started",
44
		[]string{}, nil,
45
	)
46

47
	TestMetricQuery = "SELECT 8;"
48
)
49

50
func (c *TestMetricCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
51
	db := instance.getDB()
52
	row := db.QueryRowContext(ctx,
53
		TestMetricQuery)
54

55
	var startTimeSeconds sql.NullFloat64
56
	err := row.Scan(&startTimeSeconds)
57
	if err != nil {
58
		return err
59
	}
60
	startTimeSecondsMetric := 0.0
61
	if startTimeSeconds.Valid {
62
		startTimeSecondsMetric = startTimeSeconds.Float64
63
	}
64
	ch <- prometheus.MustNewConstMetric(
65
		TestMetricStartTimeSeconds,
66
		prometheus.GaugeValue, startTimeSecondsMetric,
67
	)
68
	return nil
69
}
70

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

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

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

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