Skip to content

Commit

Permalink
Improve metrics' naming
Browse files Browse the repository at this point in the history
Signed-off-by: VirtualTam <[email protected]>
  • Loading branch information
virtualtam committed Oct 8, 2018
1 parent 0aba6eb commit a235ac4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Metrics exposed

Counters:

- ``ccache_cache_hit_total``
- ``ccache_cache_miss_total``
- ``ccache_call_total``
- ``ccache_call_hit_total``
- ``ccache_called_for_link_total``
- ``ccache_called_for_preprocessing_total``
- ``ccache_unsupported_code_directive_total``
Expand All @@ -21,8 +21,8 @@ Gauges:

- ``ccache_cache_hit_ratio``
- ``ccache_cache_size_bytes``
- ``ccache_max_cache_size_bytes``
- ``ccache_files_in_cache``
- ``ccache_cache_size_max_bytes``
- ``ccache_cached_files``


Running with Docker Compose
Expand Down
40 changes: 22 additions & 18 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const (
)

type ccacheCollector struct {
cacheHit *prometheus.Desc
cacheMiss *prometheus.Desc
call *prometheus.Desc
callHit *prometheus.Desc
cacheHitRatio *prometheus.Desc
calledForLink *prometheus.Desc
calledForPreprocessing *prometheus.Desc
Expand All @@ -33,16 +33,16 @@ type ccacheCollector struct {

func NewCcacheCollector() *ccacheCollector {
return &ccacheCollector{
cacheHit: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "cache_hit_total"),
"Cache hit",
[]string{"mode"},
call: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "call_total"),
"Cache calls (total)",
nil,
),
cacheMiss: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "cache_miss_total"),
"Cache miss",
nil,
),
callHit: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "call_hit_total"),
"Cache hits",
[]string{"mode"},
nil,
),
cacheHitRatio: prometheus.NewDesc(
Expand Down Expand Up @@ -82,8 +82,8 @@ func NewCcacheCollector() *ccacheCollector {
nil,
),
filesInCache: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "files_in_cache"),
"Files in cache",
prometheus.BuildFQName(namespace, "", "cached_files"),
"Cached files",
nil,
nil,
),
Expand All @@ -94,7 +94,7 @@ func NewCcacheCollector() *ccacheCollector {
nil,
),
maxCacheSizeBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "max_cache_size_bytes"),
prometheus.BuildFQName(namespace, "", "cache_size_max_bytes"),
"Maximum cache size (bytes)",
nil,
nil,
Expand All @@ -103,8 +103,8 @@ func NewCcacheCollector() *ccacheCollector {
}

func (c *ccacheCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.cacheHit
ch <- c.cacheMiss
ch <- c.call
ch <- c.callHit
ch <- c.cacheHitRatio
ch <- c.calledForLink
ch <- c.calledForPreprocessing
Expand All @@ -126,9 +126,13 @@ func (c *ccacheCollector) Collect(ch chan<- prometheus.Metric) {
stats.Parse(string(out[:]))

// counters
ch <- prometheus.MustNewConstMetric(c.cacheHit, prometheus.CounterValue, float64(stats.CacheHitDirect), "direct")
ch <- prometheus.MustNewConstMetric(c.cacheHit, prometheus.CounterValue, float64(stats.CacheHitPreprocessed), "preprocessed")
ch <- prometheus.MustNewConstMetric(c.cacheMiss, prometheus.CounterValue, float64(stats.CacheMiss))
ch <- prometheus.MustNewConstMetric(
c.call,
prometheus.CounterValue,
float64(stats.CacheHitDirect+stats.CacheHitPreprocessed+stats.CacheMiss),
)
ch <- prometheus.MustNewConstMetric(c.callHit, prometheus.CounterValue, float64(stats.CacheHitDirect), "direct")
ch <- prometheus.MustNewConstMetric(c.callHit, prometheus.CounterValue, float64(stats.CacheHitPreprocessed), "preprocessed")
ch <- prometheus.MustNewConstMetric(c.calledForLink, prometheus.CounterValue, float64(stats.CalledForLink))
ch <- prometheus.MustNewConstMetric(c.calledForPreprocessing, prometheus.CounterValue, float64(stats.CalledForPreprocessing))
ch <- prometheus.MustNewConstMetric(c.unsupportedCodeDirective, prometheus.CounterValue, float64(stats.UnsupportedCodeDirective))
Expand Down
11 changes: 7 additions & 4 deletions docker/ccache-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
"tableColumn": "",
"targets": [
{
"expr": "sum(ccache_cache_hit_total)",
"expr": "sum(ccache_call_hit_total)",
"format": "time_series",
"intervalFactor": 1,
"refId": "A"
Expand Down Expand Up @@ -332,8 +332,9 @@
"tableColumn": "",
"targets": [
{
"expr": "ccache_cache_miss_total",
"expr": "ccache_call_total\n- ignoring(mode) ccache_call_hit_total{mode=\"direct\"}\n- ignoring(mode) ccache_call_hit_total{mode=\"preprocessed\"}",
"format": "time_series",
"hide": false,
"intervalFactor": 1,
"refId": "A"
}
Expand Down Expand Up @@ -392,15 +393,17 @@
"steppedLine": false,
"targets": [
{
"expr": "ccache_cache_hit_total",
"expr": "ccache_call_hit_total",
"format": "time_series",
"hide": false,
"intervalFactor": 1,
"legendFormat": "Cache hit ({{mode}})",
"refId": "A"
},
{
"expr": "ccache_cache_miss_total",
"expr": "ccache_call_total\n- ignoring(mode) ccache_call_hit_total{mode=\"direct\"}\n- ignoring(mode) ccache_call_hit_total{mode=\"preprocessed\"}",
"format": "time_series",
"hide": false,
"intervalFactor": 1,
"legendFormat": "Cache miss",
"refId": "B"
Expand Down

0 comments on commit a235ac4

Please sign in to comment.