diff --git a/exporter.go b/exporter.go index deb79a14..d5a463bc 100644 --- a/exporter.go +++ b/exporter.go @@ -220,23 +220,22 @@ func NewRedisExporter(redisURI string, opts ExporterOptions) (*Exporter, error) // # Tile38 // based on https://tile38.com/commands/server/ - "aof_size": "aof_size_bytes", - "avg_item_size": "avg_item_size_bytes", - "cpus": "cpus_total", - "heap_released": "heap_released_bytes", - "heap_size": "heap_size_bytes", - "http_transport": "http_transport", - "in_memory_size": "in_memory_size_bytes", - "max_heap_size": "max_heap_size_bytes", - "mem_alloc": "mem_alloc_bytes", - "num_collections": "num_collections_total", - "num_hooks": "num_hooks_total", - "num_objects": "num_objects_total", - "num_points": "num_points_total", - "pointer_size": "pointer_size_bytes", - "read_only": "read_only", - "threads": "threads_total", - "version": "version", // since tile38 version 1.14.1 + "tile38_aof_size": "tile38_aof_size_bytes", + "tile38_avg_item_size": "tile38_avg_item_size_bytes", + "tile38_cpus": "tile38_cpus_total", + "tile38_heap_released": "tile38_heap_released_bytes", + "tile38_heap_size": "tile38_heap_size_bytes", + "tile38_http_transport": "tile38_http_transport", + "tile38_in_memory_size": "tile38_in_memory_size_bytes", + "tile38_max_heap_size": "tile38_max_heap_size_bytes", + "tile38_mem_alloc": "tile38_mem_alloc_bytes", + "tile38_num_collections": "tile38_num_collections_total", + "tile38_num_hooks": "tile38_num_hooks_total", + "tile38_num_objects": "tile38_num_objects_total", + "tile38_num_points": "tile38_num_points_total", + "tile38_pointer_size": "tile38_pointer_size_bytes", + "tile38_read_only": "tile38_read_only", + "tile38_threads": "tile38_threads_total", }, metricMapCounters: map[string]string{ @@ -846,10 +845,9 @@ func (e *Exporter) extractTile38Metrics(ch chan<- prometheus.Metric, c redis.Con } for i := 0; i < len(info); i += 2 { - log.Debugf("tile38: %s:%s", info[i], info[i+1]) - - fieldKey := info[i] + fieldKey := "tile38_" + info[i] fieldValue := info[i+1] + log.Debugf("tile38 key:%s val:%s", fieldKey, fieldValue) if !e.includeMetric(fieldKey) { continue @@ -887,10 +885,10 @@ func (e *Exporter) parseAndRegisterConstMetric(ch chan<- prometheus.Metric, fiel switch fieldValue { - case "ok": + case "ok", "true": val = 1 - case "err", "fail": + case "err", "fail", "false": val = 0 default: diff --git a/exporter_test.go b/exporter_test.go index e4c2ec0c..71383067 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -223,17 +223,18 @@ func TestTile38(t *testing.T) { }() found := false + want := "tile38_threads_total" for m := range chM { - if strings.Contains(m.Desc().String(), "cpus_total") { + fmt.Println(m.Desc().String()) + if strings.Contains(m.Desc().String(), want) { found = true - break } } if isTile38 && !found { - t.Errorf("cpus_total was *not* found in tile38 metrics but expected") + t.Errorf("%s was *not* found in tile38 metrics but expected", want) } else if !isTile38 && found { - t.Errorf("cpus_total was *found* in tile38 metrics but *not* expected") + t.Errorf("%s was *found* in tile38 metrics but *not* expected", want) } } } @@ -253,7 +254,6 @@ func TestExportClientList(t *testing.T) { for m := range chM { if strings.Contains(m.Desc().String(), "connected_clients_details") { found = true - break } } @@ -812,7 +812,6 @@ func TestKeySizeList(t *testing.T) { for m := range chM { if strings.Contains(m.Desc().String(), "test_key_size") { found = true - break } } @@ -908,12 +907,9 @@ func TestCommandStats(t *testing.T) { func TestIncludeSystemMemoryMetric(t *testing.T) { for _, inc := range []bool{false, true} { r := prometheus.NewRegistry() - prometheus.DefaultGatherer = r - prometheus.DefaultRegisterer = r - - ts := httptest.NewServer(promhttp.Handler()) + ts := httptest.NewServer(promhttp.HandlerFor(r, promhttp.HandlerOpts{})) e, _ := NewRedisExporter(os.Getenv("TEST_REDIS_URI"), ExporterOptions{Namespace: "test", InclSystemMetrics: inc}) - prometheus.Register(e) + r.Register(e) body := downloadURL(t, ts.URL+"/metrics") if inc && !strings.Contains(body, "total_system_memory_bytes") {