HP3000-L Archives

February 1997, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jim Alton <[log in to unmask]>
Reply To:
Date:
Thu, 6 Feb 1997 13:32:57 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (121 lines)
 My previous post mentioned the resolution of my problems with snmp
in attempting to gather cpuUtilization.

 I now have a simple little C program that take the date and time,
HPUSERCOUNT, HPJOBCOUNT and the cpuUtilization (from snmp) and prints
it to stdout in a tabular format.  From here I intend to suck the
data into Microsoft Excel and produce graphs that will shake
management to it's very foundations... ok well, maybe not.

 In any case, I thought someone else might want to use the code so
here it is... standard disclaimers apply....  feel free to munge the
code as you see fit.  Don't hold me (or my employer) responsible for
any of this...

 A few things... the program will attempt to automatically enable the
Measurement Interface on your system but does not shut it down.  This
can create an initial performance hit and will consume some
resources while it is enabled.  The program needs to run for a user
with NM capability and your SNMPCONF.NET.SYS must be configured with
a setting in agent-community-name.  The source code that follows has
XXXX as the community name, you will need to alter this for your
site.  Compilation is a normal CCXLLK source, binary, $NULL.

Good luck, have fun, don't call.

Jim
/*****************
 *
 * JSTATS
 *
 *  This program is being developed as a step toward gather usage
 * information on the HP3000.  At this point it checks active Sessions
 * and Jobs.
 *
 *
 *  Jim Alton - January 23, 1997
 *
 * Modified:   Feb. 6/1997
 *             - Add snmp capability to get cpuUtilization.
 *
 *****************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <mpe.h>

main()
{
   int sessions, jobs;
   char *env, *datetime;
   char *syscomm, *varreturn;
   int MIenabled, cpuUt;
   FILE *in;

   datetime = malloc(80);
   env = malloc(80);
   syscomm = malloc(128);
   varreturn = malloc(128);

   /* Let's see if the Measurement Interface is enabled */
   strcpy(syscomm, "snmpget.net.sys XXXX schmart hp.nm.system.general.\
mpexlsystem.processor.processormistate.0 > snmptemp");
   if(system(syscomm) != 0) {
     printf("Error with command to collect Measurement Interface status\n");
     exit(10);
   }

   if((in=fopen("snmptemp", "r")) == NULL) {
     printf("Error opening tempfile for Measurement Interface status\n");
     exit(11);
   }
   /* Read from the tempfile, throw away the first line */
   fgets(varreturn, 128, in);
   fgets(varreturn, 128, in);
   fclose(in);

   /* If the MI is disabled - enable it */
   if((strstr(varreturn, "enabled")) == NULL) {
     strcpy(syscomm, "snmpset.net.sys genesis XXXX hp.nm.system.general.\
mpexlsystem.processor.processormistate integer 1 > snmptemp");
     system(syscomm);
     sleep(3);
   }

   /* Ok... now let's try to get the value for cpuUtilization */
   strcpy(syscomm, "snmpget.net.sys genesis XXXX hp.nm.system.\
general.mpexlsystem.processor.cpuutilization.0 > snmptemp");
  if((system(syscomm)) != 0 ) {
    printf("Error with command to collect Cpu Utilization\n");
    exit(12);
  }

   if((in = fopen("snmptemp", "r")) == NULL) {
     printf("Error opening tempfile for Cpu Utilization\n");
     exit(14);
   }

   /* Throw away the first line of the temp file */
   fgets(varreturn, 128, in);
   fgets(varreturn, 128, in);
   /* We can ignore the first 8 characters */
   varreturn = varreturn + 8;
   fclose(in);
   unlink("snmptemp");

   env = getenv("HPDATEF");
   strcpy(datetime, env);
   env = getenv("HPTIMEF");
   strcat(datetime, env);

   env = getenv("HPUSERCOUNT");
   sessions = atoi(env);
   env = getenv("HPJOBCOUNT");
   jobs = atoi(env);

   printf("%s\t%i\t%i\t%i\t%s\n",
            datetime, sessions, jobs, sessions + jobs, varreturn);

}

ATOM RSS1 RSS2