Пример #1
0
DWORD
VmDirMetricsInitialize(
    VOID
    )
{
    DWORD   dwError = 0;

    dwError = VmMetricsInit(&pmContext);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirLdapMetricsInit();
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirReplMetricsInit();
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = _VmDirRpcMetricsInit();
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    return dwError;

error:
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "VmDirMetricsInitialize failed (%d)", dwError);

    goto cleanup;
}
Пример #2
0
static
DWORD
VmMetricsGaugeWithInvalidLabelTest()
{
    DWORD dwError = 0;
    PVM_METRICS_CONTEXT pContext = NULL;
    PVM_METRICS_GAUGE pGauge = NULL;
    VM_METRICS_LABEL pLabel[2] = {
                                    {"label1",NULL},
                                    {"label2","value2"}
                                 };

    dwError = VmMetricsInit(&pContext);
    if (dwError)
    {
        printf("FAIL: Error in MetricsInit for test: GaugeWithInvalidLabel, Error Code = %d\n", dwError);
        goto error;
    }

    dwError = VmMetricsGaugeNew(pContext,
                        "gauge_with_invalid_label_value",
                        pLabel,
                        2,
                        "Test for gauge with invalid label",
                        &pGauge);
    switch (dwError)
    {
        case VM_METRICS_ERROR_INVALID_PARAMETER:
            printf("PASS: Expected Result for test: GaugeWithInvalidLabel\n");
            dwError = 0;
            break;

        case 0:
            printf("FAIL: Unexpected Result in GaugeNew for test: GaugeWithInvalidLabel, Error Code = %d\n", dwError);
            goto error;
            break;

        default:
            printf("FAIL: Unexpected Error in GaugeNew for test: GaugeWithInvalidLabel, Error Code = %d\n", dwError);
            goto error;
            break;
    }

cleanup:
    VmMetricsDestroy(pContext);
    return dwError;

error:
    dwError = 1;
    goto cleanup;
}
Пример #3
0
static
DWORD
VmMetricsGaugeWithoutLabelTest()
{
    DWORD dwError = 0;
    PVM_METRICS_CONTEXT pContext = NULL;
    PVM_METRICS_GAUGE pGauge = NULL;
    PSTR pszData = NULL;
    PSTR pszExpected = NULL;
    DWORD dataLen = 0;

    dwError = VmMetricsInit(&pContext);
    if (dwError)
    {
        printf("FAIL: Error in MetricsInit for test: GaugeWithoutLabel, Error Code = %d\n", dwError);
        goto error;
    }

    dwError = VmMetricsGaugeNew(pContext,
                        "gauge_without_label_value",
                        NULL,
                        0,
                        "Test for gauge without label",
                        &pGauge);
    if (dwError)
    {
        printf("FAIL: Error in GaugeNew for test: GaugeWithoutLabel, Error Code = %d\n", dwError);
        goto error;
    }

    VmMetricsGaugeSetToCurrentTime(pGauge);

    VmMetricsGaugeSet(pGauge, 10);

    VmMetricsGaugeIncrement(pGauge);

    VmMetricsGaugeSubtract(pGauge, 9);

    VmMetricsGaugeAdd(pGauge, 34);

    VmMetricsGaugeSubtract(pGauge, 9);

    dwError = VmMetricsGetPrometheusData(pContext, &pszData, &dataLen);
    if (dwError)
    {
        printf("FAIL: Error in GetPrometheusData for test: GaugeWithoutLabel, Error Code = %d\n", dwError);
        goto error;
    }

    pszExpected = "# HELP gauge_without_label_value Test for gauge without label\n" \
                    "# TYPE gauge_without_label_value gauge\n" \
                    "gauge_without_label_value 27\n";

    if (strcmp(pszData, pszExpected) == 0)
    {
        printf("PASS: Expected Data received for test: GaugeWithoutLabel\n");
    }
    else
    {
        printf("FAIL: Unexpected Data received for test: GaugeWithoutLabel\n");
        goto error;
    }

cleanup:
    VM_METRICS_SAFE_FREE_MEMORY(pszData);
    VmMetricsDestroy(pContext);

    return dwError;

error:
    dwError = 1;
    goto cleanup;
}
Пример #4
0
static
DWORD
VmMetricsGaugeWithLabelTest()
{
    DWORD dwError = 0;
    PVM_METRICS_CONTEXT pContext = NULL;
    PVM_METRICS_GAUGE pGauge = NULL;
    PSTR pszData = NULL;
    PSTR pszExpected = NULL;
    DWORD dataLen = 0;

    VM_METRICS_LABEL pLabel[2] = {
                                    {"label1","value1"},
                                    {"label2","value2"}
                                 };

    dwError = VmMetricsInit(&pContext);
    if (dwError)
    {
        printf("FAIL: Error in MetricsInit for test: GaugeWithLabel, Error Code = %d\n", dwError);
        goto error;
    }

    dwError = VmMetricsGaugeNew(pContext,
                        "gauge_with_label_value",
                        pLabel,
                        2,
                        "Test for gauge with label",
                        &pGauge);
    if (dwError)
    {
        printf("FAIL: Error in GaugeNew for test: GaugeWithLabel, Error Code = %d\n", dwError);
        goto error;
    }

    VmMetricsGaugeSubtract(pGauge, 9);

    VmMetricsGaugeIncrement(pGauge);

    VmMetricsGaugeSet(pGauge, -4);

    VmMetricsGaugeAdd(pGauge, 40);

    VmMetricsGaugeDecrement(pGauge);

    dwError = VmMetricsGetPrometheusData(pContext, &pszData, &dataLen);
    if (dwError)
    {
        printf("FAIL: Error in GetPrometheusData for test: GaugeWithLabel, Error Code = %d\n", dwError);
        goto error;
    }

    pszExpected = "# HELP gauge_with_label_value Test for gauge with label\n" \
                    "# TYPE gauge_with_label_value gauge\n" \
                    "gauge_with_label_value{label1=\"value1\",label2=\"value2\"} 35\n";

    if (strcmp(pszData, pszExpected) == 0)
    {
        printf("PASS: Expected Data received for test: GaugeWithLabel\n");
    }
    else
    {
        printf("FAIL: Unexpected Data received for test: GaugeWithLabel\n");
        goto error;
    }

cleanup:
    VM_METRICS_SAFE_FREE_MEMORY(pszData);
    VmMetricsDestroy(pContext);
    return dwError;

error:
    dwError = 1;
    goto cleanup;
}