Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter metric value using regex #240

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

raedtwj
Copy link

@raedtwj raedtwj commented Jun 19, 2023

this change let you filter metric values using regex

Ex config.yml

---
modules:
  default:
    metrics:
    - name: available_memory
      path: '{ .availableMemory }'
      help: Available memory in MB
      valuetype: gauge
      regex: ^\d*\.?\d*  # only match digits

this config will be parsed

{"availableMemory": "1000 MB"}

to

# HELP available_memory Available memory in MB
# TYPE available_memory gauge
available_memory 1000

and won't throwing parse error since the suffix is not matched by the pattern

@raedtwj raedtwj force-pushed the feature/filter_metric_value_by_regex branch from 4266921 to 2fadfb1 Compare June 19, 2023 13:53
exporter/collector.go Outdated Show resolved Hide resolved
Copy link
Member

@rustycl0ck rustycl0ck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests and update the documentation/configuration file example so that users can understand how this feature works and how to use it.

The implementation looks good to me. Thanks for the PR!

config/config.go Outdated
@@ -30,6 +30,7 @@ type Metric struct {
EpochTimestamp string
Help string
Values map[string]string
Regex string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Regex string
IncludeRegex string

@dansimov04012022
Copy link

That feature would be very helpful, cause' it seems like there's no other way to convert string values like this 1.333285ms (duration, 1 millisecond and 333285 nanoseconds) to float 1.333285.

@liubo20210831
Copy link

liubo20210831 commented Aug 8, 2023

@rustycl0ck
We are looking forward to this feature very much because I want to use JSON Exporter to obtain a value with a percentage sign, such as 66.66%. If this work can be completed as soon as possible, it would be great. We are very grateful!

Thanks for the PR!

@eli-eli333
Copy link

We have been using this feature for some time and it is very useful to us. It fully meets the expected requirements. We hope you can merge this request as soon as possible. This is really important for us. Thank you very much !!!!!!

@eli-eli333
Copy link

eli-eli333 commented Aug 8, 2023

For example, using Gauge metrics to represent memory usage, number of connections, etc. Can convert string to float 1.52GB.

We have been using this feature for some time and it is very useful to us. It fully meets the expected requirements. We hope you can merge this request as soon as possible. This is really important for us. Thank you very much !!!!!!

@ylazaar
Copy link

ylazaar commented Aug 29, 2023

we cannot alter the source json. We cannot apply any transformation on the exporter's side. How are we supposed to extract any non-float data as a metric in order to plot it in grafana. We seriously need this feature or a similar solution.

@ewul
Copy link

ewul commented Sep 12, 2023

@SuperQ
Hello, how can we push this PR as soon as possible, since it seems to be very useful for everyone.

dependabot bot and others added 18 commits September 13, 2023 13:24
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.42.0 to 0.44.0.
- [Release notes](https://github.com/prometheus/common/releases)
- [Commits](prometheus/common@v0.42.0...v0.44.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Bumps [github.com/prometheus/exporter-toolkit](https://github.com/prometheus/exporter-toolkit) from 0.9.1 to 0.10.0.
- [Release notes](https://github.com/prometheus/exporter-toolkit/releases)
- [Changelog](https://github.com/prometheus/exporter-toolkit/blob/master/CHANGELOG.md)
- [Commits](prometheus/exporter-toolkit@v0.9.1...v0.10.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/exporter-toolkit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Bumps [k8s.io/client-go](https://github.com/kubernetes/client-go) from 0.27.1 to 0.27.2.
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](kubernetes/client-go@v0.27.1...v0.27.2)

---
updated-dependencies:
- dependency-name: k8s.io/client-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
* [FEATURE] Allow timestamps from metrics prometheus-community#167
* [FEATURE] Support Value Conversions prometheus-community#172

Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: rustyclock <rustyclock@protonmail.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: prombot <prometheus-team@googlegroups.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: eli_eli <771308671@qq.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: eli_eli <771308671@qq.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: eli_eli <771308671@qq.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: eli_eli <771308671@qq.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: eli_eli <771308671@qq.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: eli_eli <771308671@qq.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Bumps [k8s.io/client-go](https://github.com/kubernetes/client-go) from 0.27.2 to 0.28.1.
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](kubernetes/client-go@v0.27.2...v0.28.1)

---
updated-dependencies:
- dependency-name: k8s.io/client-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: prombot <prometheus-team@googlegroups.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
dependabot bot and others added 2 commits September 13, 2023 13:24
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.15.1 to 1.16.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.15.1...v1.16.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
Signed-off-by: prombot <prometheus-team@googlegroups.com>
Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
@raedtwj raedtwj force-pushed the feature/filter_metric_value_by_regex branch from 962da12 to e7082f9 Compare September 13, 2023 10:31
Signed-off-by: raedtwj <71555785+raedtwj@users.noreply.github.com>
@raedtwj
Copy link
Author

raedtwj commented Sep 13, 2023

Please add unit tests and update the documentation/configuration file example so that users can understand how this feature works and how to use it.

The implementation looks good to me. Thanks for the PR!

Documentation and unit tests have been added, Special thanks to @eli-eli333 and @liubo20210831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants