Use PromQL
PromQL is available only in Sysdig SaaS editions. The feature is not supported for Sysdig on-premises installations.
Sysdig Monitor’s PromQL support includes all of the features, functions, and aggregations in standard open-source PromQL.
Get Started with PromQL
To get started with the language, see:
- Prometheus Query Basics.
- See the curated list of PromQL queries and build sample dashboards.
- Learn how to use PromQL Query Explorer
- Learn how to create a Prometheus Alert.
- Read the Prometheus Monitoring Guide
- Run PromQL Queries Faster with Extended Label Set
Enrich Metrics with Labels
Running PromQL queries in Sysdig Monitor by default returns only a minimum set of labels. To enrich the return results of PromQL queries with additional labels, such as Kubernetes cluster name, you need to use a vector matching operation. The vector matching operation in Prometheus is similar to the SQL-like join operation.
Info Metrics
Prometheus returns different information metrics that have a value of 1 with several labels. The information that the info metrics return might not be useful as it is. However, joining the labels of an info metric with a non-info metric can provide useful information, such as the value of metric X across an infrastructure/application/deployment.
Vector Matching Operation
The vector matching operation is similar to an SQL join. You use a vector matching operation to build a PromQL query that can return metrics with information from your infrastructure. Vector matching helps filter and enrich labels, usually adding information labels to the metrics you are trying to visualize.
See Mapping Between Classic Metrics and PromQL Metrics for a list of info metrics.
Example 1: Return a Metric Filtered by Cluster
This example shows a metric returned by an application, say
myapp_guage, running on Kubernetes. The query attempts at getting an
aggregated value of a cluster, by having one cluster selected in the
scope. We assume that previously you have set a $cluster variable in
your scope.
To do so, run the following query to return the myapp_guage metrics:
sum (myapp_gauge * on (container_id) kube_pod_container_info{cluster=$cluster})
The query performs the following operations, not necessarily in this order:
The
kube_pod_container_infoinfo metrics is filtered, selecting only those timeseries and the associated cluster values you want to see. The selection is based on theclusterlabel.The
myapp_gaugemetric is matched with thekube_pod_container_infometric where thecontainer_idlabel has the same value, multiplying both the values. Because the info metric has the value 1, multiplying the values doesn’t change the result. As the info metric has already been filtered by a cluster, only those values associated with the cluster will be kept.The resultant timeseries with the value of
myapp_gaugeare then aggregated with the sum function and the result is returned.
Example 2: Calculate the GC Latency
This example shows calculating the GC latency in a go application deployed on a specific Kubernetes namespace.
To calculate the GC latency, run the following query:
go_gc_duration_seconds * on (container_id,host_mac) group_left(pod,namespace) kube_pod_container_info{namespace=~$namespace}
The query is performing the following operations:
The
kube_pod_container_infoinfo metrics are filtered based on the namespace variable.The metrics associated with
go_gc_duration_secondsis matched in a many-to-one way with the filteredkube_pod_container_info.The pod and namespace labels are added from the
kube_pod_container_infometric to the result. The query keeps only those metrics that have the matchingcontainer_idandhost_maclabels on both sides.The values are multiplied and the resulting metrics are returned. The new metrics will only have the values associated with
go_gc_duration_secondsbecause the info metric value is always 1.
You can use any Prometheus metric in the query. For example, the query above can be rewritten for a sample Apache metric as follows:
appinfo_apache_net_bytes * on (container_id) group_left(pod, namespace) kube_pod_container_info{namespace=~$namespace}
Example 3: Calculate Average CPU Used Percent in AWS Hosts
This example shows calculating the average CPU used percent per AWS account and region, having the hosts filtered by account and region.
avg by(region,account_id) (sysdig_host_cpu_used_percent * on (host_mac) group_left(region,account_id) sysdig_cloud_provider_info{account_id=~$AWS_account, region=~$AWS_region})
The query performs the following operations:
Filters the
sysdig_cloud_provider_infometric based on theaccount_idandregionlabels that come from the dashboard scope as variables.Matches the
sysdig_host_cpu_used_percentmetrics withsysdig_cloud_provider_info. Only those metrics with the samehost_maclabel on both sides are extracted, addingregionandaccount_idlabels to the resulting metrics.Calculates the average of the new metrics by
account_idandregion.
Example 4: Calculate Total CPU Usage in Deployments
This example shows calculating the total CPU usage per deployment. The value can also be filtered by cluster, namespace, and deployment by using the dashboard scope.
sum by(cluster,namespace,owner_name) ((sysdig_container_cpu_cores_used * on(container_id) group_left(pod,namespace,cluster) kube_pod_container_info) * on(pod,namespace,cluster) group_left(owner_name) kube_pod_owner{owner_kind="Deployment",owner_name=~$deployment,cluster=~$cluster,namespace=~$namespace})
sysdig_container_cpu_cores_usedcan be replaced by any metric that has thecontainer_idlabel.To connect the
sysdig_container_cpu_cores_usedmetric with the pod, usekube_pod_container_infoand then, usekube_pod_ownerto connect the pod to other kubernetes objects.
The query performs the following:
sysdig_container_cpu_cores_used * on(container_id) group_left(pod,namespace,cluster) kube_pod_container_info:The
sysdig_container_cpu_cores_usedmetric value is multiplied withkube_pod_container_info(which has the value of 1), by matchingcontainer_idand by keeping the pod, namespace and cluster labels as it is._name_='sysdig_container_cpu_cores_used',container='<label>', container_id='<label>',container_type='DOCKER`,host_mac='<label>'The new metrics will be
cluster='<label>',container='<label>', container_id='<label>',container_type='DOCKER`,host_mac='<label>',namespace='<label>, pod='<label>'
The value extracted from the previous result is multiplied with
kube_pod_owner(which has the value of 1) by matching on the pod, namespace, and cluster labels and keeping the owner name from the value ofkube_pod_owner. The owner can be deployment, replicaset, service, daemonset, or statefulset object.The name of the deployment to filter upon is extracted from the
kube_pod_ownermetrics.The pod, namespace, and cluster names are extracted from the
kube_pod_container_infometrics.
The new metrics will be:
cluster='<matched_label>',container='<matched_container_label>', container_id='<label>',container_type='DOCKER,host_mac=’The
kube_pod_ownerwill have a labelowner_namethat is the name of the object that owns the pod. This value is extracted by filtering:kube_pod_owner{owner_kind="Deployment",owner_name=~$deployment,cluster=~$cluster,namespace=~$namespace}The
owner_kindprovides the deployment name and the origin ofowner_name, that is the dashboard scope.The sum aggregation is applied and the time series are aggregated by cluster, namespace, and deployment.
The following table helps understand the labels applied in each step of the query:
| __name__ | container_id | container | container_type | host_mac | pod | namespace | cluster | owner_name | |
|---|---|---|---|---|---|---|---|---|---|
sysdig_container_cpu_cores_used * on(container_id) group_left(pod,namespace,cluster) kube_pod_container_info | No | Yes | Yes | Yes | Yes | Yes | Yes | Yes | No |
(sysdig_container_cpu_cores_used * on(container_id) group_left(pod,namespace,cluster) kube_pod_container_info) * on(pod,namespace,cluster) group_left(owner_name) kube_pod_owner{owner_kind="Deployment",owner_name=~$deployment,cluster=~$cluster,namespace=~$namespace} | No | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
sum by(cluster,namespace,owner_name) ((sysdig_container_cpu_cores_used * on(container_id) group_left(pod,namespace,cluster) kube_pod_container_info) * on(pod,namespace,cluster) group_left(owner_name) kube_pod_owner{owner_kind="Deployment",owner_name=~$deployment,cluster=~$cluster,namespace=~$namespace}) | No | No | No | No | No | No | Yes | Yes | Yes |
Formatting
Sysdig Monitor supports percentages only as 0-100 values. In calculated ratios, you can skip multiplying the whole query times 100 by selecting percentage as a 0-1 value.