Snmp(CPU,memoire,disque) en C??

kobee12 Messages postés 153 Date d'inscription dimanche 26 janvier 2003 Statut Membre Dernière intervention 31 octobre 2006 - 20 déc. 2003 à 17:48
sfave Messages postés 3 Date d'inscription samedi 20 novembre 2004 Statut Membre Dernière intervention 29 avril 2008 - 29 avril 2008 à 08:50
Je dois realiser un prog en C qui permet de recuperer le taux de CPU utilise, la memoire disque disponible, espace disque disponible, et pouvoir envoyer toutes ces infos a une machine principale.
J'ai apppris que l'on pouvait utiliser le protocole SNMP. Seulement je ne le connais pas du tout. Je suppose qu'il existe des bibliotheques en C du style snmp.h mais je ne connais pas les fonctions qui me permettent de realiser les operations que je dois mettre en oeuvre.
Si quelqu'un s'y connait en SNMP et connait les fonctions necessaires a mon prog, qu'il me fasse signe.
Merci d'avance kobee
:big)

6 réponses

D1m3x Messages postés 402 Date d'inscription samedi 28 décembre 2002 Statut Membre Dernière intervention 21 juillet 2005 1
20 déc. 2003 à 19:58
Google connait certainement cette librairie :p suffit de lui demander :p :d

[DmX]
0
cs_aardman Messages postés 1905 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 17 septembre 2012 3
20 déc. 2003 à 21:20
Salut,
Je ne connais pas ce protocole, mais je sais qu'il y a un chapitre entier dans MSDN qui lui est consacré. Ca peut etre une piste de depart..
0
SMarmotte Messages postés 53 Date d'inscription vendredi 17 janvier 2003 Statut Membre Dernière intervention 12 novembre 2005
21 déc. 2003 à 14:05
tu veux quoi au juste ?
pour CPU, moi je peux fournir comment récupérer l'util CPU pour NT (pas Win9x)

mais le code est long ...
il s'agit d'un fichier externe utilisant des fonction non documentées de NTDLL.DLL ...

-> A inclure ans un projet
utilisation hyper simple : float GetCPUusage()
ca fonctionne tres bien sur mon W2000

--------------------

// cpu_agent.cpp (Windows NT/2000)
// Getting the CPU usage in percent on Windows NT/2000

#include <stdio.h>
#include <conio.h>
#include <windows.h>


#define SystemBasicInformation 0
#define SystemPerformanceInformation 2
#define SystemTimeInformation 3


#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))


typedef struct
{
DWORD dwUnknown1;
ULONG uKeMaximumIncrement;
ULONG uPageSize;
ULONG uMmNumberOfPhysicalPages;
ULONG uMmLowestPhysicalPage;
ULONG uMmHighestPhysicalPage;
ULONG uAllocationGranularity;
PVOID pLowestUserAddress;
PVOID pMmHighestUserAddress;
ULONG uKeActiveProcessors;
BYTE bKeNumberProcessors;
BYTE bUnknown2;
WORD wUnknown3;
} SYSTEM_BASIC_INFORMATION;


typedef struct
{
LARGE_INTEGER liIdleTime;
DWORD dwSpare[76];
} SYSTEM_PERFORMANCE_INFORMATION;


typedef struct
{
LARGE_INTEGER liKeBootTime;
LARGE_INTEGER liKeSystemTime;
LARGE_INTEGER liExpTimeZoneBias;
ULONG uCurrentTimeZoneId;
DWORD dwReserved;
} SYSTEM_TIME_INFORMATION;



// ntdll.NtQuerySystemInformation (NT specific!)
//
// The function copies the system information of the
// specified type into a buffer
//
// NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(
// IN UINT SystemInformationClass, // information type
// OUT PVOID SystemInformation, // pointer to buffer
// IN ULONG SystemInformationLength, // buffer size in bytes
// OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit variable that receives
// // the number of bytes written to the buffer
// );
typedef long (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);

PROCNTQSI NtQuerySystemInformation=NULL;


// The function ...
float GetCPUusage()
{
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
SYSTEM_TIME_INFORMATION SysTimeInfo;
SYSTEM_BASIC_INFORMATION SysBaseInfo;
double dbIdleTime;
double dbSystemTime;
long status;
static LARGE_INTEGER liOldIdleTime = {0,0};
static LARGE_INTEGER liOldSystemTime = {0,0};

if(!NtQuerySystemInformation)
NtQuerySystemInformation=(PROCNTQSI)GetProcAddress(GetModuleHandle("ntdll"), "NtQuerySystemInformation");

if(!NtQuerySystemInformation) return -1;

// Get number of processors in the system
status=NtQuerySystemInformation(SystemBasicInformation, &SysBaseInfo, sizeof(SysBaseInfo), NULL);
if(status!=NO_ERROR) return -1;

// Get new system time
status=NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
if(status!=NO_ERROR) return -1;

// Get new CPU's idle time
status=NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
if(status!=NO_ERROR) return -1;

// CurrentValue = NewValue - OldValue
dbIdleTime=Li2Double(SysPerfInfo.liIdleTime)-Li2Double(liOldIdleTime);
dbSystemTime=Li2Double(SysTimeInfo.liKeSystemTime)-Li2Double(liOldSystemTime);

// CurrentCpuIdle = IdleTime / SystemTime
dbIdleTime=dbIdleTime/dbSystemTime;

// CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
dbIdleTime=100.0-dbIdleTime*100.0/(double)SysBaseInfo.bKeNumberProcessors;

// Store new CPU's idle and system time
liOldIdleTime=SysPerfInfo.liIdleTime;
liOldSystemTime=SysTimeInfo.liKeSystemTime;

// Sometimes, value is -0.00
if(dbIdleTime<0) dbIdleTime=-dbIdleTime;
return (float)dbIdleTime;
}
0
kobee12 Messages postés 153 Date d'inscription dimanche 26 janvier 2003 Statut Membre Dernière intervention 31 octobre 2006 1
22 déc. 2003 à 20:49
ton pgrm a l'air pas mal mais quand je le compile il me fait deux erreurs sous visual c++ :

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/cpu_agent.exe : fatal error LNK1120: 1 unresolved externals

:big)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
SMarmotte Messages postés 53 Date d'inscription vendredi 17 janvier 2003 Statut Membre Dernière intervention 12 novembre 2005
22 déc. 2003 à 20:57
salut
en fait ce fichier est à joindre dans un projet ...
et dans le fichier principal tu fait :

#include <stdio.h>
#include <windows.h>

void main()
{
for(;;)
{
printf("Util CPU = %f", GetCPUusage());
Sleep(1000);
}
}

ou int WinMain(....) pour une prog graphique

ca marche impec

d'un autre coté tu aurais pu t'en douter :
le msg d'erreur disait : "unresolved external symbol _main"

_main non trouvé (or tout prog en C a un main ou WinMain)
0
sfave Messages postés 3 Date d'inscription samedi 20 novembre 2004 Statut Membre Dernière intervention 29 avril 2008
29 avril 2008 à 08:50
Bonjour

ça fonctionne très bien. Excellent.
Et si on veut la même chose, mais pour chaque processeur ?

Quelqu'un aurait une solution ?

Merci

Seb le Fou
0
Rejoignez-nous