github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/metrics/custom_metics.go (about)

     1  package metrics
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/tidwall/gjson"
     7  )
     8  
     9  type (
    10  	CustomMetrics interface {
    11  		Submit(gjson.Result) error
    12  	}
    13  )
    14  
    15  type (
    16  	metrics struct {
    17  		account string // account use wallet address (if exists) or account id
    18  		project string // project use project name
    19  		writer  *SQLBatcher
    20  	}
    21  )
    22  
    23  func NewCustomMetric(account string, project string) CustomMetrics {
    24  	return &metrics{
    25  		account: account,
    26  		project: project,
    27  		writer:  NewSQLBatcher("INSERT INTO ws_metrics.customized_metrics VALUES"),
    28  	}
    29  }
    30  
    31  func (m *metrics) Submit(obj gjson.Result) error {
    32  	objStr := obj.String()
    33  	return m.writer.Insert(fmt.Sprintf(`now(), '%s', '%s', '%s'`, m.account, m.project, objStr))
    34  }