---

metric:
  # Image
  - name: "image.size"
    event_type:
      - "image.upload"
      - "image.delete"
      - "image.update"
    type: "gauge"
    unit: B
    volume: $.payload.size
    resource_id: $.payload.id
    project_id: $.payload.owner

  - name: "image.download"
    event_type: "image.send"
    type: "delta"
    unit: "B"
    volume: $.payload.bytes_sent
    resource_id: $.payload.image_id
    user_id: $.payload.receiver_user_id
    project_id: $.payload.receiver_tenant_id

  - name: "image.serve"
    event_type: "image.send"
    type: "delta"
    unit: "B"
    volume: $.payload.bytes_sent
    resource_id: $.payload.image_id
    project_id: $.payload.owner_id

  # MagnetoDB
  - name: 'magnetodb.table.index.count'
    type: 'gauge'
    unit: 'index'
    event_type: 'magnetodb.table.create.end'
    volume: $.payload.index_count
    resource_id: $.payload.table_uuid
    user_id: $._context_user

  - name: 'volume.size'
    event_type:
      - 'volume.exists'
      - 'volume.create.*'
      - 'volume.delete.*'
      - 'volume.resize.*'
      - 'volume.attach.*'
      - 'volume.detach.*'
      - 'volume.update.*'
    type: 'gauge'
    unit: 'GB'
    volume: $.payload.size
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.volume_id

  - name: 'snapshot.size'
    event_type:
      - 'snapshot.exists'
      - 'snapshot.create.*'
      - 'snapshot.delete.*'
    type: 'gauge'
    unit: 'GB'
    volume: $.payload.volume_size
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.snapshot_id

  # Magnum
  - name: $.payload.metrics.[*].name
    event_type: 'magnum.bay.metrics.*'
    type: 'gauge'
    unit: $.payload.metrics.[*].unit
    volume: $.payload.metrics.[*].value
    user_id: $.payload.user_id
    project_id: $.payload.project_id
    resource_id: $.payload.resource_id
    lookup: ['name', 'unit', 'volume']

  # Swift
  - name: $.payload.measurements.[*].metric.[*].name
    event_type: 'objectstore.http.request'
    type: 'delta'
    unit: $.payload.measurements.[*].metric.[*].unit
    volume: $.payload.measurements.[*].result
    resource_id: $.payload.target.id
    user_id: $.payload.initiator.id
    project_id: $.payload.initiator.project_id
    lookup: ['name', 'unit', 'volume']

  - name: 'memory'
    event_type: 'compute.instance.*'
    type: 'gauge'
    unit: 'MB'
    volume: $.payload.memory_mb
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.instance_id

  - name: 'vcpus'
    event_type: 'compute.instance.*'
    type: 'gauge'
    unit: 'vcpu'
    volume: $.payload.vcpus
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.instance_id

  - name: 'disk.root.size'
    event_type: 'compute.instance.*'
    type: 'gauge'
    unit: 'GB'
    volume: $.payload.root_gb
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.instance_id

  - name: 'disk.ephemeral.size'
    event_type: 'compute.instance.*'
    type: 'gauge'
    unit: 'GB'
    volume: $.payload.ephemeral_gb
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.instance_id

  - name: 'bandwidth'
    event_type: 'l3.meter'
    type: 'delta'
    unit: 'B'
    volume: $.payload.bytes
    project_id: $.payload.tenant_id
    resource_id: $.payload.label_id

  - name: 'compute.node.cpu.frequency'
    event_type: 'compute.metrics.update'
    type: 'gauge'
    unit: 'MHz'
    volume: $.payload.metrics[?(@.name='cpu.frequency')].value
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.frequency')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.frequency')].source

  - name: 'compute.node.cpu.user.time'
    event_type: 'compute.metrics.update'
    type: 'cumulative'
    unit: 'ns'
    volume: $.payload.metrics[?(@.name='cpu.user.time')].value
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.user.time')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.user.time')].source

  - name: 'compute.node.cpu.kernel.time'
    event_type: 'compute.metrics.update'
    type: 'cumulative'
    unit: 'ns'
    volume: $.payload.metrics[?(@.name='cpu.kernel.time')].value
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.kernel.time')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.kernel.time')].source

  - name: 'compute.node.cpu.idle.time'
    event_type: 'compute.metrics.update'
    type: 'cumulative'
    unit: 'ns'
    volume: $.payload.metrics[?(@.name='cpu.idle.time')].value
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.idle.time')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.idle.time')].source

  - name: 'compute.node.cpu.iowait.time'
    event_type: 'compute.metrics.update'
    type: 'cumulative'
    unit: 'ns'
    volume: $.payload.metrics[?(@.name='cpu.iowait.time')].value
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.iowait.time')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.iowait.time')].source

  - name: 'compute.node.cpu.kernel.percent'
    event_type: 'compute.metrics.update'
    type: 'gauge'
    unit: 'percent'
    volume: $.payload.metrics[?(@.name='cpu.kernel.percent')].value * 100
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.kernel.percent')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.kernel.percent')].source

  - name: 'compute.node.cpu.idle.percent'
    event_type: 'compute.metrics.update'
    type: 'gauge'
    unit: 'percent'
    volume: $.payload.metrics[?(@.name='cpu.idle.percent')].value * 100
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.idle.percent')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.idle.percent')].source

  - name: 'compute.node.cpu.user.percent'
    event_type: 'compute.metrics.update'
    type: 'gauge'
    unit: 'percent'
    volume: $.payload.metrics[?(@.name='cpu.user.percent')].value * 100
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.user.percent')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.user.percent')].source

  - name: 'compute.node.cpu.iowait.percent'
    event_type: 'compute.metrics.update'
    type: 'gauge'
    unit: 'percent'
    volume: $.payload.metrics[?(@.name='cpu.iowait.percent')].value * 100
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.iowait.percent')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.iowait.percent')].source

  - name: 'compute.node.cpu.percent'
    event_type: 'compute.metrics.update'
    type: 'gauge'
    unit: 'percent'
    volume: $.payload.metrics[?(@.name='cpu.percent')].value * 100
    resource_id: $.payload.host + "_" + $.payload.nodename
    timestamp: $.payload.metrics[?(@.name='cpu.percent')].timestamp
    metadata:
      event_type: $.event_type
      host: $.publisher_id
      source: $.payload.metrics[?(@.name='cpu.percent')].source


# NOTE: non-metric meters are generally events/existence meters
# These are DEPRECATED in current release and expected to be
# REMOVED in the next upcoming release.
#
  # Image
  - name: "image"
    event_type:
      - "image.upload"
      - "image.update"
      - "image.delete"
    type: "gauge"
    unit: 'image'
    volume: 1
    resource_id: $.payload.id
    project_id: $.payload.owner

  - name: "image.upload"
    event_type:
      - "image.upload"
    type: "gauge"
    unit: 'image'
    volume: 1
    resource_id: $.payload.id
    project_id: $.payload.owner

  - name: "image.delete"
    event_type:
      - "image.delete"
    type: "gauge"
    unit: 'image'
    volume: 1
    resource_id: $.payload.id
    project_id: $.payload.owner

  - name: "image.update"
    event_type:
      - "image.update"
    type: "gauge"
    unit: 'image'
    volume: 1
    resource_id: $.payload.id
    project_id: $.payload.owner

  # Orchestration
  - name: 'stack.create'
    event_type:
      - 'orchestration.stack.create.end'
    type: 'delta'
    unit: 'stack'
    volume: 1
    user_id: _context_trustor_user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.stack_identity

  - name: 'stack.update'
    event_type:
      - 'orchestration.stack.update.end'
    type: 'delta'
    unit: 'stack'
    volume: 1
    user_id: _context_trustor_user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.stack_identity

  - name: 'stack.delete'
    event_type:
      - 'orchestration.stack.delete.end'
    type: 'delta'
    unit: 'stack'
    volume: 1
    user_id: _context_trustor_user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.stack_identity

  - name: 'stack.resume'
    event_type:
      - 'orchestration.stack.resume.end'
    type: 'delta'
    unit: 'stack'
    volume: 1
    user_id: _context_trustor_user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.stack_identity

  - name: 'stack.suspend'
    event_type:
      - 'orchestration.stack.suspend.end'
    type: 'delta'
    unit: 'stack'
    volume: 1
    user_id: _context_trustor_user_id
    project_id: $.payload.tenant_id
    resource_id: $.payload.stack_identity

  # MagnetoDB
  - name: 'magnetodb.table.create'
    type: 'gauge'
    unit: 'table'
    volume: 1
    event_type: 'magnetodb.table.create.end'
    resource_id: $.payload.table_uuid
    user_id: _context_user
    project_id: _context_tenant

  - name: 'magnetodb.table.delete'
    type: 'gauge'
    unit: 'table'
    volume: 1
    event_type: 'magnetodb.table.delete.end'
    resource_id: $.payload.table_uuid
    user_id: _context_user
    project_id: _context_tenant

  # Volume
  - name: 'volume'
    type: 'gauge'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.exists'
      - 'volume.create.*'
      - 'volume.delete.*'
      - 'volume.resize.*'
      - 'volume.attach.*'
      - 'volume.detach.*'
      - 'volume.update.*'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.exists'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.exists'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.create.start'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.create.start'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.create.end'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.create.end'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.delete.start'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.delete.start'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.delete.end'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.delete.end'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.update.end'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.update.end'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.update.start'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.update.start'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.resize.end'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.resize.end'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.resize.start'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.resize.start'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id


  - name: 'volume.attach.end'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.attach.end'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.attach.start'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.attach.start'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.detach.end'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.detach.end'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'volume.detach.start'
    type: 'delta'
    unit: 'volume'
    volume: 1
    event_type:
      - 'volume.detach.start'
    resource_id: $.payload.volume_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  # Volume Snapshot
  - name: 'snapshot'
    type: 'gauge'
    unit: 'snapshot'
    volume: 1
    event_type:
      - 'snapshot.exists'
      - 'snapshot.create.*'
      - 'snapshot.delete.*'

    resource_id: $.payload.snapshot_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'snapshot.exists'
    type: 'delta'
    unit: 'snapshot'
    volume: 1
    event_type:
      - 'snapshot.exists'
    resource_id: $.payload.snapshot_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'snapshot.create.start'
    type: 'delta'
    unit: 'snapshot'
    volume: 1
    event_type:
      - 'snapshot.create.start'
    resource_id: $.payload.snapshot_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'snapshot.create.end'
    type: 'delta'
    unit: 'snapshot'
    volume: 1
    event_type:
      - 'snapshot.create.end'
    resource_id: $.payload.snapshot_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'snapshot.delete.start'
    type: 'delta'
    unit: 'snapshot'
    volume: 1
    event_type:
      - 'snapshot.delete.start'
    resource_id: $.payload.snapshot_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  - name: 'snapshot.delete.end'
    type: 'delta'
    unit: 'snapshot'
    volume: 1
    event_type:
      - 'snapshot.delete.end'
    resource_id: $.payload.snapshot_id
    user_id: $.payload.user_id
    project_id: $.payload.tenant_id

  # Sahara
  - name: 'cluster.create'
    type: 'delta'
    unit: 'cluster'
    volume: 1
    event_type:
      - 'sahara.cluster.create'
    resource_id: $.payload.cluster_id
    project_id: $.payload.project_id

  - name: 'cluster.update'
    type: 'delta'
    unit: 'cluster'
    volume: 1
    event_type:
      - 'sahara.cluster.update'
    resource_id: $.payload.cluster_id
    project_id: $.payload.project_id

  - name: 'cluster.delete'
    type: 'delta'
    unit: 'cluster'
    volume: 1
    event_type:
      - 'sahara.cluster.delete'
    resource_id: $.payload.cluster_id
    project_id: $.payload.project_id

  # Identity
  - name: 'identity.user.created'
    type: 'delta'
    unit: 'user'
    volume: 1
    event_type:
      - 'identity.user.created'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.user.updated'
    type: 'delta'
    unit: 'user'
    volume: 1
    event_type:
      - 'identity.user.updated'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.user.deleted'
    type: 'delta'
    unit: 'user'
    volume: 1
    event_type:
      - 'identity.user.deleted'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.group.created'
    type: 'delta'
    unit: 'group'
    volume: 1
    event_type:
      - 'identity.group.created'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.group.updated'
    type: 'delta'
    unit: 'group'
    volume: 1
    event_type:
      - 'identity.group.updated'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.group.deleted'
    type: 'delta'
    unit: 'group'
    volume: 1
    event_type:
      - 'identity.group.deleted'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.project.created'
    type: 'delta'
    unit: 'project'
    volume: 1
    event_type:
      - 'identity.project.created'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.project.updated'
    type: 'delta'
    unit: 'project'
    volume: 1
    event_type:
      - 'identity.project.updated'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.project.deleted'
    type: 'delta'
    unit: 'project'
    volume: 1
    event_type:
      - 'identity.project.deleted'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.role.created'
    type: 'delta'
    unit: 'role'
    volume: 1
    event_type:
      - 'identity.role.created'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.role.updated'
    type: 'delta'
    unit: 'role'
    volume: 1
    event_type:
      - 'identity.role.updated'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.role.deleted'
    type: 'delta'
    unit: 'role'
    volume: 1
    event_type:
      - 'identity.role.deleted'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.role_assignment.created'
    type: 'delta'
    unit: 'role_assignment'
    volume: 1
    event_type:
      - 'identity.role_assignment.created'
    resource_id: $.payload.role
    user_id: $.payload.initiator.id

  - name: 'identity.role_assignment.deleted'
    type: 'delta'
    unit: 'role_assignment'
    volume: 1
    event_type:
      - 'identity.role_assignment.deleted'
    resource_id: $.payload.role
    user_id: $.payload.initiator.id

  - name: 'identity.authenticate.success'
    type: 'delta'
    unit: 'user'
    volume: 1
    event_type:
      - 'identity.authenticate'
    resource_id: $.payload.initiator.id
    user_id: $.payload.initiator.id

  - name: 'identity.authenticate.pending'
    type: 'delta'
    unit: 'user'
    volume: 1
    event_type:
      - 'identity.authenticate'
    resource_id: $.payload.initiator.id
    user_id: $.payload.initiator.id

  - name: 'identity.authenticate.failure'
    type: 'delta'
    unit: 'user'
    volume: 1
    event_type:
      - 'identity.authenticate'
    resource_id: $.payload.initiator.id
    user_id: $.payload.initiator.id

  - name: 'identity.trust.created'
    type: 'delta'
    unit: 'trust'
    volume: 1
    event_type:
      - 'identity.OS-TRUST:trust.created'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'identity.trust.deleted'
    type: 'delta'
    unit: 'trust'
    volume: 1
    event_type:
      - 'identity.OS-TRUST:trust.deleted'
    resource_id: $.payload.resource_info
    user_id: $.payload.initiator.id

  - name: 'storage.api.request'
    type: 'delta'
    unit: 'request'
    volume: 1
    event_type:
      - 'objectstore.http.request'
    resource_id: $.payload.target.id
    user_id: $.payload.initiator.id
    project_id: $.payload.initiator.project_id

  - name: '$.payload.name'
    event_type: 'profiler.*'
    type: 'gauge'
    unit: 'trace'
    volume: 1
    user_id: $.payload.user_id
    project_id: $.payload.project_id
    resource_id: '"profiler-" + $.payload.base_id'
