#!/bin/sh
#
# Construct pmlogrewrite rules ...
# kernel_ulong.conf
#	Needs to be done dynamically because the type of KERNEL_ULONG is
#	platform dependent.
#

tmp=/var/tmp/$$
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15

cat <<End-of-File >$tmp.c
#include <pcp/platform_defs.h>
#if defined(HAVE_64BIT_LONG)
KERNEL_ULONG=PM_TYPE_U64
#elif defined(HAVE_32BIT_LONG)
KERNEL_ULONG=PM_TYPE_U32
#else
# bozo!
#endif
End-of-File

eval `${CPP-cpp} -I${INCDIR-.} $tmp.c \
      | sed -n -e '/KERNEL_ULONG/s/PM_TYPE_//p'`

cat <<End-of-File >kernel_ulong.conf
# These metrics are all exported from the linux PMDA
# using the KERNEL_ULONG type which might be U32
# or could be U64.
#
# Order here matches metadata definition order in pmda.c to help
# make it easier to spot differences.
#

metric disk.dev.read { type -> $KERNEL_ULONG }
metric disk.dev.write { type -> $KERNEL_ULONG }
metric disk.dev.blkread { type -> $KERNEL_ULONG }
metric disk.dev.blkwrite { type -> $KERNEL_ULONG }
metric disk.dev.read_merge { type -> $KERNEL_ULONG }
metric disk.dev.write_merge { type -> $KERNEL_ULONG }
metric kernel.all.sysfork { type -> $KERNEL_ULONG }
metric kernel.all.running { type -> $KERNEL_ULONG }
metric kernel.all.blocked { type -> $KERNEL_ULONG }
metric mem.buddyinfo.pages { type -> $KERNEL_ULONG }
metric nfs.server.threads.requests { type -> $KERNEL_ULONG }
metric nfs.server.threads.enqueued { type -> $KERNEL_ULONG }
metric nfs.server.threads.processed { type -> $KERNEL_ULONG }
metric nfs.server.threads.timedout { type -> $KERNEL_ULONG }
metric disk.partitions.read { type -> $KERNEL_ULONG }
metric disk.partitions.write { type -> $KERNEL_ULONG }
metric disk.partitions.total { type -> $KERNEL_ULONG }
metric disk.partitions.blkread { type -> $KERNEL_ULONG }
metric disk.partitions.blkwrite { type -> $KERNEL_ULONG }
metric disk.partitions.blktotal { type -> $KERNEL_ULONG }
metric disk.partitions.read_bytes { type -> $KERNEL_ULONG }
metric disk.partitions.write_bytes { type -> $KERNEL_ULONG }
metric disk.partitions.total_bytes { type -> $KERNEL_ULONG }
metric disk.partitions.read_merge { type -> $KERNEL_ULONG }
metric disk.partitions.write_merge { type -> $KERNEL_ULONG }
metric disk.dev.read_bytes { type -> $KERNEL_ULONG }
metric disk.dev.write_bytes { type -> $KERNEL_ULONG }
metric disk.dev.total_bytes { type -> $KERNEL_ULONG }
metric disk.all.read_bytes { type -> $KERNEL_ULONG }
metric disk.all.write_bytes { type -> $KERNEL_ULONG }
metric disk.all.total_bytes { type -> $KERNEL_ULONG }
metric mem.ksm.full_scans { type -> $KERNEL_ULONG }
metric mem.ksm.merge_across_nodes { type -> $KERNEL_ULONG }
metric mem.ksm.pages_shared { type -> $KERNEL_ULONG }
metric mem.ksm.pages_sharing { type -> $KERNEL_ULONG }
metric mem.ksm.pages_to_scan { type -> $KERNEL_ULONG }
metric mem.ksm.pages_unshared { type -> $KERNEL_ULONG }
metric mem.ksm.pages_volatile { type -> $KERNEL_ULONG }
metric mem.ksm.run_state { type -> $KERNEL_ULONG }
metric mem.ksm.sleep_time { type -> $KERNEL_ULONG }
metric disk.dm.read { type -> $KERNEL_ULONG }
metric disk.dm.write { type -> $KERNEL_ULONG }
metric disk.dm.blkread { type -> $KERNEL_ULONG }
metric disk.dm.blkwrite { type -> $KERNEL_ULONG }
metric disk.dm.read_merge { type -> $KERNEL_ULONG }
metric disk.dm.write_merge { type -> $KERNEL_ULONG }
metric disk.md.read { type -> $KERNEL_ULONG }
metric disk.md.write { type -> $KERNEL_ULONG }
metric disk.md.blkread { type -> $KERNEL_ULONG }
metric disk.md.blkwrite { type -> $KERNEL_ULONG }
metric disk.md.read_merge { type -> $KERNEL_ULONG }
metric disk.md.write_merge { type -> $KERNEL_ULONG }

# these ones were KERNEL_ULONG at a point of time in the past, but the
# current PMDA exports them as U64
#
metric disk.dev.total { type -> U64 }
metric disk.dev.blktotal { type -> U64 }

# and this one was KERNEL_ULONG in this file, but that was incorrect
#
metric disk.dm.total { type -> U64 }
End-of-File

exit 0
