Looking at the Prometheus scrape documentation, you can specify a full URL.

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config

Jan's suggestion of using /_{info|metrics}?accept=prometheus with the default being JSON would be better for CouchDB than the default output being Prometheus, and is a minor change.

So the job config would look like:

- job_name: 'couchdb'
  targets: my-couchdb-host.domain.com:5984
  metrics_path: /_{info}metrics}
  params:
    accept: prometheus

I would be OK with a first pass only providing this format but I would strongly prefer the JSON version come ASAP, and be the default for the endpoint if no query parameter is passed - unless Prometheus provides something we can use as a unique identifier in the request headers. (If it does you can use that to eliminate the params: line.)

As I'm on holiday for another 10 days that's about the most I want to think about this right now. Jan has covered my other concerns and discussion should happen in his thread.

-Joan

On 23/09/2020 05:17, jiangph wrote:
Thanks Joan for your quick response and suggestion.  As we can see, JSON is not 
the standard Prometheus format for _metrics endpoint. In order to be compatible 
with many monitoring tools, what about going with Prometheus standard format 
first and we may add JSON format support later?

Best regards,
Peng Hui

On Sep 23, 2020, at 9:41 AM, Joan Touzet <woh...@apache.org> wrote:

I like this, but not at the expense of JSON output. It would be the only new 
API surface for CouchDB that isn't JSON-based, and there needs to be excellent 
justification for such. Prometheus is well-known enough to be supported, but we 
should continue to put out JSON stats for the foreseeable future.

I know that Prometheus can't send a header, but sending an accepts 
application/json to /_metrics and having it send back the same data as 
Prometheus, but in JSON, would be lovely. If you feel up to it :)

-Joan "on vacation" Touzet

On 2020-09-22 8:55 a.m., jiangph wrote:
Hey all,
We would like to add a Prometheus metrics endpoint for CouchDB and wanted to 
see if the community would be interested in us contributing this to CouchDB 4.x.
Prometheus is a CNCF open-source project and the Prometheus metrics endpoint 
format is supported by many monitoring tools. Its data model is based around 
having a metric name which then contains a label name and a label value:
<metric name>{<label name>=<label value>, ...}
And it supports the Counter, Gauge, Histogram, and Summary metric types.
The idea for the new Prometheus endpoint, /_metrics, would be that the endpoint 
is a consolidation of the _stats [1],  _system [2], and _active_tasks [3] 
endpoints.
For _stats and _system, the conversion from JSON to Prometheus-based format 
seems to be straightforward.
JSON format:
{
  "value": {
   "min": 0,
   "max": 0,
   "arithmetic_mean": 0,
   "geometric_mean": 0,
   "harmonic_mean": 0,
   "median": 0,
   "variance": 0,
   "standard_deviation": 0,
...
"percentile": [
    [
     50,
     0
    ],
    [
     75,
     0
    ],
    [
     90,
     0
    ],
    [
     95,
     0
    ],
    [
     99,
     0
    ],
    [
     999,
     0
    ]
   ],
   "histogram": [
    [
     0,
     0
    ]
   ],
}
Prometheus-based format:
couchdb_stats{value="min"} 0
couchdb_stats{value="max"} 0
couchdb_stats{value="percentile50"} 0
couchdb_stats{value="percentile75"} 0
couchdb_stats{value="percentile95"} 0
For _active_tasks, the change will be a bit more complicated, and some fields 
will be added to labels and tags.
JSON format:
{
     "checkpointed_source_seq": 68585,
     "continuous": false,
     "doc_id": null,
     "doc_write_failures": 0,
     "docs_read": 4524,
     "docs_written": 4524,
     "missing_revisions_found": 4524,
     "pid": "<0.1538.5>",
     "progress": 44,
     "replication_id": "9bc1727d74d49d9e157e260bb8bbd1d5",
     "revisions_checked": 4524,
     "source": "mailbox",
     "source_seq": 154419,
     "started_on": 1376116644,
         "target": "http://mailsrv:5984/mailbox <http://mailsrv:5984/mailbox> 
<http://mailsrv:5984/mailbox <http://mailsrv:5984/mailbox>>",
     "type": "replication",
     "updated_on": 1376116651
}
Prometheus-based would look something like:
format:couchdb_active_task{type="replication", source="mailbox", target="http://mailsrv:5984/mailbox 
<http://mailsrv:5984/mailbox> <http://mailsrv:5984/mailbox <http://mailsrv:5984/mailbox>>", docs_count = 
"docs_read"} 4524
couchdb_active_task{type="replication", source="mailbox", target="http://mailsrv:5984/mailbox 
<http://mailsrv:5984/mailbox> <http://mailsrv:5984/mailbox <http://mailsrv:5984/mailbox>>", docs_count = 
"docs_written"} 4524
couchdb_active_task{type="replication", source="mailbox", target="http://mailsrv:5984/mailbox 
<http://mailsrv:5984/mailbox> <http://mailsrv:5984/mailbox <http://mailsrv:5984/mailbox>>", docs_count = 
"missing_revisions_found"} 4524
Best regards,
Garren Smith
Peng Hui Jiang
[1] https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-stats 
<https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-stats> 
<https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-stats 
<https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-stats>>
[2] https://docs.couchdb.org/en/latest/api/server/common.html#active-tasks 
<https://docs.couchdb.org/en/latest/api/server/common.html#active-tasks> 
<https://docs.couchdb.org/en/latest/api/server/common.html#active-tasks 
<https://docs.couchdb.org/en/latest/api/server/common.html#active-tasks>>
[3] https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-system 
<https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-system> 
<https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-system 
<https://docs.couchdb.org/en/latest/api/server/common.html#node-node-name-system>>


Reply via email to