Grafana and CGrateS

I’m a really big fan of CGrateS, and I’m a fan of Grafana,

So what if you combined the two?

CGrateS uses a StoreDB – In my case MySQL, but could be Postgres or MongoDB, etc, and Grafana can get data from these sources too.

So let’s join them together!

For starters, I’ve got a bunch of CDRs in my cgrates.cdrs table inside MySQL.

Setting it up is a doddle, firstly inside Grafana we link it into MySQL:

Next up we create a dashboard and add a panel.

For this instance I’m metering data usage, so I’ve set the units to Bytes/SI (but if you’re using Voice you’ll need to adjust this to time).

Here’s my Query to find the Usage:

SELECT
DATE(setup_time) AS time,
SUM(`usage`) AS total_usage
FROM
cgrates.cdrs
GROUP BY
DATE(setup_time)
ORDER BY
time ASC

And I’ve created another one for Cost:

Keep in mind for the units it’s up to you what the units are, dollars, cents, 1/10th of a cent, etc, etc – In my case 1 in CGrateS equates to 1 cent:

SELECT

DATE(setup_time) AS time,
SUM(`cost`)/100 AS cost
FROM
cgrates.cdrs
GROUP BY
DATE(setup_time)
ORDER BY
time ASC

Lastly I’ve added a board to show the usage per Account, which I get with the below query:

SELECT
account AS label,
SUM(`usage`) AS value
FROM
cgrates.cdrs
GROUP BY
account
ORDER BY
value DESC

Not complete by any means, but shows what you can do with CGrateS and Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *