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"
|
2021-07-13 08:32:39 +00:00
|
|
|
"github.com/appleboy/gorush/logx"
|
2021-07-13 15:58:47 +00:00
|
|
|
"github.com/appleboy/gorush/storage"
|
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
|
|
|
|
var StatStorage storage.Storage
|
|
|
|
|
|
|
|
// App is status structure
|
|
|
|
type App struct {
|
2016-09-30 02:49:52 +00:00
|
|
|
Version string `json:"version"`
|
2016-04-15 01:41:10 +00:00
|
|
|
QueueMax int `json:"queue_max"`
|
|
|
|
QueueUsage int `json:"queue_usage"`
|
|
|
|
TotalCount int64 `json:"total_count"`
|
|
|
|
Ios IosStatus `json:"ios"`
|
|
|
|
Android AndroidStatus `json:"android"`
|
2020-09-04 03:01:21 +00:00
|
|
|
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-07-13 15:58:47 +00:00
|
|
|
func InitAppStatus(conf config.ConfYaml) error {
|
|
|
|
logx.LogAccess.Info("Init App Status Engine as ", conf.Stat.Engine)
|
|
|
|
switch conf.Stat.Engine {
|
2016-04-22 09:54:00 +00:00
|
|
|
case "memory":
|
2016-05-02 09:03:08 +00:00
|
|
|
StatStorage = memory.New()
|
2016-05-02 11:42:21 +00:00
|
|
|
case "redis":
|
2021-07-13 15:58:47 +00:00
|
|
|
StatStorage = redis.New(conf)
|
2016-05-02 12:22:37 +00:00
|
|
|
case "boltdb":
|
2021-07-13 15:58:47 +00:00
|
|
|
StatStorage = boltdb.New(conf)
|
2016-09-19 08:19:20 +00:00
|
|
|
case "buntdb":
|
2021-07-13 15:58:47 +00:00
|
|
|
StatStorage = buntdb.New(conf)
|
2016-09-19 08:19:20 +00:00
|
|
|
case "leveldb":
|
2021-07-13 15:58:47 +00:00
|
|
|
StatStorage = leveldb.New(conf)
|
2018-04-16 09:26:15 +00:00
|
|
|
case "badger":
|
2021-07-13 15:58:47 +00:00
|
|
|
StatStorage = 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
|
|
|
|
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
|
|
|
}
|