-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
173 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
``` | ||
calert_alerts_dispatched_errors_total{provider="google_chat", room="dev_alerts"} 1 | ||
calert_alerts_dispatched_errors_total{provider="google_chat", room="prod_alerts"} 1 | ||
calert_alerts_dispatched_total{provider="google_chat", room="dev_alerts"} 1 | ||
calert_alerts_dispatched_total{provider="google_chat", room="prod_alerts"} 1 | ||
calert_http_request_duration_seconds_bucket{handler="dispatch",vmrange="4.642e-01...5.275e-01"} 2 | ||
calert_http_request_duration_seconds_sum{handler="dispatch"} 1.0370891740000001 | ||
calert_http_request_duration_seconds_count{handler="dispatch"} 2 | ||
calert_http_requests_total{handler="dispatch"} 2 | ||
calert_start_timestamp 1645193338 | ||
calert_uptime_seconds 34 | ||
``` | ||
|
||
``` | ||
calert_alerts_dispatched_duration_seconds_bucket{provider="google_chat", room="dev_alerts",vmrange="1.292e+00...1.468e+00"} 1 | ||
calert_alerts_dispatched_duration_seconds_sum{provider="google_chat", room="dev_alerts"} 1.372438907 | ||
calert_alerts_dispatched_duration_seconds_count{provider="google_chat", room="dev_alerts"} 1 | ||
calert_alerts_dispatched_duration_seconds_bucket{provider="google_chat", room="prod_alerts",vmrange="1.292e+00...1.468e+00"} 1 | ||
calert_alerts_dispatched_duration_seconds_sum{provider="google_chat", room="prod_alerts"} 1.4265874539999999 | ||
calert_alerts_dispatched_duration_seconds_count{provider="google_chat", room="prod_alerts"} 1 | ||
calert_alerts_dispatched_total{provider="google_chat", room="dev_alerts"} 1 | ||
calert_alerts_dispatched_total{provider="google_chat", room="prod_alerts"} 1 | ||
calert_http_request_duration_seconds_bucket{handler="dispatch",vmrange="1.292e+00...1.468e+00"} 2 | ||
calert_http_request_duration_seconds_sum{handler="dispatch"} 2.799676161 | ||
calert_http_request_duration_seconds_count{handler="dispatch"} 2 | ||
calert_http_requests_total{handler="dispatch"} 2 | ||
calert_start_timestamp 1645193392 | ||
calert_uptime_seconds 78 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,71 @@ | ||
// Package metrics contains wrapper around VictoriaMetrics | ||
// functions to interact with counters, gauges etc. It also has functions | ||
// to write the metrics output to to an `io.Writer` interface. | ||
package metrics | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"time" | ||
|
||
"github.com/VictoriaMetrics/metrics" | ||
) | ||
|
||
// Manager represents options for storing metrics. | ||
type Manager struct { | ||
metrics *metrics.Set | ||
namespace string // Optional string to prepend all label names. | ||
startTime time.Time | ||
} | ||
|
||
// New returns a new configured instance of Manager. | ||
func New(ns string) *Manager { | ||
return &Manager{ | ||
metrics: metrics.NewSet(), | ||
namespace: ns, | ||
startTime: time.Now(), | ||
} | ||
} | ||
|
||
// Increment the counter for the corresponding key. | ||
// This is used for Counter metric type. | ||
func (s *Manager) Increment(label string) { | ||
s.metrics.GetOrCreateCounter(s.getFormattedLabel(label)).Inc() | ||
} | ||
|
||
// Decrement the counter for the corresponding key. | ||
// This is used for Counter metric type. | ||
func (s *Manager) Decrement(label string) { | ||
s.metrics.GetOrCreateCounter(s.getFormattedLabel(label)).Dec() | ||
} | ||
|
||
// Duration updates the key with time delta value of `startTime`. | ||
// This is used for Histogram metric type. | ||
func (s *Manager) Duration(label string, startTime time.Time) { | ||
s.metrics.GetOrCreateHistogram(s.getFormattedLabel(label)).UpdateDuration(startTime) | ||
} | ||
|
||
// Set updates the key with a float64 value. | ||
// This is used for Gauge metric type. | ||
func (s *Manager) Set(label string, val float64) { | ||
s.metrics.GetOrCreateFloatCounter(s.getFormattedLabel(label)).Set(val) | ||
} | ||
|
||
// FlushMetrics writes the metrics data from the internal store | ||
// to the buffer. | ||
func (s *Manager) FlushMetrics(buf io.Writer) { | ||
metrics.WriteProcessMetrics(buf) | ||
s.metrics.WritePrometheus(buf) | ||
|
||
// Export start time and uptime in seconds | ||
fmt.Fprintf(buf, "calert_start_timestamp %d\n", s.startTime.Unix()) | ||
fmt.Fprintf(buf, "calert_uptime_seconds %d\n", int(time.Since(s.startTime).Seconds())) | ||
} | ||
|
||
// getFormattedLabel prefixes the label with namespace (if non empty). | ||
func (s *Manager) getFormattedLabel(l string) string { | ||
if s.namespace != "" { | ||
return s.namespace + "_" + l | ||
} | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.