Script to gather information for SW360 dashboard.
- Setup and install poetry.
- Install the packages with
poetry install
. - Generate the group specific files with the following command:
- Group specific files are generated to create specific metrics for
businessUnit
, a.k.a. Tags of a project. - This helps you generate detailed metrics for each business unit using your SW360 instance.
- Let's say you have business units like
DEPT
,DEPT2
, etc., you can generate files for each of them in following manner (case-sensitive):poetry run generate-groups DEPT DEPT2
- You must run this command for at least one business unit.
- This will create files under
src/sw360_dashboard
package and Grafana dashboards undergrafana/dashboards/
directory.
- Group specific files are generated to create specific metrics for
- Create
.env
from.env.example
, set the actual values and setDRY_RUN=false
to push actual data. - To run,
sw360-exporter <groups>
where<groups>
is a space-separated list of business units you want to generate metrics for. Default is all groups. - Optionally, setup a cron job run by non-root user (e.g.
sw360
):- Setup a non-root user (e.g.
sw360
) (optional, but recommended):sudo adduser sw360
- Create log directory:
sudo mkdir -p /var/log/sw360/ sudo chown -R sw360:sw360 /var/log/sw360/
- Copy the helper script dashboard_cron.sh to a
location accessible by
sw360
user. - As
sw360 user
, edit cron tab withcrontab -e
and add the following line:This will run the script every day at 20:00.0 20 * * * cd /path/to/dashboard_cron.sh && /path/to/dashboard_cron.sh >> /var/log/sw360/dashboard.log 2>&1
- Setup a non-root user (e.g.
couchdb_utils.py
contains utility functions for interacting with CouchDB,
creating views, fetching results, and pushing metrics to Prometheus.
couchdb_DEPT_exporter.py
scripts are responsible for fetching data from
CouchDB for different project tags and pushing metrics to Prometheus.
couchdb_CLI_exporter.py
script generates the metrics of CLX attachments used
per business unit.
couchdb_common_metrics.py
script generates the common metrics like type of
components, number of projects over time, etc.
cli.py
provides a command-line interface to run the exporter scripts for
specified business units.
dashboard_cron.sh
is a helper script to run the exporter scripts as a cron job.grafana
directory contains the Grafana dashboards and configuration files for Grafana itself and the Apache reverse proxy configuration.
Note: the scripts here assume you are using the non-root using sw360
as
described in Installation > 5. > 1.
- Download latest and stable version of Prometheus from the
official website and extract it to
/opt/prometheus/
. - Change the ownership of the directory:
sudo chown -R sw360:sw360 /opt/prometheus/
- Create a systemd service file at
/etc/systemd/system/prometheus.service
for Prometheus:[Unit] Description=Prometheus server Wants=network-online.target After=network-online.target [Service] User=sw360 Group=sw360 Type=simple Restart=always WorkingDirectory=/opt/prometheus RuntimeDirectory=prometheus RuntimeDirectoryMode=0750 ExecStart=/opt/prometheus/prometheus \ --config.file=/opt/prometheus/prometheus.yml \ --storage.tsdb.retention.time=7d LimitNOFILE=10000 TimeoutStopSec=20 [Install] WantedBy=multi-user.target
- Enable and start the Prometheus service:
sudo systemctl daemon-reload sudo systemctl enable prometheus sudo systemctl start prometheus
- Download latest and stable version of Prometheus Pushgateway from the
official website and extract it to
/opt/pushgateway/
. - Change the ownership of the directory:
sudo chown -R sw360:sw360 /opt/pushgateway/
- Create a systemd service file at
/etc/systemd/system/pushgateway.service
for Prometheus Pushgateway:[Unit] Description=Prometheus Pushgateway server Wants=network-online.target After=prometheus.target [Service] User=sw360 Group=sw360 Type=simple Restart=always WorkingDirectory=/opt/pushgateway/ RuntimeDirectory=pushgateway RuntimeDirectoryMode=0750 ExecStart=/opt/pushgateway/pushgateway LimitNOFILE=10000 TimeoutStopSec=20 [Install] WantedBy=multi-user.target
- Enable and start the Prometheus Pushgateway service:
sudo systemctl daemon-reload sudo systemctl enable pushgateway sudo systemctl start pushgateway
- Make sure Prometheus is scraping the Pushgateway. Add the following to
/opt/prometheus/prometheus.yml
:scrape_configs: - job_name: 'pushgateway' static_configs: - targets: ['localhost:9091']
- Install Grafana (check the
official installation guide):
sudo apt-get install -y grafana
- Modify the Grafana config at
/etc/grafana/grafana.ini
with values from grafana/grafana.ini - Enable and start the Grafana service:
sudo systemctl enable grafana-server sudo systemctl start grafana-server
Note: After setting the auth.proxy
in grafana.ini, you need to login with
your user first, disable the auth.proxy
and login with the admin user. Then
promote your user as an admin user. After that, you can enable the
auth.proxy
again.
Once above steps are completed, you can import the dashboards into Grafana. Make
sure you've run the poetry run generate-groups DEPT DEPT2
from
installation step 3 otherwise the grafana/dashboards/
directory will be empty.
- Open Grafana and navigate to the "Dashboards" section.
- Setup the datasource:
- Click on "Add data source".
- Select "Prometheus" and configure it to point to your Prometheus server.
- For example, by default it will be running on
http://localhost:9090
. - Click "Save & Test" to verify the connection.
- Click on "Manage" and then "Import".
- Upload the JSON files from the grafana/dashboards/ directory.
Grafana also allows automated setup with
Grafana provisioning
and this repo contains helper scripts for the same under
grafana/provisioning.
Find your provisioning directory and data directory from your
grafana config,
which defaults to /etc/grafana/provisioning
and /var/lib/grafana
respectively. If the locations are not default, you would have to update the
grafana/provisioning/datasources.yaml
and fix the path to data directory.
Once done, copy following files to their respective location (update the path
according to your setup) for provisioning.
- Shutdown the Grafana if running.
- Provision the datasource:
sudo cp grafana/provisioning/datasources.yaml /etc/grafana/provisioning/datasources/prometheus.yaml
- Copy the dashboards:
sudo cp -r grafana/dashboards /var/lib/grafana/dashboards/
- Provision the dashboards:
sudo cp grafana/provisioning/dashboards.yaml /etc/grafana/provisioning/dashboards/darshboard.yaml
Once done, at the next start of Grafana, it should autoconfigure the datasource and dashboards for you.
If you are using Apache as your reverse proxy and Mellon for SAML based authentication, you can refer to the grafana/apache-sw360.conf file as reference and update the Apache2 enabled site serving the SW360 application.