How to run the mock snmp device

The SNMP mock

The SNMP mock is an UDP server mocking a device using SNMP with a mock MIB file (./dev/mibs/TNO-PDU-MIB.txt). It provides simulated energy values for the following metrics: tnoPduEnergyValue and tnoPduPowerValue. This file details how to set up the mock device, and how to subsequently run a demo with it including both the PhysicalMeasurement and MeasurementDevice custom resources. The development setup deploys two SNMP mock devices.

Simulated values

Values are not purely random: each OID has a value, which drifts by a random amount within a set variance and stays between a lower and an upper bound. This keeps the values stable, enabling developers to debug against.

The simulation is configured with environment variables on the mock container (see dev/k8s/snmp-mock-deployment.yaml):

Variable Default Description
MOCK_SNMP_ADDRESS :1161 Address the UDP listener binds to.
MOCK_SNMP_VALUE_MIN 200 Lower bound of the simulated value.
MOCK_SNMP_VALUE_MAX 800 Upper bound of the simulated value.
MOCK_SNMP_VALUE_START 500 Value returned on the first request for an OID.
MOCK_SNMP_VALUE_VARIANCE 10 Maximum change per request, in either direction.

Use a different MOCK_SNMP_VALUE_START per mock deployment to tell multiple simulated devices apart.

Requirements

Ensure you have followed the installation guidance or the instructions in How to set up the local development environment to set up a production-like or local development environment. After this:

  • The cluster is running.
  • The controller is running (locally via make run or in-cluster).

Manual installation

The mock is part of the local development environment. After deploying Chantico (which is deployed by make cluster-configure), deploy the mocks with:

make docker-pull-mocks
make cluster-mocks

This deploys the mock deployments and services for the SNMP mock (including the second SNMP device) and the VM Attribution mock (see how to run the VM Attribution mock).

Running the demo with the mock SNMP device

Querying the mock directly

In the kind development cluster, the chantico-snmp-mock service is exposed on NodePort 31161. Query it with:

snmpget -v2c -c public -M +./dev -m +TNO-PDU-MIB localhost:31161 tnoPduEnergyValue

Full demo

The demo connects the mock to Prometheus in three steps. The numbers in the diagram match the steps below. For what happens inside the controller, see the system architecture.

UserChantico controllerSNMP exporterPrometheusSNMP mockUserChantico controllerSNMP exporterPrometheusSNMP mockUserChantico controllerSNMP exporterPrometheusSNMP mock1. Upload TNO-PDU-MIB (used to generate)2. Apply MeasurementDeviceSNMP module + auth3. Apply PhysicalMeasurementScrapeConfigScrape /snmpSNMP GET

make cluster-mock-resources applies the samples of steps 2 and 3 and the DataCenterResource sample from the next section in one go.

  1. Upload the MIB file ./dev/mibs/TNO-PDU-MIB.txt to the cluster:
    make cluster-mibs
  2. Create a MeasurementDevice for the mock MIB:
    kubectl config set-context --current --namespace=chantico
    kubectl apply -n chantico -f ./config/samples/chantico_v1alpha1_measurementdevice_mock.yaml
  3. Wait for the SNMP generator job:
    kubectl get jobs -n chantico -o wide
  4. Create a PhysicalMeasurement pointing at the mock target:
    kubectl apply -n chantico -f ./config/samples/chantico_v1alpha1_physicalmeasurement_mock.yaml
  5. Port-forward Prometheus (if not already done by the local development environment) and verify targets:
    kubectl port-forward -n chantico deployment/chantico-prometheus 19090:9090
    Open http://localhost:19090/targets and verify the target is UP.

Tip: To add more devices beyond the second, copy the mock manifests, update the names (e.g. chantico-snmp-mock-3), pick a free NodePort, and create corresponding MeasurementDevice / PhysicalMeasurement resources. Prometheus will automatically pick up new targets via file_sd_configs — no restart required.

Adding baremetal resources and linking them to the mock SNMP device

To demonstrate the full workflow, you can also create a DataCenterResource representing a baremetal resource and link it to the mock SNMP device. This makes it possible to aggregate metrics from the SNMP devices together into the data center resource, store the metrics in VictoriaMetrics and visualize them in Grafana.

To do so, you can apply the following manifest:

kubectl apply -n chantico -f ./config/samples/chantico_v1alpha1_datacenterresource.yaml

If all the resources are created correctly, you should see the following when querying the resources in the chantico namespace on your cluster:

$ kubectl get datacenterresource,measurementdevice,physicalmeasurement -n chantico
NAME                                                                           STATUS   REASON       TYPE      AGE
datacenterresource.chantico-project.github.io/datacenterresource-misd-gbm-01   True     Reconciled   Applied   
datacenterresource.chantico-project.github.io/datacenterresource-pdu1          True     Reconciled   Applied   
datacenterresource.chantico-project.github.io/datacenterresource-pdu2          True     Reconciled   Applied   

NAME                                                 STATUS   REASON      TYPE             AGE
measurementdevice.chantico-project.github.io/tno     True     Succeeded   ExporterReload
measurementdevice.chantico-project.github.io/tno-2   True     Succeeded   ExporterReload

NAME                                                                          STATUS   REASON       TYPE      AGE
physicalmeasurement.chantico-project.github.io/physicalmeasurement-pdu1-out   True     Reconciled   Applied   
physicalmeasurement.chantico-project.github.io/physicalmeasurement-pdu2-out   True     Reconciled   Applied

Additionally, you can verify in Prometheus that the metrics are being scraped from the mock SNMP devices and aggregated into the DataCenterResource metrics. These will show up in the “Rule health” section as the following rules containing the subsequent metrics:

  • chantico_datacenterresource_pdu1
    • chantico_power_watts{resource="datacenterresource-pdu1", type="pdu"}
  • chantico_datacenterresource_pdu2
    • chantico_power_watts{resource="datacenterresource-pdu2", type="pdu"}
  • chantico_datacenterresource_misd_gbm_01
    • chantico_power_coefficient{child="datacenterresource-misd-gbm-01", parents="datacenterresource-pdu1}
    • chantico_power_coefficient{child="datacenterresource-misd-gbm-01", parents="datacenterresource-pdu2}
    • chantico_power_watts{resource="datacenterresource-misd-gbm-01", type="baremetal"}

You can query these metrics from Prometheus for the recent data of the specific time series. You can also visualize these metrics in Grafana by visiting the pre-configured “Chantico” dashboard.