prometheus
76 строк · 2.4 Кб
1// Copyright 2015 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
14package file15
16import (17"github.com/prometheus/client_golang/prometheus"18
19"github.com/prometheus/prometheus/discovery"20)
21
22var _ discovery.DiscovererMetrics = (*fileMetrics)(nil)23
24type fileMetrics struct {25fileSDReadErrorsCount prometheus.Counter26fileSDScanDuration prometheus.Summary27fileWatcherErrorsCount prometheus.Counter28fileSDTimeStamp *TimestampCollector29
30metricRegisterer discovery.MetricRegisterer31}
32
33func newDiscovererMetrics(reg prometheus.Registerer, rmi discovery.RefreshMetricsInstantiator) discovery.DiscovererMetrics {34fm := &fileMetrics{35fileSDReadErrorsCount: prometheus.NewCounter(36prometheus.CounterOpts{37Name: "prometheus_sd_file_read_errors_total",38Help: "The number of File-SD read errors.",39}),40fileSDScanDuration: prometheus.NewSummary(41prometheus.SummaryOpts{42Name: "prometheus_sd_file_scan_duration_seconds",43Help: "The duration of the File-SD scan in seconds.",44Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},45}),46fileWatcherErrorsCount: prometheus.NewCounter(47prometheus.CounterOpts{48Name: "prometheus_sd_file_watcher_errors_total",49Help: "The number of File-SD errors caused by filesystem watch failures.",50}),51fileSDTimeStamp: NewTimestampCollector(),52}53
54fm.metricRegisterer = discovery.NewMetricRegisterer(reg, []prometheus.Collector{55fm.fileSDReadErrorsCount,56fm.fileSDScanDuration,57fm.fileWatcherErrorsCount,58fm.fileSDTimeStamp,59})60
61return fm62}
63
64// Register implements discovery.DiscovererMetrics.
65func (fm *fileMetrics) Register() error {66return fm.metricRegisterer.RegisterMetrics()67}
68
69// Unregister implements discovery.DiscovererMetrics.
70func (fm *fileMetrics) Unregister() {71fm.metricRegisterer.UnregisterMetrics()72}
73
74func (fm *fileMetrics) init(disc *Discovery) {75fm.fileSDTimeStamp.addDiscoverer(disc)76}
77