Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Add last_state metric
Browse files Browse the repository at this point in the history
It is a bit difficult to alert on sync_calls since they trigger into an error state and may stay there.
This adds the gauge last_state.  With last_state, people can easily alert on a value < 0 to indicate failure.
  • Loading branch information
Jack Lindamood committed Apr 22, 2020
1 parent b345ffd commit 3ee03ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ kubernetes-external-secrets exposes the following metrics over a prometheus endp
| Metric | Description | Example |
| ----------------------------------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `sync_calls` | This metric counts the number of sync calls by backend, secret name and status | `sync_calls{name="foo",namespace="example",backend="foo",status="success"} 1` |
| `last_state` | A value of -1 or 1 where -1 means the last sync_call was an error and 1 means the last sync_call was a success | `last_state{name="foo",namespace="example",backend="foo"} 1` |


## Development
Expand Down
19 changes: 19 additions & 0 deletions lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Metrics {
labelNames: ['name', 'namespace', 'backend', 'status'],
registers: [registry]
})
this._lastState = new Prometheus.Gauge({
name: 'last_state',
help: 'Value -1 if the last sync was a failure, 1 otherwise.',
labelNames: ['name', 'namespace', 'backend'],
registers: [registry]
})
}

/**
Expand All @@ -31,6 +37,19 @@ class Metrics {
backend,
status
})
if (status === 'success') {
this._lastState.set({
name,
namespace,
backend,
}, 1)
} else {
this._lastState.set({
name,
namespace,
backend,
}, -1)
}
}
}

Expand Down

0 comments on commit 3ee03ae

Please sign in to comment.