PromQL
Visual Studio Code plugin for Prometheus Query Language syntax highlighting.
Features
- This plugin is ready out-of-box!
- Syntax highlighting for Prometheus Query Language / PromQL (exposition format)
- Automatically closes quotes and brackets
- Can comment out one or multiple lines with
CTRL+/
or CMD+/
- Associates with files ending in
.prom
, .promql
, or .prometheus
or files named metrics
Simple Exporter
These steps outline how to set up a simple data exporter with static data using Prometheus and Grafana. First, create a file called metrics
(without an extension) which should automatically be associated with the Prometheus Query Language syntax highlighting. Create some sample metrics, here is an example of what some metrics might look like for weather sensors.
# HELP weather_sensor An example to show a metric with multiple labels
# TYPE weather_sensor gauge
weather_sensor{location="backyard", unit="F"} 59
weather_sensor{location="backyard", unit="C"} 15
weather_sensor{location="indoor", unit="F"} 68
weather_sensor{location="indoor", unit="C"} 20
# HELP weather_sensor_status An example for a secondary metric
# TYPE weather_sensor_status gauge
weather_sensor_status{location="backyard"} 1
weather_sensor_status{location="indoor"} 1
Valid metric types include counter, gauge, histogram, summary, or untyped.
Then, set up your Prometheus scrape configuration to begin scraping a new local endpoint at port 9999 (configurable.)
scrape_configs:
- job_name: simple_exporter
scrape_interval: 15s
static_configs:
- targets:
- "localhost:9999"
Finally, broadcast the metrics using this Python command. Make sure to run this command in the same directory as your metrics file.
python -m http.server 9999
In Grafana, you should be able to query these metrics. Try changing the metric values to see them update. There may be a delay in Grafana. Decrease the scrape_interval
to reduce the delay.
Video
Short demo video on using the PromQL extension and Grafana (0:30)