From 469bfc929cae771e221129ffc0ac17419f152480 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 26 Oct 2019 20:23:49 +0200 Subject: [PATCH] exporter: remove 'ccache' from struct and method names Signed-off-by: VirtualTam --- cmd/ccache_exporter/main.go | 4 ++-- collector.go | 10 +++++----- parser.go | 24 ------------------------ statistics.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 statistics.go diff --git a/cmd/ccache_exporter/main.go b/cmd/ccache_exporter/main.go index 1fc9e26..2ad92ab 100644 --- a/cmd/ccache_exporter/main.go +++ b/cmd/ccache_exporter/main.go @@ -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) { diff --git a/collector.go b/collector.go index b59c1b2..bf888f8 100644 --- a/collector.go +++ b/collector.go @@ -16,7 +16,7 @@ const ( namespace = "ccache" ) -type ccacheCollector struct { +type collector struct { call *prometheus.Desc callHit *prometheus.Desc cacheHitRatio *prometheus.Desc @@ -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)", @@ -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 @@ -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) diff --git a/parser.go b/parser.go index 61ebd21..f390b3e 100644 --- a/parser.go +++ b/parser.go @@ -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+(.+)`), diff --git a/statistics.go b/statistics.go new file mode 100644 index 0000000..4cea930 --- /dev/null +++ b/statistics.go @@ -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"` +}