3
** Copyright (C) 2000-2005 SIA Zabbix
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34
#include <sys/loadavg.h>
37
#include <sys/statvfs.h>
38
#include <sys/sysinfo.h>
40
#include <sys/types.h>
51
* ADDED to /solaric/diskio.c
53
typedef struct busy_data
59
typedef struct svc_time_data
66
typedef struct read_ios_data
72
typedef struct write_ios_data
78
typedef struct rblocks_data
84
typedef struct wblocks_data
87
u_longlong_t nwritten;
90
typedef struct disk_data
92
struct disk_data *next;
97
WRITE_IOS_DATA writes;
104
* ADDED to /solaric/net.c
106
typedef union value_overlay
115
typedef struct rbytes_data
118
VALUE_OVERLAY rbytes;
121
typedef struct obytes_data
124
VALUE_OVERLAY obytes;
127
typedef struct rpackets_data
130
VALUE_OVERLAY rpackets;
133
typedef struct opackets_data
136
VALUE_OVERLAY opackets;
139
typedef struct network_data
141
struct network_data *next;
149
static NETWORK_DATA *interfaces;
153
* ADDED to /solaric/diskio.c
155
static DISK_DATA *disks;
157
static DISK_DATA *get_disk_data_record(const char *device)
163
while ((p) && (strcmp(p->name, device) != 0))
166
if (p == (DISK_DATA *) NULL)
168
p = (DISK_DATA *) calloc(1, sizeof(DISK_DATA));
172
p->name = strdup(device);
195
* ADDED to /solaric/net.c
197
static NETWORK_DATA *get_net_data_record(const char *device)
203
while ((p) && (strcmp(p->name, device) != 0))
206
if (p == (NETWORK_DATA *) NULL)
208
p = (NETWORK_DATA *) calloc(1, sizeof(NETWORK_DATA));
212
p->name = strdup(device);
216
p->next = interfaces;
237
static int PROCCNT(const char *cmd, const char *procname,double *value, const char *msg, int mlen_max)
240
struct dirent *entries;
242
char filename[MAX_STRING_LEN];
245
// In the correct procfs.h, the structure name is psinfo_t
250
dir=opendir("/proc");
253
return SYSINFO_RET_FAIL;
256
while((entries=readdir(dir))!=NULL)
258
strscpy(filename,"/proc/");
259
strncat(filename,entries->d_name,MAX_STRING_LEN);
260
strncat(filename,"/psinfo",MAX_STRING_LEN);
262
if(stat(filename,&buf)==0)
264
fd = open (filename, O_RDONLY);
267
if (read (fd, &psinfo, sizeof(psinfo)) == -1)
270
return SYSINFO_RET_FAIL;
274
if(strcmp(procname,psinfo.pr_fname)==0)
288
*value=(double)proccount;
289
return SYSINFO_RET_OK;
294
* ADDED to /solaric/diskio.c
296
static int get_disk_kstat_record(const char *name,
299
kstat_io_t *returned_data)
301
int result = SYSINFO_RET_FAIL;
310
kt = kstat_lookup(kc, NULL, -1, (char *) name);
314
if ( (kt->ks_type == KSTAT_TYPE_IO)
315
&& (kstat_read(kc, kt, returned_data) != -1)
318
*crtime = kt->ks_crtime;
319
*snaptime = kt->ks_snaptime;
320
result = SYSINFO_RET_OK;
330
static int DISKREADOPS(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
332
int result = SYSINFO_RET_FAIL;
335
p = get_disk_data_record(device);
339
hrtime_t crtime, snaptime;
342
result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
344
if (result == SYSINFO_RET_OK)
346
int interval_seconds;
348
interval_seconds = (snaptime - p->reads.clock) / 1000000000;
350
if (interval_seconds > 0)
351
*value = (kio.reads - p->reads.reads) / interval_seconds;
356
p->reads.clock = snaptime;
358
p->reads.reads = kio.reads;
365
static int DISKREADBLOCKS(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
367
int result = SYSINFO_RET_FAIL;
370
p = get_disk_data_record(device);
374
hrtime_t crtime, snaptime;
377
result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
379
if (result == SYSINFO_RET_OK)
381
int interval_seconds;
383
interval_seconds = (snaptime - p->rblocks.clock) / 1000000000;
385
if (interval_seconds > 0)
386
*value = ((kio.nread - p->rblocks.nread) / 1024.0) / interval_seconds;
391
p->rblocks.clock = snaptime;
393
p->rblocks.nread = kio.nread;
400
static int DISKWRITEOPS(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
402
int result = SYSINFO_RET_FAIL;
405
p = get_disk_data_record(device);
409
hrtime_t crtime, snaptime;
412
result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
414
if (result == SYSINFO_RET_OK)
416
int interval_seconds;
418
interval_seconds = (snaptime - p->writes.clock) / 1000000000;
420
if (interval_seconds > 0)
421
*value = (kio.writes - p->writes.writes) / interval_seconds;
426
p->writes.clock = snaptime;
428
p->writes.writes = kio.writes;
435
static int DISKWRITEBLOCKS(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
437
int result = SYSINFO_RET_FAIL;
440
p = get_disk_data_record(device);
444
hrtime_t crtime, snaptime;
447
result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
449
if (result == SYSINFO_RET_OK)
451
int interval_seconds;
453
interval_seconds = (snaptime - p->wblocks.clock) / 1000000000;
455
if (interval_seconds > 0)
456
*value = ((kio.nwritten - p->wblocks.nwritten) / 1024.0) / interval_seconds;
461
p->wblocks.clock = snaptime;
463
p->wblocks.nwritten = kio.nwritten;
470
static int DISKBUSY(const char *cmd, const char *device, double *value, const char *msg, int mlen_max)
472
int result = SYSINFO_RET_FAIL;
475
p = get_disk_data_record(device);
479
hrtime_t crtime, snaptime;
482
result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
484
if (result == SYSINFO_RET_OK)
486
if (snaptime > p->busy.clock)
487
*value = ((kio.rtime - p->busy.rtime) * 100.0) / (snaptime - p->busy.clock);
492
p->busy.clock = snaptime;
494
p->busy.rtime = kio.rtime;
501
static int DISKSVC(const char *cmd, const char *device, double *value, const char *msg, int mlen_max)
503
int result = SYSINFO_RET_FAIL;
506
p = get_disk_data_record(device);
510
hrtime_t crtime, snaptime;
513
result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
515
if (result == SYSINFO_RET_OK)
519
ios = (kio.reads - p->svc.reads) + (kio.writes - p->svc.writes);
522
*value = ((kio.rtime - p->svc.rtime)/ios)/1000000.0;
527
p->svc.writes = kio.writes;
528
p->svc.reads = kio.reads;
529
p->svc.rtime = kio.rtime;
538
* ADDED to /solaric/cpu.c
540
static int get_cpu_data(zbx_uint64_t *idle,
541
zbx_uint64_t *system,
543
zbx_uint64_t *iowait)
557
kstat_t *k = kc->kc_chain;
561
if ( (strncmp(k->ks_name, "cpu_stat", 8) == 0)
562
&& (kstat_read(kc, k, NULL) != -1)
565
cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
567
*idle += cpu->cpu_sysinfo.cpu[CPU_IDLE];
568
*system += cpu->cpu_sysinfo.cpu[CPU_KERNEL];
569
*iowait += cpu->cpu_sysinfo.cpu[CPU_WAIT];
570
*user += cpu->cpu_sysinfo.cpu[CPU_USER];
584
static int CPUIDLE(const char *cmd, const char *param, double *value, const char *msg, int mlen_max)
586
static zbx_uint64_t idle[2];
587
static zbx_uint64_t system[2];
588
static zbx_uint64_t user[2];
589
static zbx_uint64_t iowait[2];
591
int result = SYSINFO_RET_FAIL;
593
if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
595
zbx_uint64_t interval_size;
597
interval_size = (idle[1] - idle[0])
598
+ (system[1] - system[0])
599
+ (user[1] - user[0])
600
+ (iowait[1] - iowait[0]);
602
if (interval_size > 0)
604
*value = ((idle[1] - idle[0]) * 100.0)/interval_size;
607
system[0] = system[1];
609
iowait[0] = iowait[1];
611
result = SYSINFO_RET_OK;
618
static int CPUUSER(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
620
static unsigned long long idle[2];
621
static unsigned long long system[2];
622
static unsigned long long user[2];
623
static unsigned long long iowait[2];
625
int result = SYSINFO_RET_FAIL;
627
if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
629
unsigned interval_size;
631
interval_size = (idle[1] - idle[0])
632
+ (system[1] - system[0])
633
+ (user[1] - user[0])
634
+ (iowait[1] - iowait[0]);
636
if (interval_size > 0)
638
*value = ((user[1] - user[0]) * 100.0)/interval_size;
641
system[0] = system[1];
643
iowait[0] = iowait[1];
645
result = SYSINFO_RET_OK;
652
static int CPUSYSTEM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
654
static unsigned long long idle[2];
655
static unsigned long long system[2];
656
static unsigned long long user[2];
657
static unsigned long long iowait[2];
659
int result = SYSINFO_RET_FAIL;
661
if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
663
unsigned interval_size;
665
interval_size = (idle[1] - idle[0])
666
+ (system[1] - system[0])
667
+ (user[1] - user[0])
668
+ (iowait[1] - iowait[0]);
670
if (interval_size > 0)
672
*value = ((system[1] - system[0]) * 100.0)/interval_size;
675
system[0] = system[1];
677
iowait[0] = iowait[1];
679
result = SYSINFO_RET_OK;
686
static int CPUIOWAIT(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
688
static unsigned long long idle[2];
689
static unsigned long long system[2];
690
static unsigned long long user[2];
691
static unsigned long long iowait[2];
693
int result = SYSINFO_RET_FAIL;
695
if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
697
unsigned interval_size;
699
interval_size = (idle[1] - idle[0])
700
+ (system[1] - system[0])
701
+ (user[1] - user[0])
702
+ (iowait[1] - iowait[0]);
704
if (interval_size > 0)
706
*value = ((iowait[1] - iowait[0]) * 100.0)/interval_size;
709
system[0] = system[1];
711
iowait[0] = iowait[1];
713
result = SYSINFO_RET_OK;
722
* ADDED to /solaric/net.c
724
static int get_named_field(const char *name,
726
kstat_named_t *returned_data,
729
int result = SYSINFO_RET_FAIL;
738
kp = kstat_lookup(kc, NULL, -1, (char *) name);
740
if ((kp) && (kstat_read(kc, kp, 0) != -1))
744
kn = (kstat_named_t*) kstat_data_lookup(kp, (char *) field);
746
*snaptime = kp->ks_snaptime;
748
*returned_data = *kn;
750
result = SYSINFO_RET_OK;
760
static int NETLOADIN(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
762
int result = SYSINFO_RET_FAIL;
765
p = get_net_data_record(parameter);
772
result = get_named_field(parameter, "rbytes64", &kn, &snaptime);
774
if (result == SYSINFO_RET_OK)
776
int interval_seconds;
778
interval_seconds = (snaptime - p->rb.clock) / 1000000000;
780
*value = (double) (kn.value.ui64 - p->rb.rbytes.u.ui64) / interval_seconds;
782
p->rb.rbytes.u.ui64 = kn.value.ui64;
784
p->rb.clock = snaptime;
789
result = get_named_field(parameter, "rbytes", &kn, &snaptime);
791
if (result == SYSINFO_RET_OK)
793
int interval_seconds;
795
interval_seconds = (snaptime - p->rb.clock) / 1000000000;
797
*value = (double) (kn.value.ui32 - p->rb.rbytes.u.ui32) / interval_seconds;
799
p->rb.rbytes.u.ui32 = kn.value.ui32;
801
p->rb.clock = snaptime;
809
static int NETPACKETSIN(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
811
int result = SYSINFO_RET_FAIL;
814
p = get_net_data_record(parameter);
821
result = get_named_field(parameter, "ipackets64", &kn, &snaptime);
823
if (result == SYSINFO_RET_OK)
825
int interval_seconds;
827
interval_seconds = (snaptime - p->rp.clock) / 1000000000;
829
*value = (double) (kn.value.ui64 - p->rp.rpackets.u.ui64) / interval_seconds;
831
p->rp.rpackets.u.ui64 = kn.value.ui64;
833
p->rp.clock = snaptime;
838
result = get_named_field(parameter, "ipacket", &kn, &snaptime);
840
if (result == SYSINFO_RET_OK)
842
int interval_seconds;
844
interval_seconds = (snaptime - p->rp.clock) / 1000000000;
846
*value = (double) (kn.value.ui32 - p->rp.rpackets.u.ui32) / interval_seconds;
848
p->rp.rpackets.u.ui32 = kn.value.ui32;
850
p->rp.clock = snaptime;
858
static int NETERRSIN(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
864
result = get_named_field(parameter, "ierrors", &kn, &snaptime);
866
if (result == SYSINFO_RET_OK)
867
*value = (double) kn.value.ui32;
872
static int NETLOADOUT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
874
int result = SYSINFO_RET_FAIL;
877
p = get_net_data_record(parameter);
884
result = get_named_field(parameter, "obytes64", &kn, &snaptime);
886
if (result == SYSINFO_RET_OK)
888
int interval_seconds;
890
interval_seconds = (snaptime - p->ob.clock) / 1000000000;
892
*value = (double) (kn.value.ui64 - p->ob.obytes.u.ui64) / interval_seconds;
894
p->ob.obytes.u.ui64 = kn.value.ui64;
896
p->ob.clock = snaptime;
901
result = get_named_field(parameter, "obytes", &kn, &snaptime);
903
if (result == SYSINFO_RET_OK)
905
int interval_seconds;
907
interval_seconds = (snaptime - p->ob.clock) / 1000000000;
909
*value = (double) (kn.value.ui32 - p->ob.obytes.u.ui32) / interval_seconds;
911
p->ob.obytes.u.ui32 = kn.value.ui32;
913
p->ob.clock = snaptime;
921
static int NETPACKETSOUT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
923
int result = SYSINFO_RET_FAIL;
926
p = get_net_data_record(parameter);
933
result = get_named_field(parameter, "opackets64", &kn, &snaptime);
935
if (result == SYSINFO_RET_OK)
937
int interval_seconds;
939
interval_seconds = (snaptime - p->op.clock) / 1000000000;
941
*value = (double) (kn.value.ui64 - p->op.opackets.u.ui64) / interval_seconds;
943
p->op.opackets.u.ui64 = kn.value.ui64;
945
p->op.clock = snaptime;
950
result = get_named_field(parameter, "opacket", &kn, &snaptime);
952
if (result == SYSINFO_RET_OK)
954
int interval_seconds;
956
interval_seconds = (snaptime - p->op.clock) / 1000000000;
958
*value = (double) (kn.value.ui32 - p->op.opackets.u.ui32) / interval_seconds;
960
p->op.opackets.u.ui32 = kn.value.ui32;
962
p->op.clock = snaptime;
970
static int NETERRSOUT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
976
result = get_named_field(parameter, "oerrors", &kn, &snaptime);
978
if (result == SYSINFO_RET_OK)
979
*value = (double) kn.value.ui32;
984
static int NETCOLLOUT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
990
result = get_named_field(parameter, "collisions", &kn, &snaptime);
992
if (result == SYSINFO_RET_OK)
993
*value = (double) kn.value.ui32;
1002
int INODEFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
1006
if ( statvfs( (char *)mountPoint, &s) != 0 )
1008
return SYSINFO_RET_FAIL;
1012
return SYSINFO_RET_OK;
1019
int INODETOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
1023
if ( statvfs( (char *)mountPoint, &s) != 0 )
1025
return SYSINFO_RET_FAIL;
1029
return SYSINFO_RET_OK;
1036
int DISKFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
1040
if ( statvfs( (char *)mountPoint, &s) != 0 )
1042
return SYSINFO_RET_FAIL;
1045
// return s.f_bavail * (s.f_bsize / 1024.0);
1046
*value=s.f_bavail * (s.f_frsize / 1024.0);
1047
return SYSINFO_RET_OK;
1054
int DISKUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
1058
if ( statvfs( (char *)mountPoint, &s) != 0 )
1060
return SYSINFO_RET_FAIL;
1063
// return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);
1064
*value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
1065
return SYSINFO_RET_OK;
1072
int DISKTOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
1076
if ( statvfs( (char *)mountPoint, &s) != 0 )
1078
return SYSINFO_RET_FAIL;
1081
// return s.f_blocks * (s.f_bsize / 1024.0);
1082
*value= s.f_blocks * (s.f_frsize / 1024.0);
1083
return SYSINFO_RET_OK;
1090
static int TOTALMEM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1092
*value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
1093
return SYSINFO_RET_OK;
1100
static int FREEMEM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1102
*value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
1103
return SYSINFO_RET_OK;
1110
static int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1112
int result = SYSINFO_RET_FAIL;
1121
kt = kstat_lookup(kc, "unix", 0, "var");
1125
if ( (kt->ks_type == KSTAT_TYPE_RAW)
1126
&& (kstat_read(kc, kt, NULL) != -1)
1129
struct var *v = (struct var *) kt->ks_data;
1132
result = SYSINFO_RET_OK;
1146
static int UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1148
int result = SYSINFO_RET_FAIL;
1157
kp = kstat_lookup(kc, "unix", 0, "system_misc");
1159
if ((kp) && (kstat_read(kc, kp, 0) != -1))
1164
kn = (kstat_named_t*) kstat_data_lookup(kp, "boot_time");
1168
*value=difftime(now, (time_t) kn->value.ul);
1170
result = SYSINFO_RET_OK;
1183
static int PROCLOAD(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1187
if(getloadavg(load, 3))
1190
return SYSINFO_RET_OK;
1194
return SYSINFO_RET_FAIL;
1202
static int PROCLOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1206
if(getloadavg(load, 3))
1209
return SYSINFO_RET_OK;
1213
return SYSINFO_RET_FAIL;
1221
static int PROCLOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1225
if(getloadavg(load, 3))
1228
return SYSINFO_RET_OK;
1232
return SYSINFO_RET_FAIL;
1240
static int get_swap_data(zbx_uint64_t *resv,
1241
zbx_uint64_t *avail,
1244
int result = SYSINFO_RET_FAIL;
1253
ksp = kstat_lookup(kc, "unix", 0, "vminfo");
1255
if ((ksp) && (kstat_read(kc, ksp, NULL) != -1))
1259
zbx_uint64_t oresv, ofree, oavail;
1261
vm = (vminfo_t *) ksp->ks_data;
1263
oresv = vm->swap_resv;
1264
ofree = vm->swap_free;
1265
oavail = vm->swap_avail;
1267
for (i = 0; i < 12; i++)
1271
if (kstat_read(kc, ksp, NULL) != -1)
1273
vm = (vminfo_t *) ksp->ks_data;
1275
if ((oresv != vm->swap_resv) || (ofree != vm->swap_free) || (oavail != vm->swap_avail))
1277
*resv = vm->swap_resv - oresv;
1278
*free = vm->swap_free - ofree;
1279
*avail = vm->swap_avail - oavail;
1281
result = SYSINFO_RET_OK;
1295
static int SWAPFREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1298
zbx_uint64_t resv, avail, free;
1300
result = get_swap_data(&resv, &avail, &free);
1302
if (result == SYSINFO_RET_OK)
1304
*value = free * sysconf(_SC_PAGESIZE);
1310
int SWAPTOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1313
zbx_uint64_t resv, avail, free;
1315
result = get_swap_data(&resv, &avail, &free);
1317
if (result == SYSINFO_RET_OK)
1319
zbx_uint64_t swap_total_bytes;
1321
swap_total_bytes = (resv + avail) * sysconf(_SC_PAGESIZE);
1322
*value = (double) swap_total_bytes;
1332
static int SWAPIN(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1343
kstat_t *k = kc->kc_chain;
1347
if ( (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1348
&& (kstat_read(kc, k, NULL) != -1)
1351
cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1353
*value += cpu->cpu_vminfo.swapin;
1364
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1371
static int SWAPOUT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1382
kstat_t *k = kc->kc_chain;
1386
if ( (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1387
&& (kstat_read(kc, k, NULL) != -1)
1390
cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1392
*value += cpu->cpu_vminfo.swapout;
1403
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1410
static int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1412
int result = SYSINFO_RET_FAIL;
1421
kp = kstat_lookup(kc, "unix", 0, "system_misc");
1423
if ((kp) && (kstat_read(kc, kp, 0) != -1))
1427
kn = (kstat_named_t*) kstat_data_lookup(kp, "nproc");
1429
*value = (double) kn->value.ul;
1431
result = SYSINFO_RET_OK;
1444
static int PROCRUNNING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1447
struct dirent *entries;
1449
char filename[MAX_STRING_LEN];
1452
// In the correct procfs.h, the structure name is psinfo_t
1458
dir=opendir("/proc");
1461
return SYSINFO_RET_FAIL;
1464
while((entries=readdir(dir))!=NULL)
1466
strscpy(filename,"/proc/");
1467
strncat(filename,entries->d_name,MAX_STRING_LEN);
1468
strncat(filename,"/psinfo",MAX_STRING_LEN);
1470
if(stat(filename,&buf)==0)
1472
fd = open (filename, O_RDONLY);
1475
if(read (fd, &psinfo, sizeof(psinfo)) == -1)
1478
return SYSINFO_RET_FAIL;
1482
if(psinfo.pr_lwp.pr_state == SRUN)
1496
*value=(double)proccount;
1497
return SYSINFO_RET_OK;
1504
static int CSWITCHES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1515
kstat_t *k = kc->kc_chain;
1519
if ( (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1520
&& (kstat_read(kc, k, NULL) != -1)
1523
cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1525
*value += cpu->cpu_sysinfo.pswitch;
1536
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1541
* ADDED to /solaris/net.c
1543
static int TCP_LISTEN(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1545
char command[MAX_STRING_LEN];
1547
memset(command, '\0', sizeof command);
1549
snprintf(command, sizeof command-1, "netstat -an | grep '*.%s' | wc -l", parameter);
1551
return EXECUTE(NULL, command, value, msg, mlen_max);
1558
static int INTERRUPTS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
1569
kstat_t *k = kc->kc_chain;
1573
if ( (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1574
&& (kstat_read(kc, k, NULL) != -1)
1577
cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1579
*value += cpu->cpu_sysinfo.intr;
1590
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1598
static int check_ldap(char *hostname, short port,int *value, const char *msg, int mlen_max)
1606
int scope = LDAP_SCOPE_BASE;
1607
char *filter="(objectClass=*)";
1611
attrs[0] = "namingContexts";
1618
ldap = ldap_init(hostname, port);
1622
return SYSINFO_RET_OK;
1625
rc = ldap_search_s(ldap, base, scope, filter, attrs, attrsonly, &res);
1629
return SYSINFO_RET_OK;
1632
msg = ldap_first_entry(ldap, res);
1636
return SYSINFO_RET_OK;
1639
attr = ldap_first_attribute (ldap, msg, &ber);
1640
valRes = ldap_get_values( ldap, msg, attr );
1642
ldap_value_free(valRes);
1651
return SYSINFO_RET_OK;
1656
ZBX_METRIC agent_commands[]=
1657
/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
1660
{"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
1663
{"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
1665
{"proc_cnt[*]" ,PROCCNT, 0, "inetd"},
1667
{"memory[total]" ,TOTALMEM, 0, 0},
1668
{"memory[free]" ,FREEMEM, 0, 0},
1671
{"memory[shared]" ,SHAREDMEM, 0, 0},
1672
{"memory[buffers]" ,BUFFERSMEM, 0, 0},
1673
{"memory[cached]" ,CACHEDMEM, 0, 0},
1674
{"memory[free]" ,FREEMEM, 0, 0},
1677
{"version[zabbix_agent]",0, VERSION, 0},
1679
{"diskfree[*]" ,DISKFREE, 0, "/"},
1680
{"disktotal[*]" ,DISKTOTAL, 0, "/"},
1681
{"diskused[*]" ,DISKUSED, 0, "/"},
1683
{"diskfree_perc[*]" ,DISKFREE_PERC, 0, "/"},
1684
{"diskused_perc[*]" ,DISKUSED_PERC, 0, "/"},
1686
{"inodefree[*]" ,INODEFREE, 0, "/"},
1687
{"inodefree_perc[*]" ,INODEFREE_PERC, 0, "/"},
1688
{"inodetotal[*]" ,INODETOTAL, 0, "/"},
1690
{"cksum[*]" ,CKSUM, 0, "/etc/services"},
1692
{"md5sum[*]" ,0, MD5SUM, "/etc/services"},
1694
{"filesize[*]" ,FILESIZE, 0, "/etc/passwd"},
1695
{"file[*]" ,ISFILE, 0, "/etc/passwd"},
1697
{"cpu[idle]" ,CPUIDLE, 0, 0},
1698
{"cpu[user]" ,CPUUSER, 0, 0},
1699
{"cpu[system]" ,CPUSYSTEM, 0, 0},
1700
{"cpu[iowait]" ,CPUIOWAIT, 0, 0},
1703
{"cpu[nice]" ,CPUNICE, 0, 0},
1704
{"cpu[interrupt]" ,CPUINTERRUPT, 0, 0},
1707
{"netloadin[*]" ,NETLOADIN, 0, "lo"},
1708
{"netloadout[*]" ,NETLOADOUT, 0, "lo"},
1709
{"netpacketsin[*]" ,NETPACKETSIN, 0, "lo"},
1710
{"netpacketsout[*]" ,NETPACKETSOUT, 0, "lo"},
1711
{"neterrsin[*]" ,NETERRSIN, 0, "lo"},
1712
{"neterrsout[*]" ,NETERRSOUT, 0, "lo"},
1713
{"netcollout[*]" ,NETCOLLOUT, 0, "lo"},
1716
{"disk_read_ops[*]" ,DISKREADOPS, 0, "hda"},
1717
{"disk_read_kbs[*]" ,DISKREADBLOCKS, 0, "hda"},
1718
{"disk_write_ops[*]" ,DISKWRITEOPS, 0, "hda"},
1719
{"disk_write_kbs[*]" ,DISKWRITEBLOCKS, 0, "hda"},
1720
{"disk_busy[*]" ,DISKBUSY, 0, "hda"},
1721
{"disk_svc[*]" ,DISKSVC, 0, "hda"},
1724
{"sensor[temp1]" ,SENSOR, 0, "temp1"},
1725
{"sensor[temp2]" ,SENSOR, 0, "temp2"},
1726
{"sensor[temp3]" ,SENSOR, 0, "temp3"},
1729
{"swap[free]" ,SWAPFREE, 0, 0},
1730
{"swap[total]" ,SWAPTOTAL, 0, 0},
1731
{"swap[in]" ,SWAPIN, 0, 0},
1732
{"swap[out]" ,SWAPOUT, 0, 0},
1734
{"system[interrupts]" ,INTERRUPTS, 0, 0},
1735
{"system[switches]" ,CSWITCHES, 0, 0},
1736
{"system[procload]" ,PROCLOAD, 0, 0},
1737
{"system[procload5]" ,PROCLOAD5, 0, 0},
1738
{"system[procload15]" ,PROCLOAD15, 0, 0},
1739
{"system[proccount]" ,PROCCOUNT, 0, 0},
1740
{"system[procrunning]" ,PROCRUNNING, 0, 0},
1742
{"system[hostname]" ,0, EXECUTE_STR, "hostname"},
1743
{"system[uname]" ,0, EXECUTE_STR, "uname -a"},
1744
{"system[uptime]" ,UPTIME, 0, 0},
1745
{"system[users]" ,EXECUTE, 0,"who|wc -l"},
1747
{"ping" ,PING, 0, 0},
1748
{"tcp_count" ,EXECUTE, 0, "netstat -s -P tcp | grep tcpCurrEstab | cut -f2 | tr -s ' ' | cut -d' ' -f3"},
1750
{"tcp_listen[*]" ,TCP_LISTEN, 0, "22"},
1752
{"check_port[*]" ,CHECK_PORT, 0, "80"},
1754
{"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
1755
{"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},