Skip to content

Commit

Permalink
exporter: remove 'ccache' from struct and method names
Browse files Browse the repository at this point in the history
Signed-off-by: VirtualTam <[email protected]>
  • Loading branch information
virtualtam committed Oct 26, 2019
1 parent 027bf33 commit 469bfc9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cmd/ccache_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func main() {
listenAddr := flag.String("listenAddr", DefaultListenAddr, "Listen on this address")
flag.Parse()

ccacheCollector := ccache.NewCcacheCollector()
prometheus.MustRegister(ccacheCollector)
collector := ccache.NewCollector()
prometheus.MustRegister(collector)

http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
Expand Down
10 changes: 5 additions & 5 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
namespace = "ccache"
)

type ccacheCollector struct {
type collector struct {
call *prometheus.Desc
callHit *prometheus.Desc
cacheHitRatio *prometheus.Desc
Expand All @@ -30,8 +30,8 @@ type ccacheCollector struct {
maxCacheSizeBytes *prometheus.Desc
}

func NewCcacheCollector() *ccacheCollector {
return &ccacheCollector{
func NewCollector() *collector {
return &collector{
call: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "call_total"),
"Cache calls (total)",
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewCcacheCollector() *ccacheCollector {
}
}

func (c *ccacheCollector) Describe(ch chan<- *prometheus.Desc) {
func (c *collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.call
ch <- c.callHit
ch <- c.cacheHitRatio
Expand All @@ -115,7 +115,7 @@ func (c *ccacheCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.maxCacheSizeBytes
}

func (c *ccacheCollector) Collect(ch chan<- prometheus.Metric) {
func (c *collector) Collect(ch chan<- prometheus.Metric) {
out, err := exec.Command("ccache", "-s").Output()
if err != nil {
log.Fatal(err)
Expand Down
24 changes: 0 additions & 24 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,6 @@ import (
"github.com/alecthomas/units"
)

// Statistics represents information about ccache configuration and usage.
type Statistics struct {
CacheDirectory string `json:"cache_directory"`
PrimaryConfig string `json:"primary_config"`
SecondaryConfigReadonly string `json:"secondary_config_readonly"`
StatsTime time.Time `json:"stats_time"`
StatsZeroTime time.Time `json:"stats_zero_time"`
CacheHitDirect int `json:"cache_hit_direct"`
CacheHitPreprocessed int `json:"cache_hit_preprocessed"`
CacheMiss int `json:"cache_miss"`
CacheHitRate float64 `json:"cache_hit_rate"`
CacheHitRatio float64 `json:"cache_hit_ratio"`
CalledForLink int `json:"called_for_link"`
CalledForPreprocessing int `json:"called_for_preprocessing"`
UnsupportedCodeDirective int `json:"unsupported_code_directive"`
NoInputFile int `json:"no_input_file"`
CleanupsPerformed int `json:"cleanups_performed"`
FilesInCache int `json:"files_in_cache"`
CacheSize string `json:"cache_size"`
CacheSizeBytes units.MetricBytes `json:"cache_size_bytes"`
MaxCacheSize string `json:"max_cache_size"`
MaxCacheSizeBytes units.MetricBytes `json:"max_cache_size_bytes"`
}

var rules = map[string]*regexp.Regexp{
"cacheDirectory": regexp.MustCompile(`cache directory\s+(.+)`),
"primaryConfig": regexp.MustCompile(`primary config\s+(.+)`),
Expand Down
31 changes: 31 additions & 0 deletions statistics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ccache

import (
"time"

"github.com/alecthomas/units"
)

// Statistics represents information about ccache configuration and usage.
type Statistics struct {
CacheDirectory string `json:"cache_directory"`
PrimaryConfig string `json:"primary_config"`
SecondaryConfigReadonly string `json:"secondary_config_readonly"`
StatsTime time.Time `json:"stats_time"`
StatsZeroTime time.Time `json:"stats_zero_time"`
CacheHitDirect int `json:"cache_hit_direct"`
CacheHitPreprocessed int `json:"cache_hit_preprocessed"`
CacheMiss int `json:"cache_miss"`
CacheHitRate float64 `json:"cache_hit_rate"`
CacheHitRatio float64 `json:"cache_hit_ratio"`
CalledForLink int `json:"called_for_link"`
CalledForPreprocessing int `json:"called_for_preprocessing"`
UnsupportedCodeDirective int `json:"unsupported_code_directive"`
NoInputFile int `json:"no_input_file"`
CleanupsPerformed int `json:"cleanups_performed"`
FilesInCache int `json:"files_in_cache"`
CacheSize string `json:"cache_size"`
CacheSizeBytes units.MetricBytes `json:"cache_size_bytes"`
MaxCacheSize string `json:"max_cache_size"`
MaxCacheSizeBytes units.MetricBytes `json:"max_cache_size_bytes"`
}

0 comments on commit 469bfc9

Please sign in to comment.