Skip to content

Commit

Permalink
Убрал IndexRefresh; В качестве docs_count отдается indexing.index_tot…
Browse files Browse the repository at this point in the history
…al - кол-во index-операций
  • Loading branch information
Boris committed Jan 20, 2022
1 parent 15f0dc5 commit 3dac9c7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
14 changes: 0 additions & 14 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"time"

elasticsearch "github.com/elastic/go-elasticsearch/v7"
)
Expand Down Expand Up @@ -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

}
6 changes: 4 additions & 2 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
19 changes: 0 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -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()
)

Expand All @@ -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) {
Expand Down

0 comments on commit 3dac9c7

Please sign in to comment.