From 3dac9c76e9cb1b62481090721ab3f71437aab05d Mon Sep 17 00:00:00 2001 From: Boris Date: Thu, 20 Jan 2022 15:12:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20IndexRefresh;?= =?UTF-8?q?=20=D0=92=20=D0=BA=D0=B0=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B5=20?= =?UTF-8?q?docs=5Fcount=20=D0=BE=D1=82=D0=B4=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= =?UTF-8?q?=20indexing.index=5Ftotal=20-=20=D0=BA=D0=BE=D0=BB-=D0=B2=D0=BE?= =?UTF-8?q?=20index-=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 14 -------------- collector.go | 6 ++++-- main.go | 19 ------------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/client.go b/client.go index f2eeb96..af2c279 100644 --- a/client.go +++ b/client.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - "time" elasticsearch "github.com/elastic/go-elasticsearch/v7" ) @@ -74,16 +73,3 @@ func (c *Client) GetInfo() (map[string]interface{}, error) { return r, nil } - -func (c *Client) RefreshIndices() error { - log.Debug("refresh indices") - resp, err := c.es.Indices.Refresh( - c.es.Indices.Refresh.WithIndex([]string{fmt.Sprintf("*-%s", time.Now().Format("2006.01.02"))}...), - ) - defer resp.Body.Close() - if err != nil { - return fmt.Errorf("error getting indices stats: ", err) - } - return nil - -} diff --git a/collector.go b/collector.go index 5f4d3e4..c319eec 100644 --- a/collector.go +++ b/collector.go @@ -82,8 +82,10 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { data := v.(map[string]interface{}) primaries := data["primaries"].(map[string]interface{}) - docs := primaries["docs"].(map[string]interface{}) - count := docs["count"].(float64) + // docs := primaries["docs"].(map[string]interface{}) + // count := docs["count"].(float64) + docs := primaries["indexing"].(map[string]interface{}) + count := docs["index_total"].(float64) ch <- prometheus.MustNewConstMetric(c.docsCount, prometheus.GaugeValue, count, index, indexGrouplabel) store := primaries["store"].(map[string]interface{}) diff --git a/main.go b/main.go index db749a8..374c652 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "net/http" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -43,8 +42,6 @@ var ( insecure = kingpin.Flag("insecure", "Allow insecure server connections when using SSL."). Default("false").Bool() - refreshinterval = kingpin.Flag("refreshinterval", "Period in seconds to refresh daily indices.").Default("300").Int() - projectName = kingpin.Flag("project", "Project name").String() ) @@ -60,22 +57,6 @@ func main() { if err := setLogFormat(*logFormat); err != nil { log.Fatal(err) } - - refreshTicker := time.NewTicker(time.Duration(*refreshinterval) * time.Second) - client, err := NewClient([]string{*address}, *insecure) - if err != nil { - log.Fatalf("error creating the client: %v", err) - } - go func() { - for range refreshTicker.C { - err := client.RefreshIndices() - if err != nil { - log.Fatalf("error refreshing index: %v", err) - } - } - }() - defer refreshTicker.Stop() - http.Handle(*metricsPath, promhttp.Handler()) http.HandleFunc("/healthz", healthCheck) http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {