Grafana and Prometheus: add metrics automatically - grafana

I'm using Grafana and Prometheus to monitor our server. We have a lot of database procedures like "select_users" or "insert_task". In order to monitor how many pending database procedure calls are there in the server, we add data points for every procedure call in Prometheus dynamically. Now we have data points like "pending_select_users", "pending_insert_task" in Prometheus.
However, since there are so many database procedures(and the number will increase during developing), it's not very practical for us to add metrics in Grafana for each data point manually. Is there a way we can add metrics dynamically in Grafana? Since all the data point have a common name prefix("pending_"), can we add metrics in Grafana with wildcard? Or is there a better way to do this?

Since Grafana uses JSON as the underlying dashboard DSL, you could dynamically create dashboards, every time you add a new metric, and import it (via API) into Grafana.
I'd add an automation on top of your Prometheus targets, scrape the metrics, and if new metrics (with the required prefix) are found without a matching dashboard, the automation would create it and import it into Grafana.
Grafana API: http://docs.grafana.org/http_api/ (specifically for Dashbboards).

The solution described by #Eitan is definitely feasible. The same goes for using a library like grafonnet to generate dashboards dynamically.
But the simplest approach in my opinion would be to create a variable in Grafana that contains all the label values you are interested in. Something like
label_values(metric_name{label_name=~"prefix*"}, label_name)
should work for that. And then use the repeating panels / rows feature of Grafana to repeat a set of panels for every value in the variable. Though this could get out of hand if you have dozens / hundreds of distinct values.
https://grafana.com/docs/grafana/latest/variables/repeat-panels-or-rows/
https://grafana.com/blog/2020/06/09/learn-grafana-how-to-automatically-repeat-rows-and-panels-in-dynamic-dashboards/

If you want to generate just a single dashboard from your Proimetheus metrics sample, you can use this service:
http://eljah.tatar/micrometer2grafana/

Related

Multiple asPercent series

Metrics example - something.{variable}.success & something.{variable}.total
What I want to achieve is multiple series graph containing the success percentage for each feature variable.
Trying asPercent(something.*.success, something.*.total) makes graphite simply return 400 in grafana.
As I understand I would be able to achieve this by applyByNode(), but it seems that it's not available in grafana's graphite integration? I'm using self-hosted grafana 7.0 with graphite 1.1.7 .
I also seen example of nesting reduceSeries and mapSeries, but all of them use predefined values for wildcard, in my case there are too many of them to bother.

Is it possible to have 2 different data sources in grafana dashboard

Is it possible to have 2 different sources i.e influxdb and prometheus in a single dashboard in grafana.
Yes, each panel or variable on a dashboard can use different data source.
Variables can use different data source and you can use it on panel no matter what data source uses. It allows you to mix information to have a better dashboard with more details.
Also, you have three especial data sources:
Grafana built-in data source that generates random walk data.
Mixed query multiple data sources in the same panel.
Dashboard use a result set from another panel in the same dashboard.
More info about data sources here
Yes, you can select the desired data sources in several points of the dashboard configuration (like panels and variables) and you can use different values for each one.

Prometheus Config reload Annotation for Grafana

I want to show in Grafana with an Annotation if there is a successful Prometheus config reload.
Grafana v6.3.5 &
Prometheus v2.12.0
I imported an existing Dashboard for internal Prometheus Stats and saw that within this Dashboard they use the following Statement as Annotion: sum(changes(prometheus_config_last_reload_success_timestamp_seconds[10m]))
Sadly this does not work and I am not sure how to properly use the metric to create Annotations.
How can I use this Metric to make this work?
Since you are using a recent version of Grafana, you don't need this expression any more. There is a feature to display annotations base on series value.
If you want in annotations the successful reloads of configuration, you can simply use the value of the metric prometheus_config_last_reload_success_timestamp_seconds, multiplied by 1000 to have the timestamp in msec (as expected by Grafana). And there is a tick box at the bottom of the annotation panel Series value as timestamp to active.
Save your dashboard and that's all.

How to properly monitor ELB latency on AWS using Grafana?

I am trying to monitor Latency on ElasticBeanstalk environment using Grafana.
I get some things to work, and some things do not provide any information.
I am using "CloudWatch" data source.
There is ELB and ApplicationELB.
The ApplicationELB does not offer Latency metric. In fact, every metric I select here will result with "no data".
When I configure monitoring on AWS, I get this following graph:
I am able to query for Latency on a region using Grafana and I do get some correlation
As you can see around 13:50 some requests timed-out. But it is also obvious Grafana is showing additional information from other environments which I would like to ignore.
My query currently looks like this:
Which I know is too broad, but I do not know how to refine.
I tried using "InstanceName" as dimension, but it is not clear to me which ELB I should look for, and seems to me like ApplicationELB should be what I am looking for, but that one does not offer Latency and does not provide any data either way.
Using AvailabilityZone does not help, and that's the only other option for dimension (other than InstanceName).
I need a way to refine the query so I see the same result in AWS and Grafana.
A clarification about ApplicationELB and ELB would be great also!
Application ELB vs ELB: they are just different types of load balancers provided by AWS https://aws.amazon.com/elasticloadbalancing/ - I'm not sure which one is used by ElasticBeanstalk.
You need to add dimension to filter your metrics. Some metrics may need multiple dimensions for correct filtering. Available dimensions are available in the docs. For example LoadBalancerName is a correct dimension for AWS/ELB namespace: https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html
I recommend to use existing published AWS dashboard(s) (https://github.com/monitoringartist/grafana-aws-cloudwatch-dashboards - I'm the author) and then just customize them for your needs.

How to differentiate between equally-named Prometheus metrics from dynamically discovered micro-services in Kubernetes

I’m looking for a way to differentiate between Prometheus metrics gathered from different dynamically discovered services running in a Kubernetes cluster (we’re using https://github.com/coreos/prometheus-operator). E.g. for the metrics written into the db, I would like to understand from which service they actually came.
I guess you can do this via a label from within the respective services, however, swagger-stats (http://swaggerstats.io/) which we’re using does not yet offer this functionality (to enhance this, there is an issue open: https://github.com/slanatech/swagger-stats/issues/50).
Is there a way to implement this over Prometheus itself, e.g. that Prometheus adds a service-specific label per time series after a scrape?
Appreciate your feedback!
Is there a way to implement this over Prometheus itself, e.g. that Prometheus adds a service-specific label per time series after a scrape?
This is how Prometheus is designed to be used, as a target doesn't know how the monitoring system views it and prefixing metric names makes cross-service analysis harder. Both setting labels across an entire target and prefixing metric names are considered anti-patterns.
What you want is called a target label, these usually come from relabelling applied to metadata from service discovery.
When using the Prometheus Operator, you can specify targetLabels as a list of labels to copy from the Kubernetes Service to the Prometheus targets.