hobinjk / gateway-prometheus-translator

Translator (export) from the Web Thing API to Prometheus metrics
Mozilla Public License 2.0
12 stars 2 forks source link

Error on Run: 'Invalid metric name' #3

Closed che-wf closed 6 years ago

che-wf commented 6 years ago

I'm getting an error when I run node translator.js [url] [token].

Translator listening to 3060, metrics exposed on /metrics endpoint
(node:5973) UnhandledPromiseRejectionWarning: Error: Invalid metric name
    at new Gauge (/home/www/gateway-prometheus-translator/node_modules/prom-client/lib/gauge.js:59:10)
    at fetch.then.then.things (/home/www/gateway-prometheus-translator/translator.js:87:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:5973) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5973) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It looks like it is being thrown by the Prometheus client and doesn't like my metric name. Is there anything on my end that would help resolve the error? It looks like the ID is generated by the thingId and the propId. Do I control either of those?

hobinjk commented 6 years ago

It's most likely that the thing and property ids are controlled by the source of the thing (i.e. the adapter). If you can console.log in the safeMetricId function it'll likely point to the source of the problems. I'm guessing that I missed sanitizing a prometheus-unsafe character

che-wf commented 6 years ago

It's spitting out 70:ee:50:22:c7:de_Temperature and 70:ee:50:22:c7:de_CO2. I'm guessing it's the colon since you are appending the underscore.

hobinjk commented 6 years ago

Thanks! It's almost definitely the colon, so I just pushed a commit for adding it to the list of sanitized characters

hobinjk commented 6 years ago

Oh, no, it's unfortunately the fact that it starts with a number, I'll push a better fix out

hobinjk commented 6 years ago

https://github.com/hobinjk/gateway-prometheus-translator/commit/73acc079c57f310c69251f2f0cbd0c245e854714 now properly resolves this

codesterLalit commented 1 year ago

I am using prom-client in nodejs and while giving name name of histogram I used '-'(hyphen) instead of '_' underscore.

instead of this:

 const responseTimeHistogram = new promClient.Histogram({
        name: "api-customer_response_time_duration_seconds",
        help: "REST API time in second",
        labelNames: ["method", "route", "status_code"]
    })

do this:

 const responseTimeHistogram = new promClient.Histogram({
        name: "api_customer_response_time_duration_seconds",
        help: "REST API time in second",
        labelNames: ["method", "route", "status_code"]
    })