Skip to content

Commit

Permalink
fix: fix nginx host tag error
Browse files Browse the repository at this point in the history
  • Loading branch information
谭彪 committed Sep 19, 2024
1 parent 8d17788 commit 4dc62b8
Show file tree
Hide file tree
Showing 132 changed files with 81 additions and 107 deletions.
Empty file modified internal/export/doc/en/apis.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/changelog.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/confd.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-batch-deploy.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-conf.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-daemonset-deploy.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-dql-how-to.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-filter.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-input-conf.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-install.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-monitor.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-offline-install.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-refer-table.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-service-how-to.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-tools-how-to.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/datakit-update.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/dca.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/development.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/election.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/git-config-how-to.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/apache.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/beats_output.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/cassandra.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/clickhousev1.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/cloudprober.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/cockroachdb.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/consul.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/container-log.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/container.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/coredns.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/cpu.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/datakit-logging-how.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/datakit-logging.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/datakit-tracing-introduction.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/datakit-tracing-struct.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/datakit-tracing.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/db2.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-cpp.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-golang.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-java.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-nodejs.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-php.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-python.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace-ruby.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ddtrace.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/dialtesting_json.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/disk.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/diskio.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/doc-logging.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/doris.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ebpf.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/elasticsearch.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/etcd.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/external.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/flinkv1.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/gitlab.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/gpu_smi.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/host_processes.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/hostdir.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/hostobject.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/iis.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/influxdb.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ipmi.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/jaeger.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/jenkins.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/jvm.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/kafka.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/kafkamq.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/kubernetes-crd.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/kubernetes-prom.md
100755 → 100644
Empty file.
Empty file.
Empty file modified internal/export/doc/en/inputs/logfwd.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/logfwdserver.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/logging-pipeline-bench.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/logging.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/logging_socket.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/logstreaming.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/mem.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/memcached.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/mongodb.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/mysql.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/net.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/netflow.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/netstat.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/nginx.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/nsq.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/oceanbase.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/opentelemetry-go.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/opentelemetry-java.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/opentelemetry.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/oracle.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/postgresql.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/profile.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/prom.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/prom_remote_write.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/promtail.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/proxy.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/python-profiling.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/rabbitmq.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/redis.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/rum.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/sec-checker.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/sensors.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/skywalking.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/smart.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/snmp.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/socket.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/solr.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/sqlserver.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/ssh.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/statsd.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/swap.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/system.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/tdengine.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/telegraf.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/tomcat.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/windows_event.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/inputs/zipkin.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/k8s-config-how-to.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/en/why-no-data.md
100755 → 100644
Empty file.
Empty file modified internal/export/doc/zh/inputs/datakit-trace-performance.md
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions internal/plugins/inputs/nginx/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Input struct {
UsePlusAPI bool `toml:"use_plus_api"`
Log *ngxlog `toml:"log"`
Tags map[string]string `toml:"tags"`
mergedTags map[string]string

UpState int

Expand Down
20 changes: 10 additions & 10 deletions internal/plugins/inputs/nginx/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ipt *Input) getStubStatusModuleMetric(port int) {

kvs := make(point.KVs, 0, 9)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for k, v := range ipt.Tags {
kvs = kvs.MustAddTag(k, v)
Expand Down Expand Up @@ -176,7 +176,7 @@ func (ipt *Input) handVTSResponse(r io.Reader, port int) {
func (ipt *Input) makeConnectionsLine(vtsResp NginxVTSResponse) {
kvs := make(point.KVs, 0, 12)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for k, v := range vtsResp.tags {
kvs = kvs.MustAddTag(k, v)
Expand All @@ -198,7 +198,7 @@ func (ipt *Input) makeServerZoneLine(vtsResp NginxVTSResponse) {
for k, v := range vtsResp.ServerZones {
kvs := make(point.KVs, 0, 13)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range vtsResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand All @@ -223,7 +223,7 @@ func (ipt *Input) makeUpstreamZoneLine(vtsResp NginxVTSResponse) {
for _, upstream := range upstreams {
kvs := make(point.KVs, 0, 14)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range vtsResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand All @@ -249,7 +249,7 @@ func (ipt *Input) makeCacheZoneLine(vtsResp NginxVTSResponse) {
for cacheName, cacheZone := range vtsResp.CacheZones {
kvs := make(point.KVs, 0, 17)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range vtsResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand Down Expand Up @@ -341,7 +341,7 @@ func (ipt *Input) handlePlusAPIResponse(r io.Reader, plusAPIResp *NginxPlusAPIRe
func (ipt *Input) makeNginxLine(plusAPIResp NginxPlusAPIResponse) {
kvs := make(point.KVs, 0, 10)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for k, v := range plusAPIResp.tags {
kvs = kvs.MustAddTag(k, v)
Expand All @@ -358,7 +358,7 @@ func (ipt *Input) makeServerLine(plusAPIResp NginxPlusAPIResponse) {
for k, v := range plusAPIResp.Servers {
kvs := make(point.KVs, 0, 20)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range plusAPIResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand Down Expand Up @@ -392,7 +392,7 @@ func (ipt *Input) makeUpStreamLine(plusAPIResp NginxPlusAPIResponse) {
for _, upstream := range upstreams.Peers {
kvs := make(point.KVs, 0, 20)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range plusAPIResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand Down Expand Up @@ -424,7 +424,7 @@ func (ipt *Input) makeCacheLine(plusAPIResp NginxPlusAPIResponse) {
for k, v := range plusAPIResp.Caches {
kvs := make(point.KVs, 0, 15)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range plusAPIResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand All @@ -450,7 +450,7 @@ func (ipt *Input) makeLocationLine(plusAPIResp NginxPlusAPIResponse) {
for locationName, location := range plusAPIResp.Locations {
kvs := make(point.KVs, 0, 20)
opts := point.DefaultMetricOptions()
opts = append(opts, point.WithTime(ipt.start))
opts = append(opts, point.WithTime(ipt.start), point.WithExtraTags(ipt.mergedTags))

for kk, vv := range plusAPIResp.tags {
kvs = kvs.MustAddTag(kk, vv)
Expand Down
Empty file modified internal/plugins/inputs/nginx/export.go
100755 → 100644
Empty file.
8 changes: 8 additions & 0 deletions internal/plugins/inputs/nginx/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func (ipt *Input) Run() {
tick := time.NewTicker(ipt.Interval)
defer tick.Stop()

if ipt.Election {
ipt.mergedTags = inputs.MergeTags(ipt.Tagger.ElectionTags(), ipt.Tags, ipt.URL)
} else {
ipt.mergedTags = inputs.MergeTags(ipt.Tagger.HostTags(), ipt.Tags, ipt.URL)
}

l.Infof("merged tags: %+#v", ipt.mergedTags)

for {
if ipt.pause {
l.Debugf("not leader, skipped")
Expand Down
18 changes: 5 additions & 13 deletions internal/plugins/inputs/postgresql/customer_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,21 @@ package postgresql

import (
"github.com/GuanceCloud/cliutils/point"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/datakit"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/plugins/inputs"
)

type customerObjectMeasurement struct {
name string
tags map[string]string
fields map[string]interface{}
election bool
name string
tags map[string]string
fields map[string]interface{}
ipt *Input
}

// Point implement MeasurementV2.
func (m *customerObjectMeasurement) Point() *point.Point {
opts := point.DefaultObjectOptions()
if m.election {
opts = append(opts,
point.WithExtraTags(datakit.GlobalElectionTags()),
)
point.DefaultObjectOptions()
}
return point.NewPointV2(m.name,
append(point.NewTags(m.tags), point.NewKVs(m.fields)...),
opts...)
append(point.DefaultObjectOptions(), point.WithExtraTags(m.ipt.mergedTags))...)
}

//nolint:lll
Expand Down
16 changes: 8 additions & 8 deletions internal/plugins/inputs/postgresql/customer_object_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func (ipt *Input) getCoPointByColErr() []*gcPoint.Point {
"col_co_status": ipt.CollectCoStatus,
}
m := &customerObjectMeasurement{
name: "database",
tags: tags,
fields: fields,
election: ipt.Election,
name: "database",
tags: tags,
fields: fields,
ipt: ipt,
}
ipt.setIptLastCOInfo(m)
ms = append(ms, m)
Expand Down Expand Up @@ -170,10 +170,10 @@ func (ipt *Input) collectCustomerObjectMeasurement() ([]*gcPoint.Point, error) {
"col_co_status": ipt.CollectCoStatus,
}
m := &customerObjectMeasurement{
name: "database",
tags: tags,
fields: fields,
election: ipt.Election,
name: "database",
tags: tags,
fields: fields,
ipt: ipt,
}
ipt.setIptLastCOInfo(m)
ms = append(ms, m)
Expand Down
25 changes: 17 additions & 8 deletions internal/plugins/inputs/postgresql/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ type Input struct {
Databases []string `toml:"databases"`
Interval string `toml:"interval"`
Tags map[string]string `toml:"tags"`
Relations []Relation `toml:"relations"`
CustomQuery []*customQuery `toml:"custom_queries"`
Log *postgresqllog `toml:"log"`
mergedTags map[string]string
Relations []Relation `toml:"relations"`
CustomQuery []*customQuery `toml:"custom_queries"`
Log *postgresqllog `toml:"log"`

Version string
Uptime int
Expand Down Expand Up @@ -832,11 +833,11 @@ func (ipt *Input) accRow(columnMap map[string]*interface{}, measurementInfo *inp
name = measurementInfo.Name
}
ms := &inputMeasurement{
name: name,
fields: fields,
tags: tags,
ts: time.Now(),
election: ipt.Election,
name: name,
fields: fields,
tags: tags,
ts: time.Now(),
ipt: ipt,
}
ipt.collectCache = append(ipt.collectCache, ms.Point())
}
Expand Down Expand Up @@ -912,6 +913,14 @@ func (ipt *Input) init() error {
ipt.Tags["server"] = tagAddress
ipt.Tags["db"] = dbName

if ipt.Election {
ipt.mergedTags = inputs.MergeTags(ipt.tagger.ElectionTags(), ipt.Tags, ipt.Address)
} else {
ipt.mergedTags = inputs.MergeTags(ipt.tagger.HostTags(), ipt.Tags, ipt.Address)
}

l.Infof("merged tags: %+#v", ipt.mergedTags)

// init query cache
ipt.metricQueryCache = map[string]*queryCacheItem{}

Expand Down
6 changes: 3 additions & 3 deletions internal/plugins/inputs/postgresql/input_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func getTrueData(mockFields map[string]interface{}) map[string]interface{} {
}

func TestCollect(t *testing.T) {
input := &Input{
version: &semver.Version{Major: 12},
}
input := defaultInput()

input.version = &semver.Version{Major: 12}
input.service = &MockCollectService{}
err := input.Collect()
if err != nil {
Expand Down
17 changes: 6 additions & 11 deletions internal/plugins/inputs/postgresql/metric_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/GuanceCloud/cliutils/point"

"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/datakit"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/plugins/inputs"
)

Expand Down Expand Up @@ -109,20 +108,16 @@ WHERE %s
}

type inputMeasurement struct {
name string
tags map[string]string
fields map[string]interface{}
ts time.Time
election bool
name string
tags map[string]string
fields map[string]interface{}
ts time.Time
ipt *Input
}

// Point implement MeasurementV2.
func (m *inputMeasurement) Point() *point.Point {
opts := point.DefaultMetricOptions()

if m.election {
opts = append(opts, point.WithExtraTags(datakit.GlobalElectionTags()))
}
opts := append(point.DefaultMetricOptions(), point.WithExtraTags(m.ipt.mergedTags))

return point.NewPointV2(m.name,
append(point.NewTags(m.tags), point.NewKVs(m.fields)...),
Expand Down
17 changes: 5 additions & 12 deletions internal/plugins/inputs/postgresql/metric_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,21 @@ package postgresql

import (
"github.com/GuanceCloud/cliutils/point"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/datakit"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/plugins/inputs"
)

type upMeasurement struct {
name string
tags map[string]string
fields map[string]interface{}
election bool
name string
tags map[string]string
fields map[string]interface{}
ipt *Input
}

// Point implement MeasurementV2.
func (m *upMeasurement) Point() *point.Point {
opts := point.DefaultMetricOptions()

if m.election {
opts = append(opts, point.WithExtraTags(datakit.GlobalElectionTags()))
}

return point.NewPointV2(m.name,
append(point.NewTags(m.tags), point.NewKVs(m.fields)...),
opts...)
append(point.DefaultMetricOptions(), point.WithExtraTags(m.ipt.mergedTags))...)
}

func (m *upMeasurement) Info() *inputs.MeasurementInfo { //nolint:funlen
Expand Down
60 changes: 18 additions & 42 deletions internal/plugins/inputs/postgresql/metric_up_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import (
"net"
"net/url"
"strconv"
"time"

"github.com/GuanceCloud/cliutils/point"

dkio "gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/io"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/metrics"
"gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/plugins/inputs"
)

func (ipt *Input) setUpState() {
Expand Down Expand Up @@ -51,8 +49,7 @@ func (ipt *Input) getUpInstance() string {
return ipPort
}

func (ipt *Input) buildUpPoints() ([]*point.Point, error) {
ms := []inputs.MeasurementV2{}
func (ipt *Input) buildUpPoints() *point.Point {
tags := map[string]string{
"job": ipt.getUpJob(),
"instance": ipt.getUpInstance(),
Expand All @@ -61,49 +58,28 @@ func (ipt *Input) buildUpPoints() ([]*point.Point, error) {
"up": ipt.UpState,
}
m := &upMeasurement{
name: "collector",
tags: tags,
fields: fields,
election: ipt.Election,
}
l.Debugf("build up %s points:%s", inputName, m.Point().LineProto())
ms = append(ms, m)
if len(ms) > 0 {
pts := getPointsFromMeasurement2(ms)
for k, v := range ipt.Tags {
for _, pt := range pts {
pt.AddTag(k, v)
}
}
return pts, nil
name: "collector",
tags: tags,
fields: fields,
ipt: ipt,
}

return []*point.Point{}, nil
return m.Point()
}

func getPointsFromMeasurement2(ms []inputs.MeasurementV2) []*point.Point {
pts := []*point.Point{}
for _, m := range ms {
pts = append(pts, m.Point())
}
func (ipt *Input) FeedUpMetric() {
pt := ipt.buildUpPoints()

return pts
}
l.Debug("feed up metric")

func (ipt *Input) FeedUpMetric() {
pts, _ := ipt.buildUpPoints()
if len(pts) > 0 {
l.Debug("feed up metric")
if err := ipt.feeder.FeedV2(point.Metric, pts,
dkio.WithCollectCost(time.Since(time.Now())),
dkio.WithElection(ipt.Election),
dkio.WithInputName(inputName),
); err != nil {
ipt.feeder.FeedLastError(err.Error(),
metrics.WithLastErrorInput(inputName),
metrics.WithLastErrorCategory(point.Metric),
)
l.Errorf("feed : %s", err)
}
if err := ipt.feeder.FeedV2(point.Metric, []*point.Point{pt},
dkio.WithElection(ipt.Election),
dkio.WithInputName(inputName),
); err != nil {
ipt.feeder.FeedLastError(err.Error(),
metrics.WithLastErrorInput(inputName),
metrics.WithLastErrorCategory(point.Metric),
)
l.Errorf("feed : %s", err)
}
}

0 comments on commit 4dc62b8

Please sign in to comment.