custom metric 추가
This commit is contained in:
@ -4,10 +4,12 @@ import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -17,7 +19,9 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/metric"
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||
)
|
||||
@ -138,30 +142,6 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
||||
}
|
||||
|
||||
return f.Name(), matches, nil
|
||||
// defer func() {
|
||||
// tempname := f.Name()
|
||||
// f.Close()
|
||||
|
||||
// resp, _ := http.Post(req.Url, "application/zip", f)
|
||||
// if resp != nil && resp.Body != nil {
|
||||
// resp.Body.Close()
|
||||
// }
|
||||
// os.Remove(tempname)
|
||||
// if del, err := strconv.ParseBool(req.DeleteAfterUploaded); del && err == nil {
|
||||
// for _, file := range matches {
|
||||
// if strings.HasSuffix(file, except) {
|
||||
// continue
|
||||
// }
|
||||
// os.Remove(file)
|
||||
// }
|
||||
// }
|
||||
// }()
|
||||
|
||||
// Create a new zip archive.
|
||||
|
||||
//}(f)
|
||||
|
||||
//return nil
|
||||
}
|
||||
|
||||
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *procmeta {
|
||||
@ -214,7 +194,7 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
return err
|
||||
}
|
||||
|
||||
stdReader := func(r io.ReadCloser) {
|
||||
stdReader := func(childProcName string, r io.ReadCloser) {
|
||||
defer func() {
|
||||
reco := recover()
|
||||
if reco != nil {
|
||||
@ -248,12 +228,53 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
}
|
||||
}()
|
||||
|
||||
readingMetric := false
|
||||
var metricBuffer []byte
|
||||
metricValues := make(map[string]metricValueAccessor)
|
||||
|
||||
for {
|
||||
buff, err := reader.ReadBytes('\n')
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
if readingMetric {
|
||||
metricBuffer = append(metricBuffer, buff...)
|
||||
} else if buff[0] == metric.METRIC_HEAD_INLINE {
|
||||
readingMetric = true
|
||||
metricBuffer = append(metricBuffer, buff[1:]...)
|
||||
}
|
||||
|
||||
if readingMetric {
|
||||
if metricBuffer[len(metricBuffer)-2] == metric.METRIC_TAIL_INLINE {
|
||||
readingMetric = false
|
||||
|
||||
metricBuffer = metricBuffer[:len(metricBuffer)-2]
|
||||
if metricBuffer[0] == '{' {
|
||||
var metric metric.MetricDescription
|
||||
json.Unmarshal(metricBuffer, &metric)
|
||||
|
||||
exporter := newExporterForPrometheus()
|
||||
accessor := exporter.registMetric(childProcName, metric)
|
||||
prometheus.MustRegister(exporter)
|
||||
|
||||
metricValues[metric.Key] = accessor
|
||||
} else {
|
||||
keybytes := metricBuffer[:8]
|
||||
valbits := binary.BigEndian.Uint64(metricBuffer[8:])
|
||||
val := math.Float64frombits(valbits)
|
||||
|
||||
if accessor, ok := metricValues[string(keybytes)]; ok {
|
||||
accessor.set(val)
|
||||
}
|
||||
}
|
||||
|
||||
metricBuffer = metricBuffer[:0]
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
for written := 0; written < len(buff); {
|
||||
n, err := targetFile.Write(buff)
|
||||
if err != nil {
|
||||
@ -282,7 +303,7 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
}
|
||||
}
|
||||
|
||||
go stdReader(stdout)
|
||||
go stdReader(meta.name, stdout)
|
||||
|
||||
logger.Println("startChildProcess :", meta.cmd.Args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user