serverstats

package
v2.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 34 Imported by: 0

README

Server stats plugin for YAGPDB

Records and shows stats for individual servers.

Current stats

Simple temporary stats:

  • Messages last hour
  • Users joined/left today
  • Messages today, per channel with bar graphs
  • Current online users
  • Total amount of users
Planned soon

More peristent graphable stats:

  • Users joined/left day to day chart
  • Avg. users online day to day
  • Messages day to day per channel
Redis layout

To count 24h stats yagpdb stores things inside sorted sets with unix timestamp as score, it will then routinely walk over all stats and remove those with screos of less then current unix time - 24h, this might be expensive later on, if so i might have to figure out a better way.

guild_stats_msg_channel:{guildid} - sorted set: key: channelid:msg_id, score: unix timestamp guild_stats_members_changed:{guildid} - sorted set: key: joined|left:userid, score: unix timestamp

Documentation

Index

Constants

View Source
const (
	RedisKeyLastHourlyRan = "serverstats_last_hourly_worker_ran"
)

Variables

View Source
var PageHTML string
View Source
var WebConfigCache = rcache.NewInt(cacheConfigFetcher, time.Minute)
View Source
var WebStatsCache = rcache.New(cacheChartFetcher, time.Minute)

Functions

func HandleMessageCreate

func HandleMessageCreate(evt *eventsystem.EventData) (retry bool, err error)

func HandleSaveStatsSettings

func HandleSaveStatsSettings(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleStatsCharts

func HandleStatsCharts(w http.ResponseWriter, r *http.Request, isPublicAccess bool) interface{}

func HandleStatsHtml

func HandleStatsHtml(w http.ResponseWriter, r *http.Request, isPublicAccess bool) (web.TemplateData, error)

Somewhat dirty - should clean up this mess sometime

func HandleStatsJson

func HandleStatsJson(w http.ResponseWriter, r *http.Request, isPublicAccess bool) interface{}

func MarkGuildAsToBeChecked

func MarkGuildAsToBeChecked(guildID int64)

func RegisterPlugin

func RegisterPlugin()

func RoundHour

func RoundHour(t time.Time) time.Time

RoundHour rounds a time.Time down to the hour

func StartMigrationToV2Format

func StartMigrationToV2Format() error

Types

type ChannelStats

type ChannelStats struct {
	Name  string `json:"name"`
	Count int64  `json:"count"`
}

type ChartDataPeriod

type ChartDataPeriod struct {
	T          time.Time `json:"t"`
	Joins      int       `json:"joins"`
	Leaves     int       `json:"leaves"`
	NumMembers int       `json:"num_members"`
	MaxOnline  int       `json:"max_online"`
	Messages   int       `json:"num_messages"`
}

func RetrieveChartDataPeriods

func RetrieveChartDataPeriods(ctx context.Context, guildID int64, t time.Time, days int) ([]*ChartDataPeriod, error)

type ChartResponse

type ChartResponse struct {
	Days int                `json:"days"`
	Data []*ChartDataPeriod `json:"data"`
}

func CacheGetCharts

func CacheGetCharts(guildID int64, days int, ctx context.Context) *ChartResponse

type CompressedStats

type CompressedStats struct {
	GuildID int64
	T       time.Time

	NumMessages  int
	MaxOnline    int
	TotalMembers int
	Joins        int
	Leaves       int
	MaxVoice     int
}

type Compressor

type Compressor struct {
	// contains filtered or unexported fields
}

func (*Compressor) RunCompressionLegacy

func (c *Compressor) RunCompressionLegacy(t time.Time) error

type DailyStats

type DailyStats struct {
	ChannelMessages map[string]*ChannelStats `json:"channels_messages"`
	JoinedDay       int                      `json:"joined_day"`
	LeftDay         int                      `json:"left_day"`
	Online          int                      `json:"online_now"`
	TotalMembers    int                      `json:"total_members_now"`
}

func RetrieveDailyStats

func RetrieveDailyStats(t time.Time, guildID int64) (*DailyStats, error)

type FormData

type FormData struct {
	Public         bool
	IgnoreChannels []int64 `valid:"channel,false"`
}

type GuildStatsFrame

type GuildStatsFrame struct {
	Messages      int
	TotalMembers  int
	OnlineMembers int
	Joins         int
	Leaves        int
}

type MigrationProgress

type MigrationProgress struct {
	MsgPeriods    *MigrationSubProgress
	MemberPeriods *MigrationSubProgress
}

func GetMigrationV2Progress

func GetMigrationV2Progress() (*MigrationProgress, error)

type MigrationSubProgress

type MigrationSubProgress struct {
	LastUpdated time.Time
	LastID      int64
	Running     bool
}

func (*MigrationSubProgress) IsRunning

func (m *MigrationSubProgress) IsRunning() bool

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (*Plugin) AddCommands

func (p *Plugin) AddCommands()

func (*Plugin) BotInit

func (p *Plugin) BotInit()

func (*Plugin) InitWeb

func (p *Plugin) InitWeb()

func (*Plugin) LoadServerHomeWidget

func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func (*Plugin) OnNewPremiumGuild

func (p *Plugin) OnNewPremiumGuild(guildID int64) error

func (*Plugin) PluginInfo

func (p *Plugin) PluginInfo() *common.PluginInfo

func (*Plugin) RunBackgroundWorker

func (p *Plugin) RunBackgroundWorker()

func (*Plugin) StopBackgroundWorker

func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup)

type QueuedAction

type QueuedAction struct {
	GuildID    int64
	TotalCount int
	Joins      int
	Leaves     int
}

type ServerStatsConfig

type ServerStatsConfig struct {
	Public         bool
	IgnoreChannels string

	ParsedChannels []int64
}

ServerStatsConfig represents a configuration for a server reason we dont reference the model directly is because i need to figure out a way to migrate them over to the new schema, painlessly.

func BotCachedFetchGuildConfig

func BotCachedFetchGuildConfig(ctx context.Context, guildID int64) (*ServerStatsConfig, error)

func GetConfig

func GetConfig(ctx context.Context, GuildID int64) (*ServerStatsConfig, error)

func GetConfigWeb

func GetConfigWeb(guildID int64) *ServerStatsConfig

func (*ServerStatsConfig) ParseChannels

func (s *ServerStatsConfig) ParseChannels()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL