diff options
Diffstat (limited to 'internal/metrics')
-rw-r--r-- | internal/metrics/metrics.go | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 7a67a9c..aae46cd 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -31,21 +31,21 @@ func NewMetrics(registry *prometheus.Registry) *Metrics { Name: "silentct_log_index", Help: "The next log entry to be downloaded.", }, - []string{"log_id"}, + []string{"log_id", "log_name"}, ), logSize: prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "silentct_log_size", Help: "The number of entries in the log.", }, - []string{"log_id"}, + []string{"log_id", "log_name"}, ), logTimestamp: prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "silentct_log_timestamp", Help: "The log's UNIX timestamp in ms.", }, - []string{"log_id"}, + []string{"log_id", "log_name"}, ), needRestart: prometheus.NewGauge( prometheus.GaugeOpts{ @@ -58,7 +58,7 @@ func NewMetrics(registry *prometheus.Registry) *Metrics { Name: "silentct_unexpected_certificate_count", Help: "Number of certificates without any allowlisting", }, - []string{"log_id", "log_index", "crt_sans"}, + []string{"log_id", "log_name", "log_index", "crt_sans"}, ), } registry.MustRegister( @@ -72,26 +72,33 @@ func NewMetrics(registry *prometheus.Registry) *Metrics { return m } -func (m *Metrics) LogState(state monitor.State) { - id := fmt.Sprintf("%x", state.LogID) - m.logIndex.WithLabelValues(id).Set(float64(state.NextIndex)) - m.logSize.WithLabelValues(id).Set(float64(state.TreeSize)) - m.logTimestamp.WithLabelValues(id).Set(float64(state.Timestamp)) +func (m *Metrics) LogState(logName string, state monitor.State) { + labels := prometheus.Labels{ + "log_id": fmt.Sprintf("%x", state.LogID[:]), + "log_name": logName, + } + m.logIndex.With(labels).Set(float64(state.NextIndex)) + m.logSize.With(labels).Set(float64(state.TreeSize)) + m.logTimestamp.With(labels).Set(float64(state.Timestamp)) } -func (m *Metrics) RemoveLogState(state monitor.State) { - id := fmt.Sprintf("%x", state.LogID) - m.logIndex.Delete(prometheus.Labels{"id": id}) - m.logSize.Delete(prometheus.Labels{"id": id}) - m.logTimestamp.Delete(prometheus.Labels{"id": id}) +func (m *Metrics) RemoveLogState(logName string, state monitor.State) { + labels := prometheus.Labels{ + "log_id": fmt.Sprintf("%x", state.LogID[:]), + "log_name": logName, + } + m.logIndex.Delete(labels) + m.logSize.Delete(labels) + m.logTimestamp.Delete(labels) } -func (m *Metrics) UnexpectedCertificateCount(alerts []index.CertificateInfo) { +func (m *Metrics) UnexpectedCertificateCount(logNames []string, alerts []index.CertificateInfo) { m.unexpectedCertificateCount.Reset() - for _, alert := range alerts { + for i, alert := range alerts { labels := prometheus.Labels{ "crt_sans": strings.Join(alert.SANs, " "), "log_id": fmt.Sprintf("%x", alert.LogID), + "log_name": logNames[i], "log_index": fmt.Sprintf("%d", alert.LogIndex), } m.unexpectedCertificateCount.With(labels).Set(1) |