Skip to content

Commit

Permalink
feat: add only_include_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDFiish committed Jan 8, 2025
1 parent 5224db7 commit fbdfd9d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

```yaml
rate_limit: 20

cdn:
metrics:
- 2xx
- 3xx
- 4xx
- 5xx
only_include_metrics:
- 566
delay_seconds: 360
custom_query_dimensions:
- projectId: id
Expand Down
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/go-kit/log/level"
"github.com/joho/godotenv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
Expand Down Expand Up @@ -46,7 +45,6 @@ func main() {
// load config file
if err := tencentConfig.LoadFile(*configFile); err != nil {
_ = level.Error(logger).Log("msg", "Load config error", "err", err)
os.Exit(1)
} else {
_ = level.Info(logger).Log("msg", "Load config ok")
}
Expand All @@ -68,8 +66,6 @@ func main() {
}

prometheus.MustRegister(version.NewCollector(config.NameSpace))
prometheus.Unregister(collectors.NewGoCollector())
prometheus.Unregister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))

if *enableCbs {
cpf := profile.NewClientProfile()
Expand Down
12 changes: 12 additions & 0 deletions pkg/collector/handler_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ type CdnExporter struct {
cdnInstance *prometheus.Desc
}

func contains(slice []string, item string) bool {
for _, s := range slice {
if s == item {
return true
}
}
return false
}

func NewCdnExporter(logger log.Logger, credential common.CredentialIface, tencentConfig config.TencentConfig) *CdnExporter {
return &CdnExporter{
logger: logger,
Expand Down Expand Up @@ -120,6 +129,9 @@ func (e *CdnExporter) Collect(ch chan<- prometheus.Metric) {
}

for _, data := range cdnResponse.Response.Data[0].CdnData {
if !contains(e.tencentConfig.CDN.OnlyIncludeMetrics, *data.Metric) {
continue
}
ch <- prometheus.MustNewConstMetric(
e.cdnInstance,
prometheus.GaugeValue,
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type CustomQueryDimension struct {

type CDNConfig struct {
Metrics []string `yaml:"metrics"`
OnlyIncludeMetrics []string `yaml:"only_include_metrics"`
DelaySeconds int `yaml:"delay_seconds"`
CustomQueryDimension []CustomQueryDimension `yaml:"custom_query_dimensions"`
}
Expand Down

0 comments on commit fbdfd9d

Please sign in to comment.