0

Target server

I built a target server in express-js.

const express = require("express");
var morgan = require("morgan");
const app = express();
const port = 3000;

let counter = 10;

app.use(morgan("combined"));

app.get("/metrics", (req, res) => {
  counter += 10;
  res.setHeader("Content-Type", "text/plain");
  res.send(`CUSTOM_SERVER_COUNTER ${counter}`);
});

app.get("/", (req, res) => {
  res.send("Hello World!");
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

Prometheus

Configures my target in the Prometheus and it's showing in the UI also. enter image description here

Not sure why my target is always showing down.

Rahul
  • 1,858
  • 1
  • 12
  • 33
  • It seems you might need to enable TCP connection i.e you might need to move it to https to make it work. – Apoorva Chikara Aug 04 '22 at 03:50
  • @ApoorvaChikara port 9090 is also working on HTTP which is default HTTP server of prometheus – Rahul Aug 04 '22 at 06:27
  • Does [this](https://stackoverflow.com/questions/54397463/getting-error-get-http-localhost9443-metrics-dial-tcp-127-0-0-19443-conne) helps? – Apoorva Chikara Aug 04 '22 at 08:26
  • 1
    The issue is solved, my express server was running on my system host and Prometheus was running inside docker. So, it wasn’t express server wasn’t accessible from inside the docker.. – Rahul Aug 04 '22 at 08:37
  • @Rahul How were you able to solve this issue? I too have a requirement where my service is running in local and the prometheus was running in docker. – Joel George Feb 08 '23 at 09:18
  • I used host networking, for more info see https://docs.docker.com/network/host/ – Rahul Feb 09 '23 at 19:09

0 Answers0