Define Function

Updated 1 month ago by Shoreline

Define resource

Syntax:  resource <resource_name> = resources(type=”xxx”) where “xxx” is a resource type such as container, pod. VMs...etc.

Examples:

  • op> resource host = resources(type="HOST")
  • op> resource pod = resources(type="POD")
  • op> resource aws = resources() | cloud_provider="aws"

"Host" is case sensitive

Define metric

Syntax: metric <metric_name> = <expression>

Examples:

  • op> metric cpu_usage = 100 - 100 * (metric_query(metric_names="node_cpu_seconds_total", tags={"mode":"idle"}) | irate(2) | r_mean)
  • op> metric pod_reqs_250m_percentile = 100 * pod_reqs_250m_bucket / pod_reqs_count

Define alarm

Syntax: alarm <alarm_name> = <condition>

Examples:

  • op> alarm cpu_alarm = cpu_usage > 90
  • op> alarm high_disk = pod_disk_usage > 60
After defining the alarm, you need to specify the resource query. In the above examples, you would specify the resources for cpu_alarm with op> cpu_alarm.resource_query=host -and - you would specify the high_disk resource afterwards with op> high_disk.resource_query=pod

Define action

Syntax:  action <action_name> = `<shell command>`

Examples:

  • op> action temp_files = `find /tmp -size +100M`
  • op> action drop_page_cache = `sync; echo 1 > /proc/sys/vm/drop_caches`
After defining the action, you need to specify the resource query. In the above examples, you would specify the resources for temp_files with op> temp_files.resource_query=host -and - you would specify the drop_page_cache resource afterwards with op> drop_page_cache.resource_query=host | .pod

Define bot

Syntax:  bot <bot_name> = if <alarm_name> then <action_name> fi

Example:

  • op> bot cache_free = if mem_alarm then drop_page_cache fi


How did we do?