logzio / jmx2graphite

JMX to Graphite every x seconds in one command line (Docker based) (also come in Java Agent flavour)
MIT License
77 stars 23 forks source link

Fix metric name encode #106

Closed bbranquinho closed 2 years ago

bbranquinho commented 2 years ago

Description

There is an issue to publish metrics when the metric name contains special characters; this PR is to fix that issue. The best way to fix that is by using URL encoding. The metric name should use URL encoded characters, otherwise, graphite does not show the metric. Graphite shows the error "No Data" if the metric name contains special characters.

Error

The following figure shows the error.

Screen Shot 2022-01-10 at 5 33 08 AM

Log: _22/01/10 05:33:30 TRACE jmx2graphite.MetricsPipeline: MetricValue{name='com.zaxxer.hikari.typePool-(HikariCP-writer-2).TotalConnections', value=5, timestampSeconds=1641772800}

An easy way to test graphite is by executing the command echo "local.jmx.my-project.com.zaxxer.hikari.type_Pool-(HikariCP-reader-1).TotalConnections 5 `date +%s`" | nc ${GRAPHITE_SERVER} ${PORT}

Fix

Using the URLEncoder (https://docs.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html) the error is fixed.

Screen Shot 2022-01-10 at 5 20 18 AM

Log: _22/01/10 05:37:36 TRACE jmx2graphite.MetricsPipeline: MetricValue{name='com.zaxxer.hikari.typePool-%28HikariCP-writer-2%29.ActiveConnections', value=0, timestampSeconds=1641772800}

Command to test graphite echo "local.jmx.my-project.com.zaxxer.hikari.type_Pool-%28HikariCP-reader-1%29.TotalConnections 5 `date +%s`" | nc ${GRAPHITE_SERVER} ${PORT}

Additional Information

The following PRs show the same fix applied to other projects:

https://github.com/grafana/grafana/pull/401 https://github.com/graphite-project/graphite-web/pull/1663

asafm commented 2 years ago

@bbranquinho Something is wrong with authentication in the GitHub Actions - I've reached out to GitHub support - it will take a few days based on their previous response rate

github-actions[bot] commented 2 years ago

Unit Test Results

2 files  2 suites   10s :stopwatch: 3 tests 3 :heavy_check_mark: 0 :zzz: 0 :x:

Results for commit 5e27aa74.