2021-07-13 15:58:47 +00:00
|
|
|
package status
|
2016-04-15 01:41:10 +00:00
|
|
|
|
|
|
|
import (
|
2016-12-20 01:34:25 +00:00
|
|
|
"errors"
|
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
"github.com/appleboy/gorush/config"
|
2022-11-09 06:05:09 +00:00
|
|
|
"github.com/appleboy/gorush/core"
|
2021-07-13 08:32:39 +00:00
|
|
|
"github.com/appleboy/gorush/logx"
|
2018-04-16 09:26:15 +00:00
|
|
|
"github.com/appleboy/gorush/storage/badger"
|
2016-05-03 02:26:13 +00:00
|
|
|
"github.com/appleboy/gorush/storage/boltdb"
|
2016-09-19 08:19:20 +00:00
|
|
|
"github.com/appleboy/gorush/storage/buntdb"
|
|
|
|
"github.com/appleboy/gorush/storage/leveldb"
|
2016-05-03 02:26:13 +00:00
|
|
|
"github.com/appleboy/gorush/storage/memory"
|
|
|
|
"github.com/appleboy/gorush/storage/redis"
|
2020-02-04 05:27:27 +00:00
|
|
|
|
2016-06-26 04:21:32 +00:00
|
|
|
"github.com/thoas/stats"
|
2016-04-15 01:41:10 +00:00
|
|
|
)
|
|
|
|
|
2016-06-26 04:21:32 +00:00
|
|
|
// Stats provide response time, status code count, etc.
|
2021-07-17 12:14:19 +00:00
|
|
|
var Stats *stats.Stats
|
2016-06-26 04:21:32 +00:00
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
// StatStorage implements the storage interface
|
2022-02-03 09:03:37 +00:00
|
|
|
var StatStorage *StateStorage
|
2021-07-13 15:58:47 +00:00
|
|
|
|
|
|
|
// App is status structure
|
|
|
|
type App struct {
|
2022-05-05 05:56:28 +00:00
|
|
|
Version string `json:"version"`
|
|
|
|
BusyWorkers int `json:"busy_workers"`
|
|
|
|
SuccessTasks int `json:"success_tasks"`
|
|
|
|
FailureTasks int `json:"failure_tasks"`
|
|
|
|
SubmittedTasks int `json:"submitted_tasks"`
|
|
|
|
TotalCount int64 `json:"total_count"`
|
|
|
|
Ios IosStatus `json:"ios"`
|
|
|
|
Android AndroidStatus `json:"android"`
|
|
|
|
Huawei HuaweiStatus `json:"huawei"`
|
2016-04-15 01:41:10 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 08:59:57 +00:00
|
|
|
// AndroidStatus is android structure
|
2016-04-15 01:41:10 +00:00
|
|
|
type AndroidStatus struct {
|
|
|
|
PushSuccess int64 `json:"push_success"`
|
|
|
|
PushError int64 `json:"push_error"`
|
|
|
|
}
|
|
|
|
|
2016-04-15 08:59:57 +00:00
|
|
|
// IosStatus is iOS structure
|
2016-04-15 01:41:10 +00:00
|
|
|
type IosStatus struct {
|
|
|
|
PushSuccess int64 `json:"push_success"`
|
|
|
|
PushError int64 `json:"push_error"`
|
|
|
|
}
|
|
|
|
|
2020-09-04 03:01:21 +00:00
|
|
|
// HuaweiStatus is huawei structure
|
|
|
|
type HuaweiStatus struct {
|
|
|
|
PushSuccess int64 `json:"push_success"`
|
|
|
|
PushError int64 `json:"push_error"`
|
|
|
|
}
|
|
|
|
|
2016-04-22 09:54:00 +00:00
|
|
|
// InitAppStatus for initialize app status
|
2021-08-02 06:07:30 +00:00
|
|
|
func InitAppStatus(conf *config.ConfYaml) error {
|
2021-07-13 15:58:47 +00:00
|
|
|
logx.LogAccess.Info("Init App Status Engine as ", conf.Stat.Engine)
|
2022-02-03 09:03:37 +00:00
|
|
|
|
2022-11-09 06:05:09 +00:00
|
|
|
var store core.Storage
|
2021-07-13 15:58:47 +00:00
|
|
|
switch conf.Stat.Engine {
|
2016-04-22 09:54:00 +00:00
|
|
|
case "memory":
|
2022-02-03 09:03:37 +00:00
|
|
|
store = memory.New()
|
2016-05-02 11:42:21 +00:00
|
|
|
case "redis":
|
2022-02-03 09:03:37 +00:00
|
|
|
store = redis.New(conf)
|
2016-05-02 12:22:37 +00:00
|
|
|
case "boltdb":
|
2022-02-03 09:03:37 +00:00
|
|
|
store = boltdb.New(conf)
|
2016-09-19 08:19:20 +00:00
|
|
|
case "buntdb":
|
2022-02-03 09:03:37 +00:00
|
|
|
store = buntdb.New(conf)
|
2016-09-19 08:19:20 +00:00
|
|
|
case "leveldb":
|
2022-02-03 09:03:37 +00:00
|
|
|
store = leveldb.New(conf)
|
2018-04-16 09:26:15 +00:00
|
|
|
case "badger":
|
2022-02-03 09:03:37 +00:00
|
|
|
store = badger.New(conf)
|
2016-04-22 09:54:00 +00:00
|
|
|
default:
|
2021-07-13 08:32:39 +00:00
|
|
|
logx.LogError.Error("storage error: can't find storage driver")
|
2017-06-24 14:47:35 +00:00
|
|
|
return errors.New("can't find storage driver")
|
2016-04-22 09:54:00 +00:00
|
|
|
}
|
2016-05-02 12:22:37 +00:00
|
|
|
|
2022-02-03 09:03:37 +00:00
|
|
|
StatStorage = NewStateStorage(store)
|
|
|
|
|
2016-12-20 01:34:25 +00:00
|
|
|
if err := StatStorage.Init(); err != nil {
|
2021-07-13 08:32:39 +00:00
|
|
|
logx.LogError.Error("storage error: " + err.Error())
|
2016-09-19 08:19:20 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-17 12:14:19 +00:00
|
|
|
Stats = stats.New()
|
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
return nil
|
2016-04-15 01:41:10 +00:00
|
|
|
}
|