JSON-RPC over HTTP in telegraf plugin http_response


Is it possible to use http_response plugin in telegraf to send JSON-RPC over http? Or is there better one? I tried httpjson plugin but it accepts only strings to request parameters and i need to send also int parameters.

What i need to do is send simple request to service and check that it responds ok. Service always responds with code 200 so i need to check response data to catch errors.

I haven’t used JSON-RPC before, do you think you could show how a request would look if sent using curl?


Curl is below taken from postman. I changed url and removed authentication:
curl -X POST
-H ‘Cache-Control: no-cache’
-H ‘Content-Type: application/json’
-H ‘Postman-Token: 224a53f3-a917-4f07-9bdb-12529f20dad6’
-d ‘{“method”: “Ping”, “id”: 1, “params”: [999999], “auth”: “”, “jsonrpc”: “2.0”}’

This should be fairly straightforward to do with http_response, just make sure you have these options:

  address = "http://example.org/di"
  method = "POST"
  body = '{"method": "Ping", "id": 1, "params": [999999], "auth": "", "jsonrpc": "2.0"}'
    Cache-Control = "no-cache"
    Content-Type = "application/json"
    Postman-Token = "224a53f3-a917-4f07-9bdb-12529f20dad6"


thanks it worked!

Do you know how could i monitor json values from services hosted in nginx? Services always responses with responce code 200 and actual data to be checked is in response body. I have nginx access.log logparser configured but i can only get http response codes / service.

You should be able to do this with http_response as well, you can set the response_string_match option to a regular expression that should be in the response body.

Yes that is working ok but I want also monitor server and catch faulty RPC messages. So i want to monitor http traffic and parse request response data to find errors.

I’m not sure I follow, are you hoping to monitor the result of actual RPC requests from clients?

Yes. I can get request count from nginx access log using telegraf plugin logparser but I need also count from requests that have faulty response. Let say that service is responsing “ok” normally and “error” when something is wrong so that is what i’m after.

If the response is always 200 even when an error occurs I think we would need to find a way to expose the error into the nginx logs or somewhere else we can sense the error.

In my experience, this is typically where application metrics are used. Instead of having nginx tell you the result, you add custom code to the RPC server to report the error using statsd or prometheus formats.