// Stats implements bind.Stats. func (c *Client) Stats(groups ...bind.StatisticGroup) (bind.Statistics, error) { s := bind.Statistics{} m := map[bind.StatisticGroup]bool{} for _, g := range groups { m[g] = true } var stats Statistics if m[bind.ServerStats] || m[bind.ViewStats] { if err := c.Get(ServerPath, &stats); err != nil { return s, err } s.Server.BootTime = stats.Server.BootTime s.Server.ConfigTime = stats.Server.ConfigTime for _, c := range stats.Server.Counters { switch c.Type { case opcode: s.Server.IncomingRequests = c.Counters case qtype: s.Server.IncomingQueries = c.Counters case nsstat: s.Server.NameServerStats = c.Counters } } for _, view := range stats.Views { v := bind.View{ Name: view.Name, Cache: view.Cache, } for _, c := range view.Counters { switch c.Type { case resqtype: v.ResolverQueries = c.Counters case resstats: v.ResolverStats = c.Counters } } s.Views = append(s.Views, v) } } if m[bind.TaskStats] { if err := c.Get(TasksPath, &stats); err != nil { return s, err } s.TaskManager = stats.Taskmgr } return s, nil }
// Stats implements bind.Stats. The BIND v2 API doesn't provide individual // endpoints for different statistic groups, the passed parameters don't have // any effect. func (c *Client) Stats(...bind.StatisticGroup) (bind.Statistics, error) { s := bind.Statistics{} root := Isc{} if err := c.Get("/", &root); err != nil { return s, err } stats := root.Bind.Statistics s.Server.BootTime = stats.Server.BootTime for _, t := range stats.Server.QueriesIn { s.Server.IncomingQueries = append(s.Server.IncomingQueries, counter(t)) } for _, t := range stats.Server.Requests { s.Server.IncomingRequests = append(s.Server.IncomingRequests, counter(t)) } for _, t := range stats.Server.NSStats { s.Server.NameServerStats = append(s.Server.NameServerStats, counter(t)) } for _, view := range stats.Views { v := bind.View{ Name: view.Name, Cache: view.Cache, } for _, t := range view.Rdtype { v.ResolverQueries = append(v.ResolverQueries, counter(t)) } for _, t := range view.Resstat { v.ResolverStats = append(v.ResolverStats, counter(t)) } s.Views = append(s.Views, v) } s.TaskManager = stats.Taskmgr return s, nil }