metrics.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  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. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package externalsecret
  13. import (
  14. "github.com/prometheus/client_golang/prometheus"
  15. "sigs.k8s.io/controller-runtime/pkg/metrics"
  16. esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
  17. )
  18. const (
  19. ExternalSecretSubsystem = "externalsecret"
  20. SyncCallsKey = "sync_calls_total"
  21. SyncCallsErrorKey = "sync_calls_error"
  22. externalSecretStatusConditionKey = "status_condition"
  23. )
  24. var (
  25. syncCallsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
  26. Subsystem: ExternalSecretSubsystem,
  27. Name: SyncCallsKey,
  28. Help: "Total number of the External Secret sync calls",
  29. }, []string{"name", "namespace"})
  30. syncCallsError = prometheus.NewCounterVec(prometheus.CounterOpts{
  31. Subsystem: ExternalSecretSubsystem,
  32. Name: SyncCallsErrorKey,
  33. Help: "Total number of the External Secret sync errors",
  34. }, []string{"name", "namespace"})
  35. externalSecretCondition = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  36. Subsystem: ExternalSecretSubsystem,
  37. Name: externalSecretStatusConditionKey,
  38. Help: "The status condition of a specific External Secret",
  39. }, []string{"name", "namespace", "condition", "status"})
  40. )
  41. func updateExternalSecretCondition(es *esv1alpha1.ExternalSecret, condition *esv1alpha1.ExternalSecretStatusCondition, value float64) {
  42. externalSecretCondition.With(prometheus.Labels{
  43. "name": es.Name,
  44. "namespace": es.Namespace,
  45. "condition": string(condition.Type),
  46. "status": string(condition.Status),
  47. }).Set(value)
  48. }
  49. func init() {
  50. metrics.Registry.MustRegister(syncCallsTotal, syncCallsError, externalSecretCondition)
  51. }