#!/bin/sh
#
# Construct pmlogrewrite rules ...
# linux_kernel_ulong.conf
#	Needs to be done dynamically because the type of KERNEL_ULONG is
#	platform dependent.
# linux_kernel_fixups.conf
#	Miscellaneous corrections to metadata for the linux PMDA.
#

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

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

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

cat <<End-of-File >linux_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.
#
# disk.dev group
#
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 }

# disk.partitions group
#
metric disk.partitions.read { type -> $KERNEL_ULONG }
metric disk.partitions.write { type -> $KERNEL_ULONG }
metric disk.partitions.blkread { type -> $KERNEL_ULONG }
metric disk.partitions.blkwrite { type -> $KERNEL_ULONG }

# disk.dm group
#
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 }

# miscellaneous group
#
metric kernel.all.sysfork { type -> $KERNEL_ULONG }

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

cat <<End-of-File >linux_kernel_fixups.conf
# These metrics are all exported from the linux PMDA and
# parts of their metadata have changed over time to fix
# previous errors.
#
# The rules here allow rewriting of old archives to produce
# archives with metadata that matches the current PMDA
# implementation.

# swapdev.priority had the wrong Units:
#
metric swapdev.priority { units -> 0,0,0,0,0,0 }

# network.interface.baudrate changed to 64 bits:
#
metric network.interface.baudrate { type -> U64 }

# hinv.cpu.cache had incorrect units:
#
metric hinv.cpu.cache { units -> 1,0,0,KBYTE,0,0 }

# hinv.cpu.clock is frequency in MHz which had incorrect units:
#
metric hinv.cpu.clock { units -> 0,-1,0,0,USEC,0 }

# several string typed metrics should be discrete; their string value
# prevails over time and changes very infrequently, if at all.
#
metric kernel_uname.release { sem -> discrete }
metric kernel.uname.version { sem -> discrete }
metric kernel.uname.sysname { sem -> discrete }
metric kernel.uname.machine { sem -> discrete }
metric kernel.uname.nodename { sem -> discrete }
metric kernel.uname.distro { sem -> discrete }
metric pmda.uname { sem -> discrete }
metric pmda.version { sem -> discrete }
metric disk.dev.scheduler { sem -> discrete }
metric network.interface.inet_addr { sem -> discrete }
metric network.interface.ipv6_addr { sem -> discrete }
metric network.interface.ipv6_scope { sem -> discrete }
metric network.interface.hw_addr { sem -> discrete }

End-of-File

cat <<End-of-File >proc_net_sockstat_deprecate.conf

# Copyright 2017 Red Hat.
#
# pmlogrewrite configuration for deprecating network.sockstat.{tcp,udp,raw}.{highest,util}
#
metric network.sockstat.tcp.highest { DELETE }
metric network.sockstat.tcp.util { DELETE }
metric network.sockstat.udp.highest { DELETE }
metric network.sockstat.udp.util { DELETE }
metric network.sockstat.raw.highest { DELETE }
metric network.sockstat.raw.util { DELETE }

End-of-File

exit 0
