Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

carbonserver: adds /admin/info endpoint for returning internal info #433

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,15 @@ func (c *Cache) GetRecentNewMetrics() []map[string]struct{} {
func (c *Cache) SetThrottle(throttle func(ps *points.Points, inCache bool) bool) {
c.throttle = throttle
}

func (c *Cache) GetInfo() map[string]interface{} {
s, ok := c.settings.Load().(*cacheSettings)
if !ok {
return map[string]interface{}{}
}

return map[string]interface{}{
"size": c.stat.size,
"limit": s.maxSize,
}
}
2 changes: 2 additions & 0 deletions carbon/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ func (app *App) Start(version string) (err error) {
return
}

carbonserver.RegisterInternalInfoHandler("cache", core.GetInfo)

app.Carbonserver = carbonserver
}
/* CARBONSERVER end */
Expand Down
20 changes: 20 additions & 0 deletions carbonserver/carbonserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"compress/gzip"
"context"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -258,6 +259,8 @@ type CarbonserverListener struct {
estimateSize func(metric string) (size, dataPoints int64)
quotaAndUsageMetrics chan []points.Points
quotaUsageReportFrequency time.Duration

interfalInfoCallbacks map[string]func() map[string]interface{}
}

type prometheus struct {
Expand Down Expand Up @@ -1569,6 +1572,16 @@ func (listener *CarbonserverListener) Listen(listen string) error {

fidx.trieIdx.getQuotaTree(w)
})
carbonserverMux.HandleFunc("/admin/info", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")

infos := map[string]map[string]interface{}{}
for name, f := range listener.interfalInfoCallbacks {
infos[name] = f()
}

json.NewEncoder(w).Encode(infos)
})

carbonserverMux.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "User-agent: *\nDisallow: /")
Expand Down Expand Up @@ -1773,3 +1786,10 @@ func (flc *fileListCache) close() error {

return nil
}

func (listener *CarbonserverListener) RegisterInternalInfoHandler(name string, f func() map[string]interface{}) {
if listener.interfalInfoCallbacks == nil {
listener.interfalInfoCallbacks = map[string]func() map[string]interface{}{}
}
listener.interfalInfoCallbacks[name] = f
}