-
Notifications
You must be signed in to change notification settings - Fork 14
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 #148 from 3scale-ops/metrics
Metrics
- Loading branch information
Showing
11 changed files
with
880 additions
and
719 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,87 @@ | ||
package stats | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// ensure Stats implements the prometheus Collector interface | ||
var _ prometheus.Collector = Stats{} | ||
|
||
// Descriptors used to create the metrics | ||
var ( | ||
requestCountDesc = prometheus.NewDesc( | ||
"marin3r_xdss_discovery_requests_total", | ||
"Number of discovery requests", | ||
[]string{"node_id", "resource_type", "pod_name"}, nil, | ||
) | ||
ackCountDesc = prometheus.NewDesc( | ||
"marin3r_xdss_discovery_ack_total", | ||
"Number of discovery ACK responses", | ||
[]string{"node_id", "resource_type", "pod_name"}, nil, | ||
) | ||
nackCountDesc = prometheus.NewDesc( | ||
"marin3r_xdss_discovery_nack_total", | ||
"Number of discovery NACK responses", | ||
[]string{"node_id", "resource_type", "pod_name"}, nil, | ||
) | ||
infoDesc = prometheus.NewDesc( | ||
"marin3r_xdss_discovery_info", | ||
"Information about the version a certain resource type is at", | ||
[]string{"node_id", "resource_type", "pod_name", "version"}, nil, | ||
) | ||
) | ||
|
||
// Describe is implemented with DescribeByCollect. That's possible because the | ||
// Collect method will always return the same 4 metrics with the same 4 | ||
// descriptors. | ||
func (xmc Stats) Describe(ch chan<- *prometheus.Desc) { | ||
prometheus.DescribeByCollect(xmc, ch) | ||
} | ||
|
||
// Collect dumps all the keys in the stats cache. Then it | ||
// creates constant metrics for each modeID/resourceType/pod on the fly based on the | ||
// dumped returned data. | ||
func (s Stats) Collect(ch chan<- prometheus.Metric) { | ||
|
||
items := s.DumpAll() | ||
for k, v := range items { | ||
key := NewKeyFromString(k) | ||
|
||
switch metric := key.StatName + "/" + key.Version; metric { | ||
|
||
case "request_counter/*": | ||
ch <- prometheus.MustNewConstMetric( | ||
requestCountDesc, | ||
prometheus.CounterValue, | ||
float64(v.Object.(int64)), | ||
key.NodeID, key.ResourceType, key.PodID, | ||
) | ||
|
||
case "ack_counter/*": | ||
ch <- prometheus.MustNewConstMetric( | ||
ackCountDesc, | ||
prometheus.CounterValue, | ||
float64(v.Object.(int64)), | ||
key.NodeID, key.ResourceType, key.PodID, | ||
) | ||
|
||
case "ack_counter/" + key.Version: | ||
ch <- prometheus.MustNewConstMetric( | ||
infoDesc, | ||
prometheus.UntypedValue, | ||
float64(0), | ||
key.NodeID, key.ResourceType, key.PodID, key.Version, | ||
) | ||
|
||
case "nack_counter/*": | ||
ch <- prometheus.MustNewConstMetric( | ||
nackCountDesc, | ||
prometheus.CounterValue, | ||
float64(v.Object.(int64)), | ||
key.NodeID, key.ResourceType, key.PodID, | ||
) | ||
|
||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.