simple-prom/objects/Gauge.ts

32 lines
No EOL
726 B
TypeScript

// Copyright (c) Catgirl Enterprises - Licensed under MIT
// Check LICENSE in repository root for more information.
import IMetric from "../interfaces/IMetric";
export default class Gauge implements IMetric {
private _name:string;
private _helpText:string;
public Value:number;
public constructor(name:string) {
this._name = name;
this._helpText = "";
this.Value = 0;
}
public get name() {
return this._name;
}
public add(value:number) {
this.Value += value;
}
public setHelpText(value:string) {
this._helpText = value;
}
public toString() {
return `${this._helpText.length > 0 ? `# HELP ${this._name} ${this._helpText}\n` : ""}# TYPE ${this._name} gauge\n${this._name} ${this.Value}\n`;
}
}