Dragonfly2

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

17
package metrics
18

19
import (
20
	"net/http"
21

22
	grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
23
	"github.com/prometheus/client_golang/prometheus"
24
	"github.com/prometheus/client_golang/prometheus/promauto"
25
	"github.com/prometheus/client_golang/prometheus/promhttp"
26
	"google.golang.org/grpc"
27

28
	"d7y.io/dragonfly/v2/pkg/types"
29
	"d7y.io/dragonfly/v2/trainer/config"
30
	"d7y.io/dragonfly/v2/version"
31
)
32

33
// Variables declared for metrics.
34
var (
35
	TrainCount = promauto.NewCounter(prometheus.CounterOpts{
36
		Namespace: types.MetricsNamespace,
37
		Subsystem: types.TrainerMetricsName,
38
		Name:      "training_total",
39
		Help:      "Counter of the number of the training.",
40
	})
41

42
	TrainFailureCount = promauto.NewCounter(prometheus.CounterOpts{
43
		Namespace: types.MetricsNamespace,
44
		Subsystem: types.TrainerMetricsName,
45
		Name:      "training_failure_total",
46
		Help:      "Counter of the number of failed of the training.",
47
	})
48

49
	VersionGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
50
		Namespace: types.MetricsNamespace,
51
		Subsystem: types.TrainerMetricsName,
52
		Name:      "version",
53
		Help:      "Version info of the service.",
54
	}, []string{"major", "minor", "git_version", "git_commit", "platform", "build_time", "go_version", "go_tags", "go_gcflags"})
55
)
56

57
func New(cfg *config.MetricsConfig, svr *grpc.Server) *http.Server {
58
	grpc_prometheus.Register(svr)
59

60
	mux := http.NewServeMux()
61
	mux.Handle("/metrics", promhttp.Handler())
62

63
	VersionGauge.WithLabelValues(version.Major, version.Minor, version.GitVersion, version.GitCommit, version.Platform, version.BuildTime, version.GoVersion, version.Gotags, version.Gogcflags).Set(1)
64
	return &http.Server{
65
		Addr:    cfg.Addr,
66
		Handler: mux,
67
	}
68
}
69

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

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

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

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