-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from hikhvar/improve-client-resilience
Improved client resilience
- Loading branch information
Showing
5 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package collector | ||
|
||
import ( | ||
"github.com/hikhvar/ts3exporter/pkg/serverquery" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const clientSubsystem = "client" | ||
|
||
// InstrumentedClient provides metrics from a serverquery client | ||
type InstrumentedClient interface { | ||
Metrics() serverquery.ClientMetrics | ||
} | ||
|
||
// Client is a collector providing metrics of the internal serverquery client | ||
type Client struct { | ||
source InstrumentedClient | ||
|
||
Failed *prometheus.Desc | ||
Success *prometheus.Desc | ||
} | ||
|
||
func NewClient(c InstrumentedClient) *Client { | ||
return &Client{ | ||
source: c, | ||
Failed: prometheus.NewDesc(fqdn(clientSubsystem, "commands_failed_total"), "total failed server query command", nil, nil), | ||
Success: prometheus.NewDesc(fqdn(clientSubsystem, "commands_successful_total"), "total successful server query command", nil, nil), | ||
} | ||
} | ||
|
||
func (c *Client) Describe(desc chan<- *prometheus.Desc) { | ||
prometheus.DescribeByCollect(c, desc) | ||
} | ||
|
||
func (c *Client) Collect(met chan<- prometheus.Metric) { | ||
m := c.source.Metrics() | ||
met <- prometheus.MustNewConstMetric(c.Success, prometheus.CounterValue, float64(m.Success())) | ||
met <- prometheus.MustNewConstMetric(c.Failed, prometheus.CounterValue, float64(m.Failed())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package serverquery | ||
|
||
type ClientMetrics struct { | ||
successful int | ||
failed int | ||
} | ||
|
||
func (c *ClientMetrics) CountFailure() { | ||
c.failed = c.failed + 1 | ||
} | ||
|
||
func (c *ClientMetrics) CountSuccess() { | ||
c.successful = c.successful + 1 | ||
} | ||
|
||
func (c *ClientMetrics) Success() int { | ||
return c.successful | ||
} | ||
|
||
func (c *ClientMetrics) Failed() int { | ||
return c.failed | ||
} |