Metadata-Version: 2.2
Name: bisos.grafana
Version: 0.1
Summary: bisos.grafana: Grafana via BISOS Capability Bundles
Author: Mohsen Banan
Author-email: libre@mohsen.1.banan.byname.net
Maintainer: Mohsen Banan
Maintainer-email: libre@mohsen.1.banan.byname.net
License: AGPL
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: bisos
Requires-Dist: bisos.b
Requires-Dist: bisos.banna
Requires-Dist: bisos.basics
Requires-Dist: bisos.capability
Requires-Dist: bisos.common
Requires-Dist: bisos.csPlayer
Requires-Dist: bisos.csSeed
Requires-Dist: bisos.debian
Requires-Dist: bisos.dnsCap
Requires-Dist: bisos.sbom
Requires-Dist: bisos.webCap
Requires-Dist: setuptools==75.8.0
Requires-Dist: wheel==0.38.4
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: license
Dynamic: maintainer
Dynamic: maintainer-email
Dynamic: requires-dist
Dynamic: summary

===================================================
bisos.grafana: Grafana via BISOS Capability Bundles
===================================================

.. contents::
   :depth: 3
..

Overview
========

*bisos.grafana* is a BISOS package for running `Grafana
OSS <https://grafana.com/oss/grafana/>`__ on a BISOS host as a BISOS
Capability Bundle (CBS/CBM) of ``systemd``-planted Command Services.

A planted pointer leaf (``cbmProc.spcs``, at
``sys/cbm/collective/hereWeb/grafana/``) subprocess-invokes a Capability
Bundle Specification (``grafana-cbs.pcs``). The CBS declares package
installation (sboms), the ``grafana`` ``systemd`` unit, and the assembly
step that makes Grafana browsable as ``http://grafana.here``.

Debian does not package Grafana. The sbom fetches the Grafana OSS
tarball from upstream at a pinned version, refusing it if its checksum
does not match.

It is useful out of the box: this host's Prometheus
(`bisos.prometheus <https://github.com/bisos-pip/prometheus>`__) is
provisioned as the default datasource, and a small *Host
(node\ exporter)* dashboard is provisioned under the *BISOS* folder. The
login is **admin / grafana**.

Package Documentation At Github
===============================

The information below is a subset of the full of documentation for this
bisos-pip package. More complete documentation is available at:
https://github.com/bisos-pip/grafana-cs

.. _table-of-contents:

Table of Contents TOC
=====================

-  `Overview <#overview>`__
-  `Package Documentation At
   Github <#package-documentation-at-github>`__
-  `The BISOS Grafana Model <#the-bisos-grafana-model>`__
-  `The Login: rawBisos Convenience, Insecure by
   Design <#the-login-rawbisos-convenience-insecure-by-design>`__
-  `What Gets Installed, and Where <#what-gets-installed-and-where>`__
-  `The 3 sboms: Server, Usage, and the
   CBS's <#the-3-sboms-server-usage-and-the-cbss>`__
-  `The systemd Unit <#the-systemd-unit>`__
-  `Listeners and Ports <#listeners-and-ports>`__
-  `Installation <#installation>`__

   -  `Installation With pip <#installation-with-pip>`__
   -  `Installation With pipx <#installation-with-pipx>`__

-  `Usage <#usage>`__

   -  `Materialization <#materialization>`__
   -  `Day-to-Day Admin:
      ``grafanaAdmin.cs`` <#day-to-day-admin-grafanaadmincs>`__
   -  `Direct Command Cheat Sheet:
      ``quickGrafana.cs`` <#direct-command-cheat-sheet-quickgrafanacs>`__
   -  `The API: curl and gcx <#the-api-curl-and-gcx>`__

-  `Key Files <#key-files>`__
-  `Part of BISOS — ByStar Internet Services Operating
   System <#part-of-bisos--bystar-internet-services-operating-system>`__
-  `Documentation and Blee-Panels <#documentation-and-blee-panels>`__
-  `Support <#support>`__
-  `Planned Improvements <#planned-improvements>`__

   -  `The "secure it" layer: a real admin password, HTTPS
      (bisos.crypt), listening beyond
      loopback <#the-secure-it-layer-a-real-admin-password-https-bisoscrypt-listening-beyond-loopback>`__
   -  `Architectures other than amd64 (pin each one's checksum in
      grafanaInfo) <#architectures-other-than-amd64-pin-each-ones-checksum-in-grafanainfo>`__
   -  `Plant the CBM leaf in bro\ rawBisos
      (``sys/cbm/collective/hereWeb/grafana/``) <#plant-the-cbm-leaf-in-bro_rawbisos-syscbmcollectiveherewebgrafana>`__

The BISOS Grafana Model
=======================

``bisos.grafana`` (``/bisos/git/bxRepos/bisos-pip/grafana``) packages
Grafana OSS 13.2.4 as a hereWeb CBS/CBM. It is built on the same pattern
as ``bisos.kafka`` and ``bisos.prometheus`` (the
``cbm-package-authorship`` skill): one module of facts
(``grafanaInfo.py``), pinned and checksummed upstream binaries, config
written only when absent, a read-only ``driftCheck``, a service sbom and
a usage sbom joined only by the CBS.

``bisos.grafana`` does not import ``bisos.prometheus``: the datasource
takes Prometheus's port from ``bisos.banna``. On a host without
Prometheus the datasource is simply unreachable.

Grafana would otherwise download its "preinstalled" app plugins from
grafana.com at every start, unpinned and unverified, outside the sbom.
``grafana.ini`` turns that off
(``[plugins] preinstall_disabled = true``), as it turns off usage
reporting and update checks. Plugins are installed deliberately, with
``grafana cli``.

**As of 2026-10-15 it is materialized on one host** (Debian 13): unit
active, ``http://grafana.here/login`` 200, the Prometheus datasource
healthy, the host dashboard provisioned, ``driftCheck`` agrees.

The Login: rawBisos Convenience, Insecure by Design
===================================================

``bisos.grafana`` is used primarily in rawBisos (``bro_rawBisos``), a
public layer that is recognized as insecure. Its convention is user
``admin``, password the service's name: **admin / grafana**. It is set
in ``grafana.ini`` (``[security]``), which Grafana applies only when it
creates ``grafana.db`` at the first start; change it later in the UI or
with ``grafana cli admin reset-admin-password``. A "secure it" layer, on
top of this one, is where a real password, HTTPS and listening beyond
loopback belong.

What Gets Installed, and Where
==============================

Every fact below lives in one place,
``py3/bisos/grafana/grafanaInfo.py``, which the sboms, the unit, the dns
and vhost files and the admin CS all read.

+------------------------+------------------------+------------------+
| What                   | Where                  | Owner            |
+========================+========================+==================+
| The ``grafana``        | uid/gid 505, from      | —                |
| account                | bisos.banna            |                  |
|                        | ``sysAccts``           |                  |
+------------------------+------------------------+------------------+
| Grafana OSS 13.2.4     | ``/opt/gr              | root             |
|                        | afana/grafana-13.2.4`` |                  |
+------------------------+------------------------+------------------+
| Active Grafana         | ``                     | root             |
|                        | /opt/grafana/current`` |                  |
|                        | -> the above           |                  |
|                        | (``--homepath``)       |                  |
+------------------------+------------------------+------------------+
| gcx 1.6.0 (usage side) | ``/op                  | root             |
|                        | t/grafana/gcx-1.6.0``, |                  |
|                        | ``/opt/grafana/gcx``   |                  |
|                        | -> it                  |                  |
+------------------------+------------------------+------------------+
| Config                 | ``/etc                 | root:grafana 640 |
|                        | /grafana/grafana.ini`` |                  |
+------------------------+------------------------+------------------+
| Overrides (``GF_*``)   | ``                     | root:grafana 640 |
|                        | /etc/default/grafana`` |                  |
+------------------------+------------------------+------------------+
| Datasource             | ``/etc/grafan          | root:grafana 640 |
| provisioning           | a/provisioning/datasou |                  |
|                        | rces/prometheus.yaml`` |                  |
+------------------------+------------------------+------------------+
| Dashboard provisioning | ``/etc/                | root:grafana 640 |
|                        | grafana/provisioning/d |                  |
|                        | ashboards/bisos.yaml`` |                  |
+------------------------+------------------------+------------------+
| The host dashboard     | ``/etc/grafana/        | root:grafana 640 |
|                        | dashboards/host.json`` |                  |
+------------------------+------------------------+------------------+
| ``grafana.db``,        | ``/var/lib/grafana``   | grafana 750      |
| plugins                |                        |                  |
+------------------------+------------------------+------------------+

``/etc/grafana`` is 750 root:grafana: ``grafana.ini`` holds the login.
Every file is written only when absent, so hand overrides survive
re-runs of the sbom; ``grafanaAdmin.cs -i driftCheck`` diffs each live
file against its generator. Only amd64 has a pinned checksum today; the
sbom refuses another architecture.

The 3 sboms: Server, Usage, and the CBS's
=========================================

+-------------------------+-------------------------+---------------+
| sbom                    | Installs                | Pulls in      |
+=========================+=========================+===============+
| ``grafana-sbom.pcs``    | the account, Grafana,   | nothing       |
|                         | config and provisioning |               |
+-------------------------+-------------------------+---------------+
| ``                      | gcx, Grafana Labs' CLI  | nothing       |
| grafanaUsage-sbom.pcs`` | for Grafana's HTTP API  |               |
+-------------------------+-------------------------+---------------+
| ``grafanaCbs-sbom.pcs`` | nothing of its own      | the two above |
+-------------------------+-------------------------+---------------+

Grafana's HTTP API is part of the server; what uses it is packaged
separately. ``gcx`` (which replaced ``grafanactl``) is a pinned,
checksummed binary, so it is the usage sbom's.
``grafana-foundation-sdk`` (dashboards as code, Python) goes into each
consumer's own venv. ``grafana cli`` ships with the server and does
server-side admin, so it stays with the server. The CBS runs both sboms,
through ``grafanaCbs-sbom.pcs``, because a CBS names one sbom.

The systemd Unit
================

+----------------------+----------------------+----------------------+
| Unit                 | Runs                 | Ordering             |
+======================+======================+======================+
| ``grafana-sysd.pcs`` | ``grafana s          | ``Af                 |
|                      | erver --homepath=/op | ter=network.target`` |
|                      | t/grafana/current -- |                      |
|                      | config=grafana.ini`` |                      |
+----------------------+----------------------+----------------------+

It runs as ``User=grafana``. Logs go to journald
(``[log] mode = console``).

Listeners and Ports
===================

Ports are assigned in ``bisos.banna`` (``tcpPorts.py``), never
hardcoded.

========================= ======================= ================
Listener                  Address                 banna name
========================= ======================= ================
Grafana (UI, HTTP API)    ``127.0.0.1:24011``     ``grafana``
Grafana, via nginx        ``http://grafana.here`` — (127.0.22.115)
The datasource it queries ``127.0.0.1:24010``     ``prometheus``
========================= ======================= ================

The nginx vhost also upgrades ``/api/live/`` to WebSocket, which Grafana
Live needs.

Installation
============

| The sources for the bisos.grafana pip package are maintained at:
| https://github.com/bisos-pip/grafana

| The bisos.grafana pip package is available at PYPI as
| https://pypi.org/project/bisos.grafana

You can install bisos.grafana with pip or pipx.

Installation With pip
---------------------

If you need access to bisos.grafana as a python module, install it with
pip:

.. code:: bash

   pip install bisos.grafana

Installation With pipx
----------------------

If you only need access to bisos.grafana on the command line, install it
with pipx:

.. code:: bash

   pipx install bisos.grafana

The following commands are made available:

-  ``grafanaAdmin.cs`` — day-to-day admin CS for this host's
   ``grafana.here`` installation.
-  ``quickGrafana.cs`` — direct-command cheat sheet: the HTTP API, gcx,
   grafana cli, the unit.
-  ``grafana-assemble.cs`` — assembly step: ``grafana.here`` dns entry
   and nginx vhost.
-  ``cbmProc-grafana.spcs`` — planted CBM pointer that materializes the
   CBS at this host.

The planted ``.pcs`` files (``grafana-cbs.pcs``, the three sboms,
``grafana-sysd.pcs``, ``grafana-here-dns.pcs``, ``grafana-wvd.pcs``) are
invoked directly from ``py3/bin/``.

Usage
=====

Materialization
---------------

.. code:: bash

   grafana-sbom.pcs -i sbom_fullUpdate             # install the server only
   grafanaUsage-sbom.pcs -i sbom_fullUpdate        # install the usage side only (gcx)
   grafana-cbs.pcs -i cbs_materialize              # both sboms + unit + assemble
   cbmProc-grafana.spcs -i cbm_enable              # at the planted CBM leaf, then:
   cbmProc-grafana.spcs -i cbm_materialize

Then browse ``http://grafana.here``, log in as admin / grafana, and open
*Dashboards > BISOS > Host (node\ exporter)*.

Day-to-Day Admin: ``grafanaAdmin.cs``
-------------------------------------

.. code:: bash

   grafanaAdmin.cs -i hostInfo        # fqdn, listener, login, install/config/data paths
   grafanaAdmin.cs -i servicesInfo    # links for operating the unit, dns and vhost
   grafanaAdmin.cs -i apiInfo         # health, datasources, dashboards through curl and gcx
   grafanaAdmin.cs -i driftCheck      # read-only: live config/provisioning, unit and link vs grafanaInfo
   grafanaAdmin.cs -i fullUpdate      # the three info Cmnds together

Direct Command Cheat Sheet: ``quickGrafana.cs``
-----------------------------------------------

.. code:: bash

   quickGrafana.cs

The API: curl and gcx
---------------------

.. code:: bash

   curl -s http://127.0.0.1:24011/api/health
   curl -s -u admin:grafana http://grafana.here/api/datasources/uid/bisos-prometheus/health
   export GCX_KEYCHAIN=off     # gcx wants an OS keychain; a BISOS host has none (plaintext under ~/.config/gcx)
   GRAFANA_PASSWORD=grafana /opt/grafana/gcx/gcx login local --server http://grafana.here --basic-auth --user admin --yes
   /opt/grafana/gcx/gcx dashboards list

Key Files
=========

-  ``py3/bisos/grafana/grafanaInfo.py`` — the single source of facts:
   pinned versions and checksums, paths, ports, the login, the
   generators of the config and provisioning files (including the host
   dashboard) and the unit's identity lines, the tarball-install script,
   and the drift helpers.
-  ``py3/bin/grafana-cbs.pcs`` — CBS declaring the bundle (sbom + unit +
   assemble).
-  ``py3/bin/cbmProc-grafana.spcs`` — planted CBM pointer leaf that
   materializes the CBS.
-  ``py3/bin/grafana-sbom.pcs``, ``grafanaUsage-sbom.pcs``,
   ``grafanaCbs-sbom.pcs`` — the server, usage and CBS sboms via
   `bisos.sbom <https://github.com/bisos-pip/sbom>`__.
-  ``py3/bin/grafana-sysd.pcs`` — the unit.
-  ``py3/bin/grafana-assemble.cs`` — assembly step (dns + vhost).
-  ``py3/bin/grafana-here-dns.pcs`` — ``.here`` fake-domain DNS
   registration for ``grafana.here``.
-  ``py3/bin/grafana-wvd.pcs`` — nginx vhost for ``grafana.here``,
   proxying to Grafana on loopback, with the WebSocket upgrade for
   Grafana Live.
-  ``py3/bin/grafanaAdmin.cs``, ``py3/bin/quickGrafana.cs`` — admin CS
   and cheat sheet.
-  ``py3/tests/verify.sh`` — smoke test of every command and of
   ``grafanaInfo``'s invariants.
-  ``py3/setup.py``, ``py3/pypiProc.sh`` — PyPI packaging (setup.py is
   dblock-driven; do not hand-edit).

Part of BISOS — ByStar Internet Services Operating System
=========================================================

Layered on top of Debian, **BISOS** (By\* Internet Services Operating
System) is a unified and universal framework for developing both
internet services and software-service continuums that use internet
services. See `Bootstrapping ByStar, BISOS and
Blee <https://github.com/bxGenesis/start>`__ for information about
getting started with BISOS.

**BISOS** is a foundation for **The Libre-Halaal ByStar Digital
Ecosystem** which is described as a cure for losses of autonomy and
privacy in a book titled: `Nature of
Polyexistentials <https://github.com/bxplpc/120033>`__

*bisos.grafana* is part of BISOS. It is a standalone package that can be
used independently of the full BISOS environment.

Documentation and Blee-Panels
=============================

bisos.grafana is part of the ByStar Digital Ecosystem
http://www.by-star.net.

This module's primary documentation is in the form of Blee-Panels.
Blee-Panels are in the ``./panels`` directory. From within Blee and
BISOS these panels are accessible under the Blee "Panels" menu.

See
`file:./panels/bisos.grafana/_nodeBase_/fullUsagePanel-en.org <./panels/bisos.grafana/_nodeBase_/fullUsagePanel-en.org>`__
for a starting point.

*bisos.grafana* is best developed with
`Blee <https://github.com/bx-blee>`__, the *By\* BISOS Libre-Halaal
Emacs Environment* — a layer on top of Emacs and BISOS which creates a
comprehensive integrated usage and development environment.

Support
=======

| For support, criticism, comments and questions; please contact the
  author/maintainer
| `Mohsen Banan <http://mohsen.1.banan.byname.net>`__ at:
  http://mohsen.1.banan.byname.net/contact

Planned Improvements
====================

.. _the-secure-it-layer-a-real-admin-password-https-bisos.crypt-listening-beyond-loopback:

TODO The "secure it" layer: a real admin password, HTTPS (bisos.crypt), listening beyond loopback
-------------------------------------------------------------------------------------------------

.. _architectures-other-than-amd64-pin-each-ones-checksum-in-grafanainfo:

TODO Architectures other than amd64 (pin each one's checksum in grafanaInfo)
----------------------------------------------------------------------------

.. _plant-the-cbm-leaf-in-brorawbisos-syscbmcollectiveherewebgrafana:

TODO Plant the CBM leaf in bro\ :sub:`rawBisos` (``sys/cbm/collective/hereWeb/grafana/``)
-----------------------------------------------------------------------------------------
