IMPORTANT: the format netdata sends metrics to prometheus has changed since netdata v1.7. The new prometheus backend for netdata supports a lot more features and is aligned to the development of the rest of the netdata backends.

Prometheus is a distributed monitoring system which offers a very simple setup along with a robust data model. Recently netdata added support for Prometheus. I’m going to quickly show you how to install both netdata and prometheus on the same server. We can then use grafana pointed at Prometheus to obtain long term metrics netdata offers. I’m assuming we are starting at a fresh ubuntu shell (whether you’d like to follow along in a VM or a cloud instance is up to you).

In order to install prometheus we are going to introduce our own systemd startup script along with an example of prometheus.yaml configuration. Prometheus needs to be pointed to your server at a specific target url for it to scrape netdata’s api. Prometheus is always a pull model meaning netdata is the passive client within this architecture. Prometheus always initiates the connection with netdata.

We will use the following prometheus.yml file. Save it at /opt/prometheus/prometheus.yml.

Make sure to replace your.netdata.ip with the IP or hostname of the host running netdata.

# my global configglobal:scrape_interval:5s# Set the scrape interval to every 5 seconds. Default is every 1 minute.evaluation_interval:5s# Evaluate rules every 5 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Attach these labels to any time series or alerts when communicating with# external systems (federation, remote storage, Alertmanager).external_labels:monitor:'codelab-monitor'# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files:# - "first.rules"# - "second.rules"# A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.-job_name:'prometheus'# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:-targets:['0.0.0.0:9090']-job_name:'netdata-scrape'metrics_path:'/api/v1/allmetrics'params:# format: prometheus | prometheus_all_hosts# You can use `prometheus_all_hosts` if you want Prometheus to set the `instance` to your hostname instead of IP format:[prometheus]## sources: as-collected | raw | average | sum | volume# default is: average#source: [as-collected]## server name for this prometheus - the default is the client IP# for netdata to uniquely identify it#server: ['prometheus1']honor_labels:truestatic_configs:-targets:['{your.netdata.ip}:19999']

The following is completely optional, it will enable Prometheus to generate alerts from some NetData sources. Tweak the values to your own needs. We will use the following nodes.yml file below. Save it at /opt/prometheus/nodes.yml, and add a - “nodes.yml” entry under the rule_files: section in the example prometheus.yml file above.

Each chart in netdata has several properties (common to all its metrics):

chart_id - uniquely identifies a chart.

chart_name - a more human friendly name for chart_id, also unique.

context - this is the template of the chart. All disk I/O charts have the same context, all mysql requests charts have the same context, etc. This is used for alarm templates to match all the charts they should be attached to.

family groups a set of charts together. It is used as the submenu of the dashboard.

Then each netdata chart contains metrics called dimensions. All the dimensions of a chart have the same units of measurement, and are contextually in the same category (ie. the metrics for disk bandwidth are read and write and they are both in the same chart).

as collected or raw - this data source sends the metrics to prometheus as they are collected. No conversion is done by netdata. The latest value for each metric is just given to prometheus. This is the most preferred method by prometheus, but it is also the harder to work with. To work with this data source, you will need to understand how to get meaningful values out of them.

The format of the metrics is: CONTEXT{chart="CHART",family="FAMILY",dimension="DIMENSION"}.

If the metric is a counter (incremental in netdata lingo), _total is appended the context.

Unlike prometheus, netdata allows each dimension of a chart to have a different algorithm and conversion constants (multiplier and divisor). In this case, that the dimensions of a charts are heterogeneous, netdata will use this format: CONTEXT_DIMENSION{chart="CHART",family="FAMILY"}

average - this data source uses the netdata database to send the metrics to prometheus as they are presented on the netdata dashboard. So, all the metrics are sent as gauges, at the units they are presented in the netdata dashboard charts. This is the easiest to work with.

The format of the metrics is: CONTEXT_UNITS_average{chart="CHART",family="FAMILY",dimension="DIMENSION"}.

When this source is used, netdata keeps track of the last access time for each prometheus server fetching the metrics. This last access time is used at the subsequent queries of the same prometheus server to identify the time-frame the average will be calculated. So, no matter how frequently prometheus scrapes netdata, it will get all the database data. To identify each prometheus server, netdata uses by default the IP of the client fetching the metrics. If there are multiple prometheus servers fetching data from the same netdata, using the same IP, each prometheus server can append server=NAME to the URL. Netdata will use this NAME to uniquely identify the prometheus server.

sum or volume, is like average but instead of averaging the values, it sums them.

The format of the metrics is: CONTEXT_UNITS_sum{chart="CHART",family="FAMILY",dimension="DIMENSION"}.
All the other operations are the same with average.

Keep in mind that early versions of netdata were sending the metrics as: CHART_DIMENSION{}.

(replace your.netdata.ip with the ip or hostname of your netdata server)

netdata will respond with all the metrics it sends to prometheus.

If you search that page for "system.cpu" you will find all the metrics netdata is exporting to prometheus for this chart. system.cpu is the chart name on the netdata dashboard (on the netdata dashboard all charts have a text heading such as : Total CPU utilization (system.cpu). What we are interested here in the chart name: system.cpu).

In average or sum data sources, all values are normalized and are reported to prometheus as gauges. Now, use the ‘expression’ text form in prometheus. Begin to type the metrics we are looking for: netdata_system_cpu. You should see that the text form begins to auto-fill as prometheus knows about this metric.

The format=prometheus parameter only exports the host’s netdata metrics. If you are using the master/slave functionality of netdata this ignores any upstream hosts - so you should consider using the below in your prometheus.yml:

netdata collects various system configuration metrics, like the max number of TCP sockets supported, the max number of files allowed system-wide, various IPC sizes, etc. These metrics are not exposed to prometheus by default.

To save bandwidth, and because prometheus does not use them anyway, # TYPE and # HELP lines are suppressed. If wanted they can be re-enabled via types=yes and help=yes, e.g. /api/v1/allmetrics?format=prometheus&types=yes&help=yes

netdata can filter the metrics it sends to prometheus with this setting:

[backend]send charts matching=*

This settings accepts a space separated list of patterns to match the charts to be sent to prometheus. Each pattern can use * as wildcard, any number of times (e.g *a*b*c* is valid). Patterns starting with ! give a negative match (e.g !*.bad users.* groups.* will send all the users and groups except bad user and bad group). The order is important: the first match (positive or negative) left to right, is used.

The default source average adds the unit of measurement to the name of each metric (e.g. _KiB_persec).
To hide the units and get the same metric names as with the other sources, append to the URL &hideunits=yes.

The units were standardized in v1.12, with the effect of changing the metric names.
To get the metric names as they were before v1.12, append to the URL &oldunits=yes

When the data source is set to average or sum, netdata remembers the last access of each client accessing prometheus metrics and uses this last access time to respond with the average or sum of all the entries in the database since that. This means that prometheus servers are not losing data when they access netdata with data source = average or sum.

To uniquely identify each prometheus server, netdata uses the IP of the client accessing the metrics. If however the IP is not good enough for identifying a single prometheus server (e.g. when prometheus servers are accessing netdata through a web proxy, or when multiple prometheus servers are NATed to a single IP), each prometheus may append &server=NAME to the URL. This NAME is used by netdata to uniquely identify each prometheus server and keep track of its last access time.