我在我的Node js App中使用express在3000上运行服务器。如果scrape_configs,我可以将指标发布到Prometheus:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'referral'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:3000']
在节点服务器端
const Prometheus = require('prom-client');
const app = express();
const metricsInterval = Prometheus.collectDefaultMetrics();
const test = new Prometheus.Counter({
name: 'num_of_requests',
help: 'Number of requests made',
labelNames: ['method', 'route', 'code']
});
test.inc({ method: "GET", route: url, code: status });
app.get('/metrics', (req, res) => {
res.set('Content-Type', Prometheus.register.contentType)
res.end(Prometheus.register.metrics())
});
这工作正常。现在,如果我想更改端口Prometheus正在侦听3000以外的其他内容。如果在不同端口上运行Express服务器并在不同端口上发布指标是可行的吗?