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

MINOR: Add ClearCounters() and ClearCountersAll() #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions runtime/counters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package runtime

// ClearCounters sets all max counters to zero using the runtime API
// To reset all counters see ClearAllCounters()
// REF: https://www.haproxy.com/documentation/haproxy-runtime-api/reference/clear-counters/
func (s *SingleRuntime) ClearCounters() error {
_, err := s.ExecuteWithResponse("clear counters")
return err
}

// ClearAllCounters sets all counters to zero using the runtime API
// REF: https://www.haproxy.com/documentation/haproxy-runtime-api/reference/clear-counters-all/
func (s *SingleRuntime) ClearAllCounters() error {
_, err := s.ExecuteWithResponse("clear counters all")
return err
}
4 changes: 4 additions & 0 deletions runtime/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ type Info interface {
type Manage interface {
// Reloads HAProxy's configuration file. Similar to SIGUSR2. Returns the startup logs.
Reload() (string, error)
// Clears max counters
ClearCounters() error
// Clears counters
ClearAllCounters() error
}

type Raw interface {
Expand Down
10 changes: 10 additions & 0 deletions runtime/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func (c *client) initWithMasterSocket(opt options.RuntimeOptions) error {
return nil
}

// ClearCounters resets max counts from socket
func (c *client) ClearCounters() error {
return c.runtime.ClearCounters()
}

// ClearAllCounters resets all counters from socket
func (c *client) ClearAllCounters() error {
return c.runtime.ClearAllCounters()
}

// GetStats returns stats from the socket
func (c *client) GetStats() models.NativeStats {
result := c.runtime.GetStats()
Expand Down