GB
  
You are currently viewing the United Kingdom version of the site.
Would you like to switch to your local site?
14 MIN READ TIME
Create graphs in Grafana

Collect and graph metrics with Python

We delve into exposing Prometheus metrics with some capable Python 3 scripts and the help of Mihalis Tsoukalos.

The code

VISUALISING IN GRAFANA

»PROMETHEUS DATA TYPES

The code

Get it from linuxform at. com/archives and on the DVD

Get it from linuxform at. com/archives and on the DVD

The quickest way to start using Grafana is by downloading and executing its official Docker image. This means that apart from the Docker image, you won’t need to download, set up or install anything else for Grafana to work. However, you’ll still need to define the port number that Grafana listens to as well as the local directory where Grafana will store its files in order to have data persistency.

Prometheus pulls data from its sources, which means it acts as a client in order to get its data. This is a crucial detail that you should keep in mind while developing applications that collect Prometheus metrics. In practice, this means that apart from collecting the desired metrics, the Python script should also offer support for HTTP connections each time Prometheus asks for metrics.

In order to plot data, you first need to obtain that data. In the case of Grafana, data comes from one or more data sources. A Grafana Data Source is a data base, file or service that provides data to Grafana – the program won’t work without data. Prometheus is going to act as the Grafana data source in this tutorial.

Prometheus supports four different types of data:

OUR EXPERT

The visualisation process is described as follows: Go to http://localhost:3000 to connect to Grafana – use a different hostname if Grafana is a different machine.

>Counter This is a cumulative value that’s used for representing increasing counters. The value of a counter can stay the same, go up or be reset to zero, but it can’t decrease. Counters are usually used to represent cumulative values such as number of requests served so far or the total number of errors.

Mihalis Tsoukalos

Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for 99p
SUBSCRIBE NOW
30 day trial, then just £9.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
June 2021
VIEW IN STORE

Other Articles in this Issue


WELCOME
LINUX FORMAT
MEET THE TEAM
No free lunches
They’re not Google’s photos, they’re mine! To the
REGULARS AT A GLANCE
The right to repair movement gains steam
HARDWARE
Google wins copyright case
COPYRIGHT
Ubuntu working on Windows
OPERATING SYSTEMS
YOUR DATA IS YOURS
Matt Yonkovit is Percona’s Head of Open Source
HORSES & COURSES
OPINION
IBM’s COBOL comes to Linux
PROGRAMMING
Librem 5 progress
HARDWARE
New Android Bluetooth stack
ANDROID
Distro Watch
What’s down the side of the free software sofa?
PANFROST TO VULKAN
OPINION
HERE’S STALLMAN
OPINION
Kernel Watch
Jon Masters summarises the latest happenings in the Linux kernel, so that you don’t have to
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com
Mailserver
WRITE TO US Do you have a burning
Audacity
Version: 3.0 Web: www.audacityteam.org Hot off the
Clapper
Version: 0.1.0 Web: https://github.com/ Rafostar/clapper A t
Haguichi
Version: 1.4.3 Web: https://github.com/ ztefn/haguichi T ime to
Media Downloader
Version: 1.1.0 Web: https://github.com/ mhogomchungu/media-downloader L ately
Panon
Version: 0.4.6 Web: https://github.com/rbn42/panon C alling all
Radiotray-NG
Version: 0.2.7 Web: https://github.com/ebruck/radiotray-ng W hen it
Dragit
Version: 0.5 Web: https://github.com/ sireliah/dragit F ile sharing
Balla
Version: GIT Web: https://github.com/ TimothyGramnaes/Ball-game C asual browser-based
Command Line Heroes
Version: GIT Web: https://github.com/ CommandLineHeroes/clh-bash H ow many
Pixelorama
Version: 0.8.2 Web: https://github . com/Orama-Interactive/Pixelorama T he
Trash-cli
Version: 0.20.12.26 Web: https:// github.com/andreafrancia/trash-cli A trash can
On the disc
Discover the highlights from this month’s packed DVD!
REVIEWS
Samsung 980 1TB SSD
A strange drive for stranger times, says a perfectly normal  Alan Dexter
Radeon RX 6700 XT
Navi 22 joins the GPU party, trimming core counts, die size and price, as Jarred Walton discovers. If only you could get your hands on it…
Kodachi 8.3
A self-confessed Kodachi fanboy, Mayank Sharma is left speechless by its latest release and doesn’t mind if this review sounds biased (which it is)
Shells.com
Having surrendered most of his existence to the cloud, Mayank Sharma tests a service that might just let him chuck his computer out as well
AlmaLinux OS 8.3
Mayank Sharma is flabbergasted that someone would spend a million dollars to create a community supported clone of a distro
Desperados 3
Management love maverick office types who shoot from the hip, but when Fraser Brown did it they were ducking for cover!
ROUNDUP
Web browsers
Default web browsers are fine, but there’ll come a time when you’ll demand more from your online tools. Shashank Sharma presents five contenders
ESCAPE GOOGLE PHOTOS
Google’s free photo storage is a thing of the past. Jonni Bidwell has some free software to get your albums in order
Free your photos
Whether at home or in the cloud, your photos deserve a new host
Install Nextcloud
Discover how you can tap into the power of Docker Compose to get Nextcloud up and running in a jiffy just like the professionals
Transfer your photos
Now that Nextcloud is installed and operational, it’s time to get your photos into it, and out of reaching distance from Google
Let’s look at Lychee
Get simply beautiful photo hosting with a tropical, fruity aftertaste
IN-DEPTH
OPENSTREETMAP TURNS ONE HUNDRED MILLION!
Google Maps isn’t the only mapping tool on the block. One alternative in particular, OpenStreetMaps, employs an open crowd-sourcing approach, as Mike Bedford reveals
GET INTO GENTOO
Famed as the fastest penguin on the planet, Mats Tage explains how you to can use it to run the fastest of Tux boxes
Pi USER
BITTEN BY THE Pi BUG
Andy Piper is a senior staff developer advocate
Pi 5 confirmed and the Pico’s name
Eben Upton confirms the Pi 5, another Pico and what the model number actually means
AdaFruit ItsyBitsy
Teeny weeny Pico bikini
Plant your Pico
Seeed maker base
Inky Impression
Les Pounder enjoys pop art and eight-bit computers, so this new screen from Pimoroni is an ideal way to display his favourite style of art
Building code for microcontrollers
CIRCUITPYTHON
Build your own URL shortening service
WEB APPLICATION
TUTORIALS
System boot speeds
While Shashank Sharma doesn’t much care for cars that can go 0-60 in six seconds or less, he does expect his distro to boot up in no time at all
Administer servers with your browser
Nick Peers reveals how to use Cockpit to access and manage your headless server remotely – no keyboard or display required
Model and render objects in Blender
We love tea at Linux Format Towers – even that fancy herbal stuff – so Michael Reed is going to show you how to make a lovely cuppa… in Blender
Emulating the Commodore PET
Les Pounder relives a time when a roguish smuggler who looked a lot like Harrison Ford shot first and your computer was ready to code in seconds!
Protecting documents with security tools
Kseniya Fedoruk applies digital signatures, passwords and watermarks, to ensure extra security when working with documents in OnlyOffice
Explore Forth on the Jupiter Ace
Mike Bedford reveals the Jupiter Ace, the contemporary of the Sinclair ZX81 that was programmed in Forth rather than the more popular BASIC
CODING ACADEMY
Coding Zombie Runner with Python
Calvin Robinson creates a custom toolbox for quickly manipulating a custom-built environment, complete with graphical user interface
Chat
X
Pocketmags Support