{"id":22869942,"url":"https://github.com/kobtea/jsonnet-libs","last_synced_at":"2025-03-31T11:25:30.098Z","repository":{"id":151990844,"uuid":"363350770","full_name":"kobtea/jsonnet-libs","owner":"kobtea","description":"Jsonnet libraries for Monitoring Mixin.","archived":false,"fork":false,"pushed_at":"2021-09-18T08:50:35.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-06T16:57:29.059Z","etag":null,"topics":["grafana","jsonnet","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Jsonnet","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kobtea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-01T07:33:25.000Z","updated_at":"2023-01-26T08:13:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"aaebee3d-3baf-4ec6-884e-e72b79a33096","html_url":"https://github.com/kobtea/jsonnet-libs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kobtea%2Fjsonnet-libs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kobtea%2Fjsonnet-libs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kobtea%2Fjsonnet-libs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kobtea%2Fjsonnet-libs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kobtea","download_url":"https://codeload.github.com/kobtea/jsonnet-libs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246460032,"owners_count":20781033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grafana","jsonnet","prometheus"],"created_at":"2024-12-13T13:12:48.315Z","updated_at":"2025-03-31T11:25:30.092Z","avatar_url":"https://github.com/kobtea.png","language":"Jsonnet","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonnet-libs\n\nThis repository aims to manage [Monitoring Mixins](https://monitoring.mixins.dev) and libraries for Jsonnet.\nMonitoring mixin is a set of Prometheus rules and Grafana dashboards.\n\n## Overview\n\n## As a project template\n\nTo use this repository as a project template, fork and clone it.\nSee usage section below.\n\n## As a library and mixin\n\nTo use libraries and mixins in this repository, install packages you need with jsonnet-bundler.\n\n```bash\n$ cd your-project\n$ jb init\n$ jb install https://github.com/kobtea/jsonnet-libs/lib@main\n$ jb install https://github.com/kobtea/jsonnet-libs/mixin/sample-one-mixin@main\n```\n\n## Directory structure\n\n```bash\n# dist contains generated rules and dashboards.\n# Deploy these files to each environment.\n├── dist\n│   ├── project-foo\n│   │   ├── alerts.yml\n│   │   ├── dashboards\n│   │   └── rules.yml\n│   └── project-k8s\n│       └── ...\n# env contains config for each environment.\n# environment is a logical unit such a `prod`, `dev`, `service1-in-eks` or `service2-in-gke`.\n# mixin.libsonnet is the entry point of mixin for each environment.\n├── env\n│   ├── project-foo\n│   │   ├── mixin.libsonnet\n│   └── project-k8s\n│       └── ...\n# lib contains jsonnet libraries not mixin.\n├── lib\n│   └── utils.libsonnet\n# mixin contains monitoring mixins.\n└── mixin\n    ├── sample-one-mixin\n    │   ├── alerts.libsonnet\n    │   ├── config.libsonnet\n    │   ├── dashboards\n    │   │   ├── dashboards.libsonnet\n    │   │   ├── sample-one-one.libsonnet\n    │   │   └── sample-one-two.libsonnet\n    │   ├── jsonnetfile.json\n    │   ├── jsonnetfile.lock.json\n    │   ├── mixin.libsonnet\n    │   └── rules.libsonnet\n    └── sample-two-mixin\n        └── ...\n```\n\n## Requirements\n\n- [jsonnet](https://github.com/google/jsonnet) or [go-jsonnet](https://github.com/google/go-jsonnet)\n- [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler)\n- [promtool](https://github.com/prometheus/prometheus)\n- [mixtool](https://github.com/monitoring-mixins/mixtool)\n- [fswatch](https://github.com/emcrisostomo/fswatch)\n\n## Usage\n\nSetup this repository.\n\n```bash\n$ git clone https://github.com/kobtea/jsonnet-libs.git\n$ cd jsonnet-libs\n$ jb install\n```\n\n### Prepare minxins\n\n#### Use mixins at another repository\n\nIf you want to use mixin at another repository such a [kubernetes-mixin](https://github.com/kubernetes-monitoring/kubernetes-mixin), install that package with jsonnet-bundler.\n\n```bash\n$ jb install https://github.com/kubernetes-monitoring/kubernetes-mixin\n```\n\n#### Create mixins at this repository\n\nIf you want to create a new mixin at this repository, refer to sample mixins at [here](https://github.com/kobtea/jsonnet-libs/tree/main/mixin).\n\n### Create environments\n\nCreate a config file for a new environment.\nThe only need is a file name of entry point is `mixin.libsonnet`.\n\n```bash\n$ mkdir env/project-sample\n$ vim env/project-sample/mixin.libsonnet\n```\n\nInclude mixins and override values.\n\n```jsonnet\n$ cat env/project-sample/mixin.libsonnet\nlocal sampleOne = import '../../mixin/sample-one-mixin/mixin.libsonnet';\nlocal k8s = import 'kubernetes-mixin/mixin.libsonnet';\n\nsampleOne {\n  _config+:: {\n    sampleOneSelector: 'job=\"sample-one-mod\"',\n  },\n} +\nk8s {\n  _config+:: {\n    nodeExporterSelector: 'job=\"node\"',\n  },\n}\n```\n\nUseful functions are under lib directory.\nFull example is [here](https://github.com/kobtea/jsonnet-libs/blob/main/env/project-foo/mixin.libsonnet).\n\n```jsonnet\n// include utils\nlocal utils = import '../../lib/utils.libsonnet';\n\n// override alert\nutils.overrideAlerts([\n  {\n    alert: 'SampleTwoUp',\n    expr: |||\n      up{%(sampleTwoSelector)s} == 0\n    ||| % $._config,\n  },\n]),\n\n// override rule\nutils.overrideRules([\n  {\n    record: 'instance_path:two_requests:rate5m',\n    expr: |||\n      rate(two_requests_total{%(sampleTwoSelector)s}[10m])\n    ||| % $._config,\n  },\n]),\n\n// override dashboard\nlocal dashboards = super.grafanaDashboards;\nlocal d1 = '%(sampleTwoGrafanaFolder)s/sample-two-one.json' % $._config;\n{\n  [d1]:\n    std.foldl(\n      function(acc, elm) acc + utils.overrideDashboardPanelTarget(elm.target, elm.title, acc),\n      [\n        {\n          title: 'Requests',\n          target: {\n            refId: 'A',\n            expr: 'avg(instance_path:one_requests:rate5m)',\n          },\n        },\n        {\n          title: 'Requests2',\n          target: {\n            refId: 'A',\n            expr: 'max(instance_path:one_requests:rate5m)',\n          },\n        },\n      ],\n      dashboards[d1],\n    )\n},\n```\n\n### Generate rules and dashboards\n\n```bash\n# format and check syntax\n$ make fmt\n$ make lint\n\n# generate yaml and json\n$ make generate ARG=project-sample\n```\n\nOutput files are in dist directory.\n\n### Deploy\n\nDeployment is out of the scope of this project.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkobtea%2Fjsonnet-libs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkobtea%2Fjsonnet-libs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkobtea%2Fjsonnet-libs/lists"}