1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-22 20:11:18 +00:00

Add support for different stale status than Unknown

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-09-16 14:47:51 +02:00
parent dfc3ff81f0
commit 017c29caae
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 26 additions and 16 deletions

View file

@ -107,7 +107,7 @@ type PostMetricInput struct {
// Default: `604800` // Default: `604800`
Expires int64 `json:"expires,omitempty"` Expires int64 `json:"expires,omitempty"`
// Time in seconds when to switch to `Unkown` state of there is no update (Valid: `0 < x < 604800`) // Time in seconds when to switch to stale state of there is no update (Valid: `0 < x < 604800`)
// Default: 3600 // Default: 3600
Freshness int64 `json:"freshness,omitempty"` Freshness int64 `json:"freshness,omitempty"`
@ -122,6 +122,10 @@ type PostMetricInput struct {
// If set to true the value of the metric is not shown on the dashboard // If set to true the value of the metric is not shown on the dashboard
// Default: false // Default: false
HideValue bool `json:"hide_value,omitempty"` HideValue bool `json:"hide_value,omitempty"`
// If set this status will be set when the metric gets stale (no updates within freshness time range
// Default: "Unknown"
StalenessStatus string `json:"staleness_status,omitifempty"`
} }
func (p *PostMetricInput) validate() error { func (p *PostMetricInput) validate() error {

View file

@ -11,6 +11,8 @@ import (
"github.com/Luzifer/mondash/storage" "github.com/Luzifer/mondash/storage"
) )
const defaultStalenessStatus = "Unknown"
type dashboard struct { type dashboard struct {
DashboardID string `json:"-"` DashboardID string `json:"-"`
APIKey string `json:"api_key"` APIKey string `json:"api_key"`
@ -54,18 +56,19 @@ func (a dashboardMetrics) Less(i, j int) bool {
} }
type dashboardMetric struct { type dashboardMetric struct {
MetricID string `json:"id"` MetricID string `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
Status string `json:"status"` Status string `json:"status"`
Value float64 `json:"value,omitifempty"` Value float64 `json:"value,omitifempty"`
Expires int64 `json:"expires,omitifempty"` Expires int64 `json:"expires,omitifempty"`
Freshness int64 `json:"freshness,omitifempty"` Freshness int64 `json:"freshness,omitifempty"`
IgnoreMAD bool `json:"ignore_mad"` IgnoreMAD bool `json:"ignore_mad"`
HideMAD bool `json:"hide_mad"` HideMAD bool `json:"hide_mad"`
HideValue bool `json:"hide_value"` HideValue bool `json:"hide_value"`
HistoricalData dashboardMetricHistory `json:"history,omitifempty"` HistoricalData dashboardMetricHistory `json:"history,omitifempty"`
Meta dashboardMetricMeta `json:"meta,omitifempty"` Meta dashboardMetricMeta `json:"meta,omitifempty"`
StalenessStatus string `json:"staleness_status,omitifempty"`
} }
type dashboardMetricStatus struct { type dashboardMetricStatus struct {
@ -86,7 +89,7 @@ type dashboardMetricHistory []dashboardMetricStatus
func newDashboardMetric() *dashboardMetric { func newDashboardMetric() *dashboardMetric {
return &dashboardMetric{ return &dashboardMetric{
Status: "Unknown", Status: defaultStalenessStatus,
Expires: 604800, Expires: 604800,
Freshness: 3600, Freshness: 3600,
HistoricalData: dashboardMetricHistory{}, HistoricalData: dashboardMetricHistory{},
@ -171,7 +174,10 @@ func (dm *dashboardMetric) StatisticalStatus() string {
func (dm *dashboardMetric) PreferredStatus() string { func (dm *dashboardMetric) PreferredStatus() string {
if dm.Meta.LastUpdate.Before(time.Now().Add(-1 * time.Duration(dm.Freshness) * time.Second)) { if dm.Meta.LastUpdate.Before(time.Now().Add(-1 * time.Duration(dm.Freshness) * time.Second)) {
return "Unknown" if dm.StalenessStatus == "" {
return defaultStalenessStatus
}
return dm.StalenessStatus
} }
if dm.IgnoreMAD { if dm.IgnoreMAD {
@ -289,7 +295,7 @@ func (dm dashboardMetric) GetHistoryBar() []historyBarSegment {
segLength int segLength int
segments = []historyBarSegment{} segments = []historyBarSegment{}
segStart time.Time segStart time.Time
status = "Unknown" status = defaultStalenessStatus
) )
for _, point = range dm.HistoricalData { for _, point = range dm.HistoricalData {