...

Source file src/github.com/prometheus/alertmanager/api/metrics/metrics.go

Documentation: github.com/prometheus/alertmanager/api/metrics

     1  // Copyright 2019 Prometheus Team
     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 metrics
    15  
    16  import "github.com/prometheus/client_golang/prometheus"
    17  
    18  // Alerts stores metrics for alerts which are common across all API versions.
    19  type Alerts struct {
    20  	firing   prometheus.Counter
    21  	resolved prometheus.Counter
    22  	invalid  prometheus.Counter
    23  }
    24  
    25  // NewAlerts returns an *Alerts struct for the given API version.
    26  func NewAlerts(version string, r prometheus.Registerer) *Alerts {
    27  	numReceivedAlerts := prometheus.NewCounterVec(prometheus.CounterOpts{
    28  		Name:        "alertmanager_alerts_received_total",
    29  		Help:        "The total number of received alerts.",
    30  		ConstLabels: prometheus.Labels{"version": version},
    31  	}, []string{"status"})
    32  	numInvalidAlerts := prometheus.NewCounter(prometheus.CounterOpts{
    33  		Name:        "alertmanager_alerts_invalid_total",
    34  		Help:        "The total number of received alerts that were invalid.",
    35  		ConstLabels: prometheus.Labels{"version": version},
    36  	})
    37  	if r != nil {
    38  		r.MustRegister(numReceivedAlerts, numInvalidAlerts)
    39  	}
    40  	return &Alerts{
    41  		firing:   numReceivedAlerts.WithLabelValues("firing"),
    42  		resolved: numReceivedAlerts.WithLabelValues("resolved"),
    43  		invalid:  numInvalidAlerts,
    44  	}
    45  }
    46  
    47  // Firing returns a counter of firing alerts.
    48  func (a *Alerts) Firing() prometheus.Counter { return a.firing }
    49  
    50  // Resolved returns a counter of resolved alerts.
    51  func (a *Alerts) Resolved() prometheus.Counter { return a.resolved }
    52  
    53  // Invalid returns a counter of invalid alerts.
    54  func (a *Alerts) Invalid() prometheus.Counter { return a.invalid }
    55  

View as plain text