2021-07-13 15:58:47 +00:00
|
|
|
package metric
|
2017-01-19 08:56:30 +00:00
|
|
|
|
|
|
|
import (
|
2021-07-13 15:58:47 +00:00
|
|
|
"github.com/appleboy/gorush/status"
|
|
|
|
|
2022-05-05 05:56:28 +00:00
|
|
|
"github.com/golang-queue/queue"
|
2017-01-19 08:56:30 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
const namespace = "gorush_"
|
|
|
|
|
|
|
|
// Metrics implements the prometheus.Metrics interface and
|
2017-01-19 14:21:53 +00:00
|
|
|
// exposes gorush metrics for prometheus
|
2017-01-19 08:56:30 +00:00
|
|
|
type Metrics struct {
|
|
|
|
TotalPushCount *prometheus.Desc
|
|
|
|
IosSuccess *prometheus.Desc
|
|
|
|
IosError *prometheus.Desc
|
|
|
|
AndroidSuccess *prometheus.Desc
|
|
|
|
AndroidError *prometheus.Desc
|
2020-09-04 03:01:21 +00:00
|
|
|
HuaweiSuccess *prometheus.Desc
|
|
|
|
HuaweiError *prometheus.Desc
|
2022-05-05 05:56:28 +00:00
|
|
|
BusyWorkers *prometheus.Desc
|
|
|
|
SuccessTasks *prometheus.Desc
|
|
|
|
FailureTasks *prometheus.Desc
|
|
|
|
SubmittedTasks *prometheus.Desc
|
|
|
|
q *queue.Queue
|
2017-01-19 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewMetrics returns a new Metrics with all prometheus.Desc initialized
|
2022-05-05 05:56:28 +00:00
|
|
|
func NewMetrics(q *queue.Queue) Metrics {
|
2021-07-13 15:58:47 +00:00
|
|
|
m := Metrics{
|
2017-01-19 08:56:30 +00:00
|
|
|
TotalPushCount: prometheus.NewDesc(
|
|
|
|
namespace+"total_push_count",
|
|
|
|
"Number of push count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
IosSuccess: prometheus.NewDesc(
|
|
|
|
namespace+"ios_success",
|
|
|
|
"Number of iOS success count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
IosError: prometheus.NewDesc(
|
|
|
|
namespace+"ios_error",
|
|
|
|
"Number of iOS fail count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
AndroidSuccess: prometheus.NewDesc(
|
|
|
|
namespace+"android_success",
|
|
|
|
"Number of android success count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
AndroidError: prometheus.NewDesc(
|
|
|
|
namespace+"android_fail",
|
|
|
|
"Number of android fail count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
2020-09-04 03:01:21 +00:00
|
|
|
HuaweiSuccess: prometheus.NewDesc(
|
|
|
|
namespace+"huawei_success",
|
|
|
|
"Number of huawei success count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
HuaweiError: prometheus.NewDesc(
|
|
|
|
namespace+"huawei_fail",
|
|
|
|
"Number of huawei fail count",
|
|
|
|
nil, nil,
|
|
|
|
),
|
2022-05-05 05:56:28 +00:00
|
|
|
BusyWorkers: prometheus.NewDesc(
|
|
|
|
namespace+"busy_workers",
|
|
|
|
"Length of busy workers",
|
2019-03-16 14:19:05 +00:00
|
|
|
nil, nil,
|
|
|
|
),
|
2022-05-05 05:56:28 +00:00
|
|
|
FailureTasks: prometheus.NewDesc(
|
|
|
|
namespace+"failure_tasks",
|
|
|
|
"Length of Failure Tasks",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
SuccessTasks: prometheus.NewDesc(
|
|
|
|
namespace+"success_tasks",
|
|
|
|
"Length of Success Tasks",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
SubmittedTasks: prometheus.NewDesc(
|
|
|
|
namespace+"submitted_tasks",
|
|
|
|
"Length of Submitted Tasks",
|
|
|
|
nil, nil,
|
|
|
|
),
|
|
|
|
q: q,
|
2021-07-13 15:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
2017-01-19 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Describe returns all possible prometheus.Desc
|
|
|
|
func (c Metrics) Describe(ch chan<- *prometheus.Desc) {
|
|
|
|
ch <- c.TotalPushCount
|
|
|
|
ch <- c.IosSuccess
|
|
|
|
ch <- c.IosError
|
|
|
|
ch <- c.AndroidSuccess
|
|
|
|
ch <- c.AndroidError
|
2020-09-04 03:01:21 +00:00
|
|
|
ch <- c.HuaweiSuccess
|
|
|
|
ch <- c.HuaweiError
|
2022-05-05 05:56:28 +00:00
|
|
|
ch <- c.BusyWorkers
|
|
|
|
ch <- c.SuccessTasks
|
|
|
|
ch <- c.FailureTasks
|
|
|
|
ch <- c.SubmittedTasks
|
2017-01-19 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect returns the metrics with values
|
|
|
|
func (c Metrics) Collect(ch chan<- prometheus.Metric) {
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.TotalPushCount,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetTotalCount()),
|
2017-01-19 08:56:30 +00:00
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.IosSuccess,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetIosSuccess()),
|
2017-01-19 08:56:30 +00:00
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.IosError,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetIosError()),
|
2017-01-19 08:56:30 +00:00
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.AndroidSuccess,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetAndroidSuccess()),
|
2017-01-19 08:56:30 +00:00
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.AndroidError,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetAndroidError()),
|
2017-01-19 08:56:30 +00:00
|
|
|
)
|
2020-09-04 03:01:21 +00:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.HuaweiSuccess,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetHuaweiSuccess()),
|
2020-09-04 03:01:21 +00:00
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.HuaweiError,
|
2021-05-14 23:05:54 +00:00
|
|
|
prometheus.CounterValue,
|
2021-07-13 15:58:47 +00:00
|
|
|
float64(status.StatStorage.GetHuaweiError()),
|
2020-09-04 03:01:21 +00:00
|
|
|
)
|
2019-03-16 14:19:05 +00:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
2022-05-05 05:56:28 +00:00
|
|
|
c.BusyWorkers,
|
2019-03-16 14:19:05 +00:00
|
|
|
prometheus.GaugeValue,
|
2022-05-05 05:56:28 +00:00
|
|
|
float64(c.q.BusyWorkers()),
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.SuccessTasks,
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(c.q.SuccessTasks()),
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.FailureTasks,
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(c.q.FailureTasks()),
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.SubmittedTasks,
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(c.q.SubmittedTasks()),
|
2019-03-16 14:19:05 +00:00
|
|
|
)
|
2017-01-19 08:56:30 +00:00
|
|
|
}
|