Python Version

Create the file util1.py with the following content to increment the counter statistics in this example. See the libsstore(python) man page for information about the Python libsstore library, the SStore class, and the data_attach() method.

#!/usr/bin/python

# Example program to provide statistics values using Python data_attach().

import time
import random
from libsstore import SStore

ssids = [
    "//:class.app/util1//:stat.reads",
    "//:class.app/util1//:stat.writes",
    "//:class.app/util1//:stat.errors"
]

# Get an instance of the SStore class.
ss = SStore()

# Set up the shared memory region.
try:
    stats = ss.data_attach(ssids)
except:
    print("data_attach() failed. Reason {0}".format(
        ss.err_description))
    exit(1)

# Update statistics every second.
for i in range (500):
    stats[0] += random.randint(2,6)
    stats[1] += random.randint(1,4)
    stats[2] += random.randint(0,1)
    time.sleep(1)