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

[FeatureRequest] Support ajson scripting engine for more complex queries #781

Open
Adirael opened this issue Jan 28, 2025 · 1 comment
Open

Comments

@Adirael
Copy link

Adirael commented Jan 28, 2025

At the moment the Pod collector only supports JSONPath, which means that the underlying metrics need to be "processed" and the data cannot be parsed in any way before making it available as a metric.

The underlying ajson library has a scripting engine that makes this feature possible without having to substantial lifting. Is this something you would be interested in supporting? I have a working POC here.

I skip JSONPath validation as that short circuits scripts and run the expression through ajson.Eval when ajson.Node.JSONPath fails. ajson's CLI works in a similar way.

We could have a different syntax too, metric-config.pods.<metricName>.json-path/json-eval maybe, where JSONPath validation is kept and only one of them can be used at a time.

An example of the kind of expression this allows is:

    metric-config.pods.idle-processes.json-path/json-key: |
      ceil($['active processes'] / $['total processes']) * 100

This returns the used worker percent for php-fpm calculated from the status endpoint that returns a JSON document like this:

{
  "pool": "www",
  "process manager": "dynamic",
  "start time": 1738071206,
  "start since": 1898,
  "accepted conn": 1280,
  "listen queue": 0,
  "max listen queue": 0,
  "listen queue len": 0,
  "idle processes": 9,
  "active processes": 1,
  "total processes": 10,
  "max active processes": 4,
  "max children reached": 0,
  "slow requests": 0
}
@mikkeloscar
Copy link
Contributor

You're welcome to contribute this feature. I would propose it's implemented in a custom field like json-eval as you suggest.

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

No branches or pull requests

2 participants