@@ -35,8 +35,13 @@ def _convert_candidates_to_upgrade_infos(candidates):
3535 changes_dict = collections .defaultdict (lambda : collections .defaultdict (int ))
3636
3737 for candidate in candidates :
38+ # The 'now' archive only shows that packages are not installed. We tend
39+ # to filter the candidates on those kinds of conditions before reaching
40+ # here so here we don't want to include this information in order to
41+ # reduce noise in the data.
3842 origins = sorted (
39- {f"{ o .origin } :{ o .codename } /{ o .archive } " for o in candidate .origins }
43+ {f"{ o .origin } :{ o .codename } /{ o .archive } " for o in candidate .origins
44+ if o .archive != 'now' }
4045 )
4146 changes_dict ["," .join (origins )][candidate .architecture ] += 1
4247
@@ -105,6 +110,17 @@ def _write_autoremove_pending(registry, cache):
105110 g .set (len (autoremovable_packages ))
106111
107112
113+ def _write_installed_packages_per_origin (registry , cache ):
114+ installed_packages = {p .candidate for p in cache if p .is_installed }
115+ per_origin = _convert_candidates_to_upgrade_infos (installed_packages )
116+
117+ if per_origin :
118+ g = Gauge ('apt_packages_per_origin_count' , "Number of packages installed per origin." ,
119+ ['origin' , 'arch' ], registry = registry )
120+ for o in per_origin :
121+ g .labels (o .labels ['origin' ], o .labels ['arch' ]).set (o .count )
122+
123+
108124def _write_cache_timestamps (registry ):
109125 g = Gauge ('apt_package_cache_timestamp_seconds' , "Apt update last run time." , registry = registry )
110126 apt_pkg .init_config ()
@@ -138,6 +154,7 @@ def _main():
138154 _write_held_upgrades (registry , cache )
139155 _write_obsolete_packages (registry , cache )
140156 _write_autoremove_pending (registry , cache )
157+ _write_installed_packages_per_origin (registry , cache )
141158 _write_cache_timestamps (registry )
142159 _write_reboot_required (registry )
143160 print (generate_latest (registry ).decode (), end = '' )
0 commit comments