| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package bind |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | |
| 9 | "github.com/netdata/netdata/go/plugins/pkg/web" |
| 10 | ) |
| 11 | |
| 12 | type serverStats = jsonServerStats |
| 13 | |
| 14 | type jsonServerStats struct { |
| 15 | OpCodes map[string]int64 |
| 16 | QTypes map[string]int64 |
| 17 | NSStats map[string]int64 |
| 18 | SockStats map[string]int64 |
| 19 | Views map[string]jsonView |
| 20 | } |
| 21 | |
| 22 | type jsonView struct { |
| 23 | Resolver jsonViewResolver |
| 24 | } |
| 25 | |
| 26 | type jsonViewResolver struct { |
| 27 | Stats map[string]int64 |
| 28 | QTypes map[string]int64 |
| 29 | CacheStats map[string]int64 |
| 30 | } |
| 31 | |
| 32 | func newJSONClient(client *http.Client, request web.RequestConfig) *jsonClient { |
| 33 | return &jsonClient{httpClient: client, request: request} |
| 34 | } |
| 35 | |
| 36 | type jsonClient struct { |
| 37 | httpClient *http.Client |
| 38 | request web.RequestConfig |
| 39 | } |
| 40 | |
| 41 | func (c jsonClient) serverStats() (*serverStats, error) { |
| 42 | req, err := web.NewHTTPRequestWithPath(c.request, "/server") |
| 43 | if err != nil { |
| 44 | return nil, fmt.Errorf("failed to create HTTP request: %v", err) |
| 45 | } |
| 46 | |
| 47 | var stats jsonServerStats |
| 48 | |
| 49 | if err := web.DoHTTP(c.httpClient).RequestJSON(req, &stats); err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | |
| 53 | return &stats, nil |
| 54 | } |