• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

promjs

A Prometheus metrics registry implemented in TypeScript

Goals

  • Stick to Prometheus client best practices as closely as possible
  • Run in Node.js or the browser
  • Fit into the modern JavaScript ecosystem
  • Minimally rely on third-party dependencies

Installation

Install via npm:

$ npm install --save promjs

or via yarn:

$ yarn add promjs

Usage

// Using es6 imports
import prom from 'promjs';
// Using CommonJS
const prom = require('promjs');

const registry = prom();
const pageRequestCounter = registry.create('counter', 'page_requests', 'A counter for page requests');

pageRequestCounter.inc();
console.log(registry.metrics());
// =>
// # HELP page_requests A counter for page requests \n
// # TYPE page_requests counter
// page_requests 1 \n

API

prom()

Returns a registry class.

Registry

registry.create(type, name, help) => collector (counter | gauge | histogram)

Returns a metric class of the specified type. The metric is already registered with the registry that creates it.

Arguments

  1. type (String): The type of metric to create. The current supported types are counter, gauge, and histogram.
  2. name (String): The name of the metric
  3. help (String): The help message for the metric

Example

import prom from 'promjs';

const registry = prom();
const counter = registry.create('counter', 'my_counter', 'A counter for things');

registry.metrics() => string

Returns a prometheus formatted string containing all existing metrics.

const counter = registry.create('counter', 'my_counter', 'A counter for things');
counter.inc();
console.log(registry.metrics());
// =>
// # HELP my_counter A counter for things \n
// # TYPE my_counter counter
// my_counter 1 \n

registry.clear() => self

Removes all metrics from internal data storage. Returns itself to allow for chaining.

registry.reset() => self

Resets all existing metrics to 0. This can be used to reset metrics after reporting to a prometheus aggregator. Returns itself to allow for chaining.

registry.get(type, name) => collector (counter | gauge | histogram) | null

Fetches an existing metric by name. Returns null if no metrics are found

Collector

All of the metric classes (Counter, Gauge, Histogram) inherit from the Collector class. Collector methods are available on each of the metic classes.

collector.reset([labels]) => self

Resets metrics in the collector. Optionally pass in labels to reset only those labels.

collector.resetAll() => self

Resets all metrics in the collector, including metrics with labels.

Counter

A counter can only ever be incremented positively.

counter.inc([labels]) => self

Increments a counter. Optionally pass in a set of labels to increment only those labels.

counter.add(amount, [labels]) => self

Increments a counter by a given amount. amount must be a Number. Optionally pass in a set of labels to increment only those labels.

const counter = registry.create('counter', 'my_counter', 'A counter for things');
counter.inc();
counter.add(2, { ok: true, status: 'success', code: 200 });
counter.add(2, { ok: false, status: 'fail', code: 403 });

console.log(registry.metrics());
// =>
// # HELP my_counter A counter for things
// # TYPE my_counter counter
// my_counter 1
// my_counter{ok="true",status="success",code="200"} 2
// my_counter{ok="false",status="fail",code="403"} 2

Gauge

A gauge is similar to a counter, but can be incremented up and down.

gauge.inc([labels]) => self

Increments a gauge by 1.

gauge.dec([lables]) => self

Decrements a gauge by 1.

gauge.add(amount, [lables]) => self

Increments a gauge by a given amount. amount must be a Number.

gauge.sub(amount, [labels]) => self

Decrements a gauge by a given amount.

const gauge = registry.create('gauge', 'my_gauge', 'A gauge for stuffs');
gauge.inc();
gauge.inc({ instance: 'some_instance' });
gauge.dec({ instance: 'some_instance' });
gauge.add(100, { instance: 'some_instance' });
gauge.sub(50, { instance: 'some_instance' });

console.log(registry.metrics());
// =>
// # HELP my_gauge A gauge for stuffs
// # TYPE my_gauge gauge
// my_gauge 1
// my_gauge{instance="some_instance"} 50

Histogram

Histograms are used to group values into pre-defined buckets. Buckets are passed in to the registry.create() call.

histogram.observe(value) => self

Adds value to a pre-existing bucket.value must be a number.

const histogram = registry.create('histogram', 'response_time', 'The response time', [
  200,
  300,
  400,
  500
]);
histogram.observe(299);
histogram.observe(253, { path: '/api/users', status: 200 });
histogram.observe(499, { path: '/api/users', status: 200 });

console.log(registry.metrics());
// =>
// # HELP response_time The response time
// # TYPE response_time histogram
// response_time_count 3
// response_time_sum 599
// response_time_bucket{le="200"} 1
// response_time_bucket{le="400",path="/api/users",status="200"} 1
// response_time_bucket{le="200",path="/api/users",status="200"} 1

Getting Help

If you have any questions about, feedback for or problems with promjs:

Weaveworks follows the CNCF Code of Conduct. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a Weaveworks project maintainer, or Alexis Richardson ([email protected]).

Your feedback is always welcome!

More Repositories

1

weave

Simple, resilient multi-host containers networking and more.
Go
6,618
star
2

scope

Monitoring, visualisation & management for Docker & Kubernetes
Go
5,854
star
3

eksctl

The official CLI for Amazon EKS
Go
4,493
star
4

ignite

Ignite a Firecracker microVM
Go
3,486
star
5

grafanalib

Python library for building Grafana dashboards
Python
1,872
star
6

footloose

Container Machines - Containers that look like Virtual Machines
Go
1,589
star
7

awesome-gitops

A curated list for awesome GitOps resources
1,504
star
8

kubediff

Kubediff: a tool for Kubernetes to show differences between running state and version controlled configuration.
Python
1,182
star
9

tf-controller

A GitOps Terraform controller for Kubernetes
Go
1,002
star
10

weave-gitops

Weave GitOps provides insights into your application deployments, and makes continuous delivery with GitOps easier to adopt and scale across your teams.
MDX
914
star
11

mesh

A tool for building distributed applications.
Go
882
star
12

tcptracer-bpf

eBPF program using kprobes to trace TCP events without run-time compilation dependencies
Shell
409
star
13

wksctl

Open Source Weaveworks Kubernetes System
Go
396
star
14

wks-quickstart-firekube

Example configuration to create Kubernetes clusters powered by ignite and gitops
Shell
343
star
15

prom-aggregation-gateway

An aggregating push gateway for Prometheus
Shell
328
star
16

vscode-gitops-tools

GitOps Visual Studio Code Extension
TypeScript
224
star
17

weave-gitops-enterprise

This repo provides the enterprise level features for the weave-gitops product, including CAPI cluster creation and team workspaces.
Go
160
star
18

common

Libraries used in multiple Weave projects
Go
129
star
19

go-odp

A Go library to control the Open vSwitch in-kernel datapath
Go
73
star
20

libgitops

A Go library for implementing GitOps, used by Ignite
Go
66
star
21

terraform-kubernetes

Terraform module for provisioning AWS resources to run a Kubernetes cluster
HCL
61
star
22

eks-quickstart-app-dev

Example flux manifests for eksctl gitops
56
star
23

cluster-api-provider-existinginfra

Manage existing infrastructure with Cluster API using this provider.
Go
45
star
24

build-tools

Collection of build & test tools shared by various Weaveworks projects
Shell
44
star
25

flintlock

Lock, Stock, and Two Smoking MicroVMs. Create and manage the lifecycle of MicroVMs backed by containerd.
Go
41
star
26

kubernetes-ami

A simple AMI and CloudFormation for launching Kubernetes on AWS
Shell
40
star
27

promrus

Logrus hook to expose Prometheus metrics.
Go
34
star
28

weaveworks-backstage

Backstage app and Plugins for WeaveWorks and Flux.
TypeScript
33
star
29

policy-agent

Weaveworks Policy Agent
Go
32
star
30

ui-components

A collection of UI components that are shared across Weaveworks projects
JavaScript
30
star
31

integrations

Weave Third-Party Integrations
Shell
26
star
32

prometheus_sql_exporter

A service that exposes user-specified SQL queries on a prometheus metrics endpoint
Go
26
star
33

cortex-dashboards

Grafana dashboards for Cortex
Python
22
star
34

guestbook-gitops

GitOps with GitHub Actions to ECR and EKS
Makefile
20
star
35

fk-covid

Firekube distro with COVID-Net ML
Shell
18
star
36

multienv-example

Example of how to manage configuration for multiple Kubernetes clusters e.g., dev, staging, production
14
star
37

profiles

GitOps native package management
Go
11
star
38

mlops-profile

Kubeflow-based Machine Learning Profile
10
star
39

launcher

Weave Cloud Launcher
Go
10
star
40

eks-appmesh-profile

AWS App Mesh eksctl profile
10
star
41

docker-ansible

Shell
9
star
42

homebrew-tap

Ruby
9
star
43

gitopssets-controller

Manages the GitOpsSet CRDs.
Go
9
star
44

weavecloud-browser-extension

Browser extension to integrate Grafana dashboards with Weave Cloud
JavaScript
9
star
45

billing-client

A client library for sending usage data to the billing system.
Go
7
star
46

pctl

CLI for interacting with profiles
Go
7
star
47

flux-example

Small example of Kubernetes config, for the purpose of illustrating how to use Flux
Go
7
star
48

wordepress

Tool support enabling hosting of technical documentation in WordPress
Go
7
star
49

MoodyKubie

Face detection and emotion classification, in Docker containers, on Kubernetes, running on CubieBoard (ARM).
JavaScript
7
star
50

flux-adapter

Connecting fluxd to Weave Cloud
Go
6
star
51

image-builder

Image building for Weaveworks projects.
Dockerfile
6
star
52

covid-ml-profile

FireKube and EKS Machine Learning Profile for the fk-covid Project
5
star
53

cluster-controller

cluster-controller for Weave GitOps Enterprise
Go
5
star
54

alertdiff

Expose metrics detailing differences between two alert sources
Haskell
4
star
55

flux2-openshift

OperatorHub submission repo for Flux2
JavaScript
4
star
56

weave-gitops-quickstart

Quickstart resources to get you started with Weave GitOps Enterprise
4
star
57

cluster-bootstrap-controller

bootstrap-controller for Weave Gitops Enterprise
Go
4
star
58

profiles-catalog

Profiles for Weave GitOps
Makefile
4
star
59

gitops-toolkit-demo

GoTK Demo
3
star
60

schemer

Library to generate JSON schemas for your docs
Go
3
star
61

weave-gitops-scenarios

Various test scenarios for weave-gitops
Python
3
star
62

wkp-docs

Home of the Weave Kubernetes Platform technical documentation.
JavaScript
3
star
63

policy-library

The policy-as-code library
Open Policy Agent
3
star
64

cluster-api-provider-firecracker

CAPF - A Cluster API Provider for Firecracker
2
star
65

backstage-sockshop

Sockshop Components for Backstage
2
star
66

weave-gitops-private

This is for tracking weaveworks internal information on weave-gitops. Will include issues, internal roadmaps, etc.
Shell
2
star
67

service

☁️ Images for Weave Cloud (R) (TM) (C) ☁️
Go
2
star
68

clusters-config

Configuration for engineering's ephemeral clusters
Shell
2
star
69

weave-gitops-enterprise-tf-aws-provider

GitOps-first Terraform for Weave GitOps enterprise customers to use.
HCL
1
star
70

weave-gitops-ssp-addon

Weave GitOps AddOn for SSP EKS Quickstart
TypeScript
1
star
71

buildpack-profile

1
star
72

weave-assured-flux

Weaveworks Assured Flux
Shell
1
star
73

cluster-reflector-controller

Automatically "reflect" existing AKS/EKS/GKE clusters into Weave GitOps Enterprise.
Go
1
star
74

go-git-providers

A collection of clients for different git providers like Github
Go
1
star
75

weave-action

Weaveworks GitHub Actions
1
star
76

homebrew-weave-gitops

The repository contains only the brew formula for installing weave-gitops
Ruby
1
star
77

templates-controller

Manages the GitopsTemplates CRDs
Go
1
star
78

flux-shard-controller

Easily spread load across replicated kustomize, source, helm and notification controllers
Go
1
star
79

weave-gitops-profile-examples

These profiles and profile index can be used as examples of how to construct a Weave GitOps Enterprise profile and repository.
Smarty
1
star
80

corp-gh-org-controller

A Kubernetes controller to create and manage GitHub Enterprise Organisations.
Go
1
star
81

microvm-scheduler-api

The API types for the Microvm Scheduler
1
star
82

pipeline-controller

This repository contains the Pipeline CRD and associated controller for Weave GitOps Enterprise.
Go
1
star
83

weaveworks-backstage-enterprise

Weaveworks enterprise backstage plugins
TypeScript
1
star
84

progressive-delivery

This repository contains the progressive delivery API handlers that Weave GitOps Enterprise serves.
Go
1
star
85

weave-gitops-clusters

Configuration for the staging k8s clusters used by weave-gitops.
HCL
1
star
86

weave-policy-validator

Weaveworks Infrastructure as Code Validator
Go
1
star
87

sa-demos

This repository is dealing with the Weave GitOps demos and demo environments. Please use it to file and update issues that you are seeing. You can also put your demo guides and demo scripts here.
Shell
1
star