Overview
A self-hosted Source Collector runs on infrastructure you manage and submits billing data to the Varibill Source Collector API. You choose this option when your data lives in a system Varibill does not collect from directly, or when policy requires collection to run inside your own environment.
Self-hosted collection is built on the Varibill Source Collector Core PowerShell module. The module handles authentication, batching, retries, and submission, so a collector script only needs to gather data and hand it to the module.
Note: Before building a self-hosted collector, create the collector in the Varibill User Interface and select Self Hosted as the hosting provider. This generates the credentials the collector uses. See Configuring a New Source Collector.
Rated and Unrated Data
The module supports two data types:
- Unrated Source Data: raw usage or quantity records. Varibill applies your selling rates to calculate the billed amount.
- Rated Source Data: pre-calculated records where you supply the cost, price, and quantity.
Use unrated data when Varibill should do the rating, and rated data when your source system already calculates the charge.
Prerequisites
- PowerShell 5.1 or later (PowerShell 7 or later recommended).
- A Source Collector configured in the Varibill User Interface, set to Self Hosted.
- The collector credentials from the Source Collector API
Credentials section of the editor:
- Tenant Key
- Source Collector Key
- Source Collector Secret
- The Source Collector API URL for your environment.
- Network access from the host to the Source Collector API.
Warning! Treat the Source Collector Secret like a password. Do not commit it to source control or share it in plain text. Store it using a secret manager or an environment variable on the host that runs the collector.
How a Self-Hosted Collector Works
The Core module provides two classes that follow the same workflow:
- Create a data object with your collector credentials.
- Add records to it.
- Save the data to disk.
- Post the data to the Source Collector API.
The module also provides:
- Automatic batching: records are split into files of up to 10,000 records each by default.
- Staging files: pending uploads use a
.rdyextension; completed uploads use.json. - Response logging: API responses are saved for audit and troubleshooting.
- Configurable storage: data is written to a temporary directory by default, or to a path you specify.
Installing the Core Module
Install from the PowerShell Gallery:
Then import it before use:
Configuring Credentials
Assign your credentials and environment URL to variables. The keys come from the Source Collector API Credentials section of the collector editor.
# Confirm the Source Collector API URL for your environment.
$SourceCollectorAPI = "https://api.varibill.com/"
$TenantKey = "your-tenant-guid"
$SourceCollectorKey = "your-collector-guid"
$SourceCollectorSecret = "your-secret"Submitting Unrated Source Data
Use unrated data to send raw usage that Varibill will rate.
$unrated = New-UnratedSourceData `
-SourceCollectorAPI $SourceCollectorAPI `
-TenantKey $TenantKey `
-SourceCollectorKey $SourceCollectorKey `
-SourceCollectorSecret $SourceCollectorSecret
# AddUnratedSourceData(Client, Product, Record, UID, Timestamp, Quantity, Tag)
$unrated.AddUnratedSourceData(
"ClientName",
"ProductCode",
"RecordDescription",
"UniqueID",
(Get-Date),
100,
"OptionalTag"
)
$unrated.SaveData()
$unrated.PostSourceData()Submitting Rated Source Data
Use rated data when your source system already calculates cost and price.
$rated = New-RatedSourceData `
-SourceCollectorAPI $SourceCollectorAPI `
-TenantKey $TenantKey `
-SourceCollectorKey $SourceCollectorKey `
-SourceCollectorSecret $SourceCollectorSecret
# AddRatedSourceData(Client, Product, Record, UID, Timestamp, Quantity, Cost, Price, Tag)
$rated.AddRatedSourceData(
"ClientName",
"ProductCode",
"RecordDescription",
"UniqueID",
(Get-Date),
100,
50.00,
75.00,
"OptionalTag"
)
$rated.SaveData()
$rated.PostSourceData()Using the Example Collectors
The framework ships ready-made collectors you can use as a starting point or run directly. Each collector documents its own parameters, but all of them take the standard credential parameters above.
The VMware vCenter collector, for example, gathers virtual machine resource usage (CPU, memory, and storage) and submits it as unrated data:
./VCenter_0.5.ps1 `
-SourceCollectorAPI $SourceCollectorAPI `
-TenantKey $TenantKey `
-SourceCollectorKey $SourceCollectorKey `
-SourceCollectorSecret $SourceCollectorSecret `
-VCenterHost "vcenter.example.com" `
-VCenterUsername "admin" `
-VCenterPassword "password" `
-CPUProductCode "VM-CPU" `
-MemoryProductCode "VM-MEM" `
-HDDProductCode "VM-HDD"Tip: Most collectors accept an optional
-SourceCollectorPath to control where data files are
written, and a -VerboseOutput switch for diagnostic logging
while you test.
Running in a Container
The framework provides container runtime environments for common collector needs, including PowerShell, Azure (Az) PowerShell, and VMware PowerCLI, on supported Ubuntu base images. Running a collector in a container gives it a clean, repeatable runtime.
A containerized collector reads its credentials from environment variables on the host or orchestrator, so no secrets are stored in the image.
Scheduling
Run a self-hosted collector on a schedule using the scheduler native to your platform:
- On Windows, use Task Scheduler to run the PowerShell script.
- On Linux, use
cron. - In a container platform, use the platform’s scheduled job mechanism.
Match the schedule to your billing cycle so that data is collected before validation and invoicing.
Troubleshooting
- Pending
.rdyfiles: indicate data that was saved but not yet posted. Re-running the post step retries them. - API responses: the module saves responses alongside the data files; review them to see why a submission was rejected.
- Verbose logging: run the collector with
-VerboseOutputto see detailed diagnostic output. - Authentication failures: confirm the Tenant Key, Source Collector Key, and Source Collector Secret match the values in the collector editor, and that the collector is set to Self Hosted.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article