메트릭 생성 파라미터 변경
This commit is contained in:
@ -5,9 +5,11 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -60,30 +62,36 @@ func (mc *metricCollection) metricWriter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var metricWriterFlag sync.Once
|
var NewMetric func(MetricType, string, string, map[string]string) MetricWriter
|
||||||
|
|
||||||
func NewMetric(mt MetricType, name string, help string, constLabel ...string) (writer MetricWriter) {
|
func init() {
|
||||||
metricWriterFlag.Do(func() {
|
NewMetric = func(MetricType, string, string, map[string]string) MetricWriter {
|
||||||
|
return func(val float64) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
ppid := os.Getppid()
|
||||||
|
if parent, _ := os.FindProcess(ppid); parent != nil {
|
||||||
|
filename := fmt.Sprintf(`/proc/%d/stat`, os.Getppid())
|
||||||
|
if fn, err := os.ReadFile(filename); err == nil {
|
||||||
|
if string(fn) == "houston" {
|
||||||
|
logger.Println("metrics are activated for houston")
|
||||||
go mc.metricWriter()
|
go mc.metricWriter()
|
||||||
})
|
NewMetric = newMetricImpl
|
||||||
|
} else {
|
||||||
|
logger.Println("metrics are NOT activated")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Println("metrics are NOT activated")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Println("metrics are NOT activated")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMetricImpl(mt MetricType, name string, help string, constLabels map[string]string) (writer MetricWriter) {
|
||||||
hash := md5.New()
|
hash := md5.New()
|
||||||
hash.Write([]byte(name))
|
hash.Write([]byte(name))
|
||||||
|
|
||||||
var constLabels map[string]string
|
|
||||||
if len(constLabel) > 0 {
|
|
||||||
constLabels = make(map[string]string)
|
|
||||||
for i := 0; i < len(constLabel); i = i + 2 {
|
|
||||||
constLabels[constLabel[i]] = ""
|
|
||||||
hash.Write([]byte(constLabel[i]))
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 1; i < len(constLabel); i = i + 2 {
|
|
||||||
constLabels[constLabel[i-1]] = constLabel[i]
|
|
||||||
hash.Write([]byte(constLabel[i]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
key := hex.EncodeToString(hash.Sum(nil))[:metric_key_size]
|
key := hex.EncodeToString(hash.Sum(nil))[:metric_key_size]
|
||||||
temp, _ := json.Marshal(MetricDescription{
|
temp, _ := json.Marshal(MetricDescription{
|
||||||
Key: key,
|
Key: key,
|
||||||
|
|||||||
Reference in New Issue
Block a user