Skip to content

Commit

Permalink
Merge pull request hyperic#1 from boundary/win_metrics
Browse files Browse the repository at this point in the history
Win metrics
  • Loading branch information
busterb committed Apr 15, 2014
2 parents c2c6174 + 2362fbc commit 3cd70c9
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 119 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case $host_os in
*mingw*)
SRC_OS="win32"
AC_DEFINE(SIGAR_TEST_OS_WIN32, [1], [for the tests])
SIGAR_LIBS="-lws2_32 -liphlpapi -lnetapi32 -lversion"
SIGAR_LIBS="-lws2_32 -liphlpapi -lnetapi32 -lversion -lole32 -loleaut32"
;;
*)
ac_system="unknown"
Expand Down
10 changes: 6 additions & 4 deletions examples/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main(int argc, char **argv) {
int status, i;
sigar_t *sigar;
sigar_cpu_list_t cpulist;
sigar_loadavg_t loadavg;

sigar_open(&sigar);

Expand All @@ -46,15 +47,16 @@ int main(int argc, char **argv) {
}

sigar_cpu_list_destroy(sigar, &cpulist);

status = sigar_loadavg_get(sigar, &loadavg);

sigar_processor_queue_t proc_queue;
status = sigar_processor_queue_get(sigar, &proc_queue);
if (status != SIGAR_OK) {
printf("processor_queue error: %d (%s)\n",
printf("sigar_loadavg_get: %d (%s)\n",
status, sigar_strerror(sigar, status));
exit(1);
}
printf("Processor Queue Length: %u\n", proc_queue.processor_queue);

printf("Processor Queue Length: %u\n", loadavg.processor_queue);

sigar_close(sigar);

Expand Down
8 changes: 1 addition & 7 deletions include/sigar.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,12 @@ SIGAR_DECLARE(int) sigar_uptime_get(sigar_t *sigar,

typedef struct {
double loadavg[3];
sigar_uint32_t processor_queue;
} sigar_loadavg_t;

SIGAR_DECLARE(int) sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg);

typedef struct {
sigar_uint32_t processor_queue;
} sigar_processor_queue_t;

SIGAR_DECLARE(int) sigar_processor_queue_get(sigar_t *sigar,
sigar_processor_queue_t *queue_info);

typedef struct {
unsigned long number;
unsigned long size;
Expand Down
44 changes: 44 additions & 0 deletions include/sigar_rma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#ifndef SIGAR_RMA_H
#define SIGAR_RMA_H

#include <stdarg.h>
#include <stdbool.h>

#define SIGAR_RMA_RATE_1_MIN 1 * 60
#define SIGAR_RMA_RATE_5_MIN 5 * 60
#define SIGAR_RMA_RATE_15_MIN 15 * 60

typedef struct {

/* Elements configured by the caller. */

int sample_rate_secs; /* Period of sample secs. */
int element_count; /* Number of elements in the ring
* buffer. */

/* Internal items for tracking. */

float *values; /* Ring buffer sample set. */
bool have_wrapped; /* Have we wrapped the buffer yet. */
int current_pos; /* Current index location. */
} sigar_rma_stat_handle_t;

sigar_rma_stat_handle_t *sigar_rma_init(sigar_t *sigar, int sample_rate_secs, int max_average_time);
void sigar_rma_add_sample(sigar_t *sigar, sigar_rma_stat_handle_t * rma, float sample);
float sigar_rma_get_average(sigar_t *sigar, sigar_rma_stat_handle_t * rma, int rate);

#endif /* SIGAR_RMA_H */
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libsigar_la_SOURCES = \
sigar_format.c \
sigar_getline.c \
sigar_ptql.c \
sigar_rma.c \
sigar_signal.c \
sigar_util.c \
sigar_version_autoconf.c
Expand Down
6 changes: 0 additions & 6 deletions src/os/aix/aix_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,6 @@ int sigar_who_list_get(sigar_t *sigar,
return SIGAR_OK;
}

int sigar_processor_queue_get(sigar_t *sigar,
sigar_processor_queue_t *queue_info)
{
return SIGAR_ENOTIMPL;
}

int sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg)
{
Expand Down
6 changes: 0 additions & 6 deletions src/os/darwin/darwin_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,12 +936,6 @@ int sigar_uptime_get(sigar_t *sigar,
return SIGAR_OK;
}

int sigar_processor_queue_get(sigar_t *sigar,
sigar_processor_queue_t *queue_info)
{
return SIGAR_ENOTIMPL;
}

int sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg)
{
Expand Down
6 changes: 0 additions & 6 deletions src/os/hpux/hpux_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ int sigar_uptime_get(sigar_t *sigar,
return SIGAR_OK;
}

int sigar_processor_queue_get(sigar_t *sigar,
sigar_processor_queue_t *queue_info)
{
return SIGAR_ENOTIMPL;
}

int sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg)
{
Expand Down
6 changes: 0 additions & 6 deletions src/os/linux/linux_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,6 @@ int sigar_uptime_get(sigar_t *sigar,
return SIGAR_OK;
}

int sigar_processor_queue_get(sigar_t *sigar,
sigar_processor_queue_t *queue_info)
{
return SIGAR_ENOTIMPL;
}

int sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg)
{
Expand Down
6 changes: 0 additions & 6 deletions src/os/solaris/solaris_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,6 @@ int sigar_uptime_get(sigar_t *sigar,
return SIGAR_OK;
}

int sigar_processor_queue_get(sigar_t *sigar,
sigar_processor_queue_t *queue_info)
{
return SIGAR_ENOTIMPL;
}

static int loadavg_keys[] = {
KSTAT_SYSTEM_LOADAVG_1,
KSTAT_SYSTEM_LOADAVG_2,
Expand Down
11 changes: 11 additions & 0 deletions src/os/win32/sigar_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
#include <stdio.h>
#include <errno.h>
#include <tlhelp32.h>
#include <wbemcli.h>

#include "sigar_rma.h"
#include "sigar_util.h"

#ifdef MSVC
Expand Down Expand Up @@ -572,6 +574,13 @@ typedef struct {
sigar_dll_func_t end;
} sigar_mpr_t;


typedef struct wmi_handle {
int initialized;
IWbemLocator *locator;
IWbemServices *services;
} sigar_wmi_handle_t;

struct sigar_t {
SIGAR_T_BASE;
char *machine;
Expand All @@ -580,6 +589,7 @@ struct sigar_t {
HKEY handle;
char *perfbuf;
DWORD perfbuf_size;
sigar_wmi_handle_t *wmi_handle;
sigar_wtsapi_t wtsapi;
sigar_iphlpapi_t iphlpapi;
sigar_advapi_t advapi;
Expand All @@ -589,6 +599,7 @@ struct sigar_t {
sigar_kernel_t kernel;
sigar_mpr_t mpr;
sigar_win32_pinfo_t pinfo;
sigar_rma_stat_handle_t *rma_process_queue;
sigar_cache_t *netif_adapters;
sigar_cache_t *netif_mib_rows;
sigar_cache_t *netif_addr_rows;
Expand Down
34 changes: 33 additions & 1 deletion src/os/win32/win32_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "sigar_private.h"
#include "sigar_pdh.h"
#include "sigar_os.h"
#include "sigar_rma.h"
#include "sigar_util.h"
#include "sigar_format.h"
#include <shellapi.h>
Expand Down Expand Up @@ -557,6 +558,7 @@ int sigar_os_open(sigar_t **sigar_ptr)
HINSTANCE h;
OSVERSIONINFO version;
int i;
int wmi_status;
sigar_t *sigar;

*sigar_ptr = sigar = malloc(sizeof(*sigar));
Expand Down Expand Up @@ -620,6 +622,16 @@ int sigar_os_open(sigar_t **sigar_ptr)
/* increase process visibility */
sigar_enable_privilege(SE_DEBUG_NAME);

/* Open our WMI handle. */

sigar->wmi_handle = (sigar_wmi_handle_t *)wmi_handle_open(&wmi_status);

if(wmi_status != 0)
{
/* TODO What shall we do if WMI open fails? Retry every call? */
sigar_log_printf(sigar, SIGAR_LOG_WARN, "Unable to create WMI handle");
}

return result;
}

Expand Down Expand Up @@ -1091,7 +1103,27 @@ SIGAR_DECLARE(int) sigar_uptime_get(sigar_t *sigar,
SIGAR_DECLARE(int) sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg)
{
return SIGAR_ENOTIMPL;
sigar_uint32_t p_queue = 0;
int status;

unsigned long num_elems;
status = wmi_query_sum_u32(sigar,
L"SELECT ProcessorQueueLength FROM Win32_PerfFormattedData_PerfOS_System",
L"ProcessorQueueLength", &p_queue, &num_elems);

if (status == SIGAR_OK)
{
if(sigar->rma_process_queue == NULL)
sigar->rma_process_queue = sigar_rma_init(sigar, 1, SIGAR_RMA_RATE_15_MIN);
sigar_rma_add_sample(sigar, sigar->rma_process_queue, p_queue);
loadavg->processor_queue = p_queue;
loadavg->loadavg[0] = sigar_rma_get_average(sigar, sigar->rma_process_queue, SIGAR_RMA_RATE_1_MIN);
loadavg->loadavg[1] = sigar_rma_get_average(sigar, sigar->rma_process_queue, SIGAR_RMA_RATE_5_MIN);
loadavg->loadavg[2] = sigar_rma_get_average(sigar, sigar->rma_process_queue, SIGAR_RMA_RATE_15_MIN);
return SIGAR_OK;
}

return status;
}

#define get_process_object(sigar, err) \
Expand Down
Loading

0 comments on commit 3cd70c9

Please sign in to comment.