Skip to content

Commit 87f1ef4

Browse files
committed
support deloy load metric
1 parent ccc1aec commit 87f1ef4

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.scannerwork
22
/.idea
3+
build/*
4+
qcloud.yml

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ lint:
1212
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION); \
1313
fi; \
1414
./bin/golangci-lint run ./...
15+
16+
deploy:
17+
env GOOS=linux GOARCH=amd64 go build -o "build/qcloud_exporter" ./cmd/qcloud-exporter/
18+

build/qcloud_exporter

-31.3 MB
Binary file not shown.

pkg/metric/metric.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ func (m *TcmMetric) LoadSeries(series []*TcmSeries) error {
3434
}
3535

3636
func (m *TcmMetric) GetLatestPromMetrics(repo TcmMetricRepository) (pms []prometheus.Metric, err error) {
37-
st := time.Now().Unix() - m.Conf.StatNumSamples*m.Conf.StatPeriodSeconds
37+
var st int64
38+
et := int64(0)
39+
now := time.Now().Unix()
40+
if m.Conf.StatDelaySeconds > 0 {
41+
st = now - m.Conf.StatPeriodSeconds - m.Conf.StatDelaySeconds
42+
et = now - m.Conf.StatDelaySeconds
43+
} else {
44+
st = now - m.Conf.StatNumSamples*m.Conf.StatPeriodSeconds
45+
}
3846

39-
samplesList, err := repo.ListSamples(m, st, 0)
47+
samplesList, err := repo.ListSamples(m, st, et)
4048
if err != nil {
4149
return nil, err
4250
}
@@ -69,12 +77,22 @@ func (m *TcmMetric) GetLatestPromMetrics(repo TcmMetricRepository) (pms []promet
6977
if err != nil {
7078
return nil, err
7179
}
72-
pm := prometheus.MustNewConstMetric(
73-
desc,
74-
prometheus.GaugeValue,
75-
point.Value,
76-
values...,
77-
)
80+
var pm prometheus.Metric
81+
if m.Conf.StatDelaySeconds > 0 {
82+
pm = prometheus.NewMetricWithTimestamp(time.Unix(int64(point.Timestamp), 0), prometheus.MustNewConstMetric(
83+
desc,
84+
prometheus.GaugeValue,
85+
point.Value,
86+
values...,
87+
))
88+
} else {
89+
pm = prometheus.MustNewConstMetric(
90+
desc,
91+
prometheus.GaugeValue,
92+
point.Value,
93+
values...,
94+
)
95+
}
7896
pms = append(pms, pm)
7997
}
8098
}

0 commit comments

Comments
 (0)