Prometheus Pushgateway with requests

Hi, n8n is great, i really love it, I managed to automate in an easy and fun way,
now when i start to use it in production i would like to push my own metrics to prometheus push gatway,
i was trying in so many ways,
the curl way of doing so is:

echo "some_metric 3.14" | curl --data-binary @- "http://pushgateway.domain.com:9091/metrics/job/pushgateway-metrics?ttl=15m"

i was trying to make a function with a static string, move it to binary data and ship it with requests, was trying raw data,
until now i did not get any results, any ideas?
got this one

text format parsing error in line 1: unexpected end of input stream

or this one

text format parsing error in line 1: invalid metric name

my flow:

{
  "name": "test",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "position": [
        -2020,
        -950
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {
          "mimeType": "application/json",
          "useRawData": true
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "position": [
        -1650,
        -950
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "=URL",
        "responseFormat": "string",
        "jsonParameters": true,
        "options": {
          "bodyContentType": "multipart-form-data"
        },
        "sendBinaryData": true,
        "headerParametersJson": "="
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1470,
        -950
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "functionCode": "return ((\"workflow_triggered_\" + \"1\"));"
      },
      "name": "string",
      "type": "n8n-nodes-base.functionItem",
      "position": [
        -1820,
        -950
      ],
      "notesInFlow": true,
      "typeVersion": 1
    }
  ],
  "connections": {
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "string": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "string",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 2
}

Welcome to the community @Raggingpuppies

Great to hear that you are enjoying n8n.

Can you try setting the body content type to Raw/Custom and the header to { "content-type": "plain/text" }

Thanks @RicardoE105 !
so i put the settings as you pointed me, so now i guess i do not ship the binary data, where can i place a string to send?

You still have to turn JSON/RAW parameters on in the UI.

Thank you @RicardoE105 ! it is working, i will post here an example for any one else that might be struggling :slight_smile:

{
  "name": "Example",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "position": [
        -2350,
        -1070
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {
          "mimeType": "application/json",
          "useRawData": true
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "position": [
        -1660,
        -960
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "functionCode": "return ((\"workflow_triggered_\"  + \" 1\" + \"\\n\"));"
      },
      "name": "N8N_Format_Item1",
      "type": "n8n-nodes-base.functionItem",
      "position": [
        -1850,
        -960
      ],
      "notesInFlow": true,
      "typeVersion": 1,
      "notes": "sometimes alertc send different webhook format, here we change the format to one aggregated format."
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "=PLACE_HOLDER",
        "responseFormat": "string",
        "jsonParameters": true,
        "options": {
          "bodyContentType": "raw",
          "timeout": 30000
        },
        "sendBinaryData": true
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1480,
        -960
      ],
      "typeVersion": 1
    }
  ],
  "connections": {
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "N8N_Format_Item1": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 3
}
1 Like